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