Skip to content
Snippets Groups Projects
Commit 912e1bd0 authored by Hallvard Trætteberg's avatar Hallvard Trætteberg
Browse files

Fixes most google checkstyle warnings.

parent 6d304474
No related branches found
No related tags found
No related merge requests found
Showing
with 77 additions and 75 deletions
......@@ -13,14 +13,14 @@ import java.util.Collection;
* Incomplete implementation of **IDocumentStorage**, to simplify implementing ones for specific
* document and location types. The main missing methods are for getting and setting the current
* document, creating an empty one and creating an **InputStream** from a location.
*
*
* @author hal
*
* @param <D> the document type
* @param <L> the location type
*/
public abstract class AbstractDocumentStorageImpl<D, L>
implements IDocumentStorage<L>, IDocumentPersistence<D, L> {
implements IDocumentStorage<L>, IDocumentPersistence<D, L> {
private L documentLocation = null;
......@@ -43,14 +43,14 @@ public abstract class AbstractDocumentStorageImpl<D, L>
/**
* Returns the current document.
*
*
* @return the current document
*/
protected abstract D getDocument();
/**
* Sets the current document
*
* Sets the current document.
*
* @param document the new document
*/
protected abstract void setDocument(D document);
......@@ -88,7 +88,7 @@ public abstract class AbstractDocumentStorageImpl<D, L>
/**
* Creates a new and empty document.
*
*
* @return
*/
protected abstract D createDocument();
......@@ -99,11 +99,11 @@ public abstract class AbstractDocumentStorageImpl<D, L>
}
/**
* Creates an ImportStream from a location
*
* @param location
* @return
* @throws IOException
* Creates an InputStream from a location.
*
* @param location the location
* @return the location's InputStream
* @throws IOException when the InputStream cannot be created
*/
protected abstract InputStream toInputStream(L location) throws IOException;
......
......@@ -79,15 +79,6 @@ public class FileMenuController {
}
}
private void showExceptionDialog(final String message) {
final Alert alert = new Alert(AlertType.ERROR, message, ButtonType.CLOSE);
alert.showAndWait();
}
private void showExceptionDialog(final String message, final Exception e) {
showExceptionDialog(message + ": " + e.getLocalizedMessage());
}
void handleOpenAction(final File selection) {
try {
documentStorage.openDocument(selection);
......@@ -97,6 +88,15 @@ public class FileMenuController {
}
}
private void showExceptionDialog(final String message) {
final Alert alert = new Alert(AlertType.ERROR, message, ButtonType.CLOSE);
alert.showAndWait();
}
private void showExceptionDialog(final String message, final Exception e) {
showExceptionDialog(message + ": " + e.getLocalizedMessage());
}
private void showSaveExceptionDialog(final File location, final Exception e) {
showExceptionDialog("Oops, problem saving to " + location, e);
}
......@@ -177,7 +177,7 @@ public class FileMenuController {
private TextInputDialog inputDialog;
@FXML
public void handleURLImportAction() {
public void handleUrlImportAction() {
if (inputDialog == null) {
inputDialog = new TextInputDialog();
}
......@@ -191,7 +191,7 @@ public class FileMenuController {
break;
}
try {
if (handleURLImportAction(new URL(result.get()))) {
if (handleUrlImportAction(new URL(result.get()))) {
break;
}
inputDialog.setHeaderText("Problems reading it...");
......@@ -202,7 +202,7 @@ public class FileMenuController {
}
}
boolean handleURLImportAction(final URL url) {
boolean handleUrlImportAction(final URL url) {
for (final IDocumentImporter importer : documentStorage.getDocumentImporters()) {
try (InputStream input = url.openStream()) {
importer.importDocument(input);
......
......@@ -6,16 +6,16 @@ import java.io.InputStream;
/**
* An interface with a method for importing domain data from a location. The main use is supporting
* an **import** action in a **File** menu.
*
*
* @author hal
*
*/
public interface IDocumentImporter {
/**
* Loads a document from the input stream and sets it as the current document.
*
* @param inputStream
* @throws IOException
*
* @param inputStream the document to import
* @throws IOException when the document cannot imported
*/
public void importDocument(InputStream inputStream) throws IOException;
}
......@@ -6,7 +6,7 @@ import java.io.InputStream;
* An interface with a method for loading and returning a document (domain data container) from an
* InputStream. This allows various ways of loading or importing domain data, with different sources
* and formats.
*
*
* @author hal
*
* @param <D> the document type
......@@ -14,10 +14,10 @@ import java.io.InputStream;
public interface IDocumentLoader<D> {
/**
* Loads and returns a new document from an InputStream
*
* @param inputStream
* @return
* @throws Exception
*
* @param inputStream the InputStream to load from
* @return the loaded document
* @throws Exception when the document couldn't be loaded
*/
public D loadDocument(InputStream inputStream) throws Exception;
}
......@@ -3,7 +3,7 @@ package fxutil.doc;
/**
* An interface with a method for saving a document (domain data container) to a location. This
* allows various ways of saving or exporting domain data, to different locations and formats.
*
*
* @author hal
*
* @param <D> the document type
......@@ -12,10 +12,10 @@ package fxutil.doc;
public interface IDocumentSaver<D, L> {
/**
* Saves the provided document to the provided location
*
* @param document
* @param documentLocation
* @throws Exception
*
* @param document the document to save
* @param documentLocation the location to save to
* @throws Exception when the document couldn't be saved
*/
public void saveDocument(D document, L documentLocation) throws Exception;
}
......@@ -8,7 +8,7 @@ import java.util.Collection;
* representing the document (domain data container) is implicit in the implementation of this
* interface. The interface includes methods for getting and setting the location and creating,
* opening and saving the (current) document.
*
*
* @author hal
*
* @param <L> The type of the location, typically java.io.File.
......@@ -16,30 +16,30 @@ import java.util.Collection;
public interface IDocumentStorage<L> {
/**
* Returns the current location (of the current document).
*
*
* @return the current location
*/
public L getDocumentLocation();
/**
* Sets the current location (of the current document), can be used by a save-as action.
*
* @param documentLocation
*
* @param documentLocation the new document location
*/
public void setDocumentLocation(L documentLocation);
/**
* Adds an IDocumentStorageListener that will be notified when the current location changes.
*
* @param documentStorageListener
*
* @param documentStorageListener the listener to add
*/
public void addDocumentStorageListener(IDocumentStorageListener<L> documentStorageListener);
/**
* Removes an IDocumentStorageListener.
*
* @param documentStorageListener
*
* @param documentStorageListener the listener to remove
*/
public void removeDocumentStorageListener(IDocumentStorageListener<L> documentStorageListener);
......@@ -61,7 +61,7 @@ public interface IDocumentStorage<L> {
/**
* Returns the set of IDocumentImporters, can be used by an import action.
*
*
* @return
*/
public Collection<IDocumentImporter> getDocumentImporters();
......
......@@ -3,15 +3,15 @@ package fxutil.doc;
/**
* Listener interface for the (current) location of the (current) document of an IDocumentStorage,
* e.g. when a **save-as** action is performed.
*
*
* @author hal
*
* @param <L>
* @param <L> the document location type
*/
public interface IDocumentStorageListener<L> {
/**
* Notifies that the current document location has changed.
*
*
* @param documentLocation the new document location
* @param oldDocumentLocation the previous document location
*/
......
package fxutil.doc;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Collection;
import java.util.Collections;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
public abstract class SimpleJsonFileStorageImpl<T> extends AbstractDocumentStorageImpl<T, File>
implements IDocumentStorage<File> {
implements IDocumentStorage<File> {
private T document;
......
......@@ -2,7 +2,10 @@ package simpleex.core;
public class LatLong {
private final double latitude, longitude;
public static final String SEPARATOR = ",";
private final double latitude;
private final double longitude;
public LatLong(final double latitude, final double longitude) {
super();
......@@ -10,7 +13,6 @@ public class LatLong {
this.longitude = longitude;
}
public final static String SEPARATOR = ",";
public double getLatitude() {
return latitude;
......
package simpleex.json;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
......@@ -8,6 +7,7 @@ import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.io.IOException;
import simpleex.core.LatLong;
public class LatLongDeserializer extends JsonDeserializer<LatLong> {
......
package simpleex.json;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
import simpleex.core.LatLong;
public class LatLongSerializer extends JsonSerializer<LatLong> {
......
package simpleex.json;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import simpleex.core.LatLong;
import simpleex.core.LatLongs;
......
package simpleex.json;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
import simpleex.core.LatLong;
import simpleex.core.LatLongs;
......
package simpleex.ui;
import java.io.File;
import java.util.Optional;
import fxmapcontrol.Location;
import fxmapcontrol.MapBase;
import fxmapcontrol.MapItemsControl;
......@@ -9,6 +7,8 @@ import fxmapcontrol.MapNode;
import fxmapcontrol.MapProjection;
import fxutil.doc.FileMenuController;
import fxutil.doc.IDocumentListener;
import java.io.File;
import java.util.Optional;
import javafx.collections.FXCollections;
import javafx.fxml.FXML;
import javafx.geometry.Point2D;
......
package simpleex.ui;
import fxutil.doc.AbstractDocumentStorageImpl;
import fxutil.doc.IDocumentImporter;
import fxutil.doc.IDocumentLoader;
import fxutil.doc.IDocumentPersistence;
import fxutil.doc.IDocumentStorage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
......@@ -9,11 +14,6 @@ import java.io.OutputStream;
import java.util.Arrays;
import java.util.Collection;
import java.util.stream.Collectors;
import fxutil.doc.AbstractDocumentStorageImpl;
import fxutil.doc.IDocumentImporter;
import fxutil.doc.IDocumentLoader;
import fxutil.doc.IDocumentPersistence;
import fxutil.doc.IDocumentStorage;
import simpleex.core.LatLongs;
public class LatLongsApp {
......
package simpleex.ui;
import java.io.File;
import com.fasterxml.jackson.databind.module.SimpleModule;
import fxutil.doc.IDocumentStorage;
import fxutil.doc.SimpleJsonFileStorageImpl;
import java.io.File;
import simpleex.core.LatLong;
import simpleex.core.LatLongs;
import simpleex.json.LatLongDeserializer;
......
package simpleex.json;
import java.io.IOException;
import org.junit.Assert;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import java.io.IOException;
import org.junit.Assert;
public abstract class AbstractJsonTest {
......
package simpleex.json;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import com.fasterxml.jackson.databind.ObjectMapper;
import simpleex.core.LatLong;
public class LatLongJsonTest extends AbstractJsonTest {
......
package simpleex.json;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import simpleex.core.LatLong;
import simpleex.core.LatLongs;
......
......@@ -3,14 +3,14 @@ package simpleex.ui;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import fxmapcontrol.Location;
import fxmapcontrol.MapBase;
import java.util.ArrayList;
import java.util.List;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.testfx.framework.junit.ApplicationTest;
import fxmapcontrol.Location;
import fxmapcontrol.MapBase;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment