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

Added google style checks and formatted all code using google style

settings in Eclipse.
parent aaebac25
No related branches found
No related tags found
No related merge requests found
Pipeline #46506 passed
Showing
with 1440 additions and 803 deletions
...@@ -10,7 +10,9 @@ plugins { ...@@ -10,7 +10,9 @@ plugins {
// code quality with PMD // code quality with PMD
id 'pmd' id 'pmd'
// code quality with SpotBugs // code quality with SpotBugs
id "com.github.spotbugs" version "2.0.0" id 'com.github.spotbugs' version '2.0.0'
// code quality with checkstyle
id 'checkstyle'
} }
repositories { repositories {
...@@ -61,6 +63,10 @@ tasks.withType(com.github.spotbugs.SpotBugsTask) { ...@@ -61,6 +63,10 @@ tasks.withType(com.github.spotbugs.SpotBugsTask) {
} }
} }
checkstyle {
configFile = project.file("config/checkstyle/google_checks.xml")
}
dependencies { dependencies {
compile "com.fasterxml.jackson.core:jackson-databind:2.9.8" compile "com.fasterxml.jackson.core:jackson-databind:2.9.8"
// compile 'fischer.clemens:FxMapControl:1.0' // compile 'fischer.clemens:FxMapControl:1.0'
......
This diff is collapsed.
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<!--
Checkstyle configuration that checks the Google coding conventions from Google Java Style
that can be found at https://google.github.io/styleguide/javaguide.html
Checkstyle is very configurable. Be sure to read the documentation at
http://checkstyle.sf.net (or in your downloaded distribution).
To completely disable a check, just comment it out or delete it from the file.
Authors: Max Vetrenko, Ruslan Diachenko, Roman Ivanov.
-->
<module name = "Checker">
<property name="charset" value="UTF-8"/>
<property name="severity" value="warning"/>
<property name="fileExtensions" value="java, properties, xml"/>
<!-- Excludes all 'module-info.java' files -->
<!-- See https://checkstyle.org/config_filefilters.html -->
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="module\-info\.java$"/>
</module>
<!-- Checks for whitespace -->
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
<module name="FileTabCharacter">
<property name="eachLine" value="true"/>
</module>
<module name="TreeWalker">
<module name="OuterTypeFilename"/>
<module name="IllegalTokenText">
<property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/>
<property name="format"
value="\\u00(09|0(a|A)|0(c|C)|0(d|D)|22|27|5(C|c))|\\(0(10|11|12|14|15|42|47)|134)"/>
<property name="message"
value="Consider using special escape sequence instead of octal value or Unicode escaped value."/>
</module>
<module name="AvoidEscapedUnicodeCharacters">
<property name="allowEscapesForControlCharacters" value="true"/>
<property name="allowByTailComment" value="true"/>
<property name="allowNonPrintableEscapes" value="true"/>
</module>
<module name="LineLength">
<property name="max" value="100"/>
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
</module>
<module name="AvoidStarImport"/>
<module name="OneTopLevelClass"/>
<module name="NoLineWrap"/>
<module name="EmptyBlock">
<property name="option" value="TEXT"/>
<property name="tokens"
value="LITERAL_TRY, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, LITERAL_SWITCH"/>
</module>
<module name="NeedBraces"/>
<module name="LeftCurly"/>
<module name="RightCurly">
<property name="id" value="RightCurlySame"/>
<property name="tokens"
value="LITERAL_TRY, LITERAL_CATCH, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE,
LITERAL_DO"/>
</module>
<module name="RightCurly">
<property name="id" value="RightCurlyAlone"/>
<property name="option" value="alone"/>
<property name="tokens"
value="CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, LITERAL_WHILE, STATIC_INIT,
INSTANCE_INIT"/>
</module>
<module name="WhitespaceAround">
<property name="allowEmptyConstructors" value="true"/>
<property name="allowEmptyLambdas" value="true"/>
<property name="allowEmptyMethods" value="true"/>
<property name="allowEmptyTypes" value="true"/>
<property name="allowEmptyLoops" value="true"/>
<message key="ws.notFollowed"
value="WhitespaceAround: ''{0}'' is not followed by whitespace. Empty blocks may only be represented as '{}' when not part of a multi-block statement (4.1.3)"/>
<message key="ws.notPreceded"
value="WhitespaceAround: ''{0}'' is not preceded with whitespace."/>
</module>
<module name="OneStatementPerLine"/>
<module name="MultipleVariableDeclarations"/>
<module name="ArrayTypeStyle"/>
<module name="MissingSwitchDefault"/>
<module name="FallThrough"/>
<module name="UpperEll"/>
<module name="ModifierOrder"/>
<module name="EmptyLineSeparator">
<property name="allowNoEmptyLineBetweenFields" value="true"/>
</module>
<module name="SeparatorWrap">
<property name="id" value="SeparatorWrapDot"/>
<property name="tokens" value="DOT"/>
<property name="option" value="nl"/>
</module>
<module name="SeparatorWrap">
<property name="id" value="SeparatorWrapComma"/>
<property name="tokens" value="COMMA"/>
<property name="option" value="EOL"/>
</module>
<module name="SeparatorWrap">
<!-- ELLIPSIS is EOL until https://github.com/google/styleguide/issues/258 -->
<property name="id" value="SeparatorWrapEllipsis"/>
<property name="tokens" value="ELLIPSIS"/>
<property name="option" value="EOL"/>
</module>
<module name="SeparatorWrap">
<!-- ARRAY_DECLARATOR is EOL until https://github.com/google/styleguide/issues/259 -->
<property name="id" value="SeparatorWrapArrayDeclarator"/>
<property name="tokens" value="ARRAY_DECLARATOR"/>
<property name="option" value="EOL"/>
</module>
<module name="SeparatorWrap">
<property name="id" value="SeparatorWrapMethodRef"/>
<property name="tokens" value="METHOD_REF"/>
<property name="option" value="nl"/>
</module>
<module name="PackageName">
<property name="format" value="^[a-z]+(\.[a-z][a-z0-9]*)*$"/>
<message key="name.invalidPattern"
value="Package name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="TypeName">
<message key="name.invalidPattern"
value="Type name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="MemberName">
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
<message key="name.invalidPattern"
value="Member name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="ParameterName">
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
<message key="name.invalidPattern"
value="Parameter name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="LambdaParameterName">
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
<message key="name.invalidPattern"
value="Lambda parameter name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="CatchParameterName">
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
<message key="name.invalidPattern"
value="Catch parameter name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="LocalVariableName">
<property name="tokens" value="VARIABLE_DEF"/>
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
<message key="name.invalidPattern"
value="Local variable name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="ClassTypeParameterName">
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
<message key="name.invalidPattern"
value="Class type name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="MethodTypeParameterName">
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
<message key="name.invalidPattern"
value="Method type name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="InterfaceTypeParameterName">
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
<message key="name.invalidPattern"
value="Interface type name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="NoFinalizer"/>
<module name="GenericWhitespace">
<message key="ws.followed"
value="GenericWhitespace ''{0}'' is followed by whitespace."/>
<message key="ws.preceded"
value="GenericWhitespace ''{0}'' is preceded with whitespace."/>
<message key="ws.illegalFollow"
value="GenericWhitespace ''{0}'' should followed by whitespace."/>
<message key="ws.notPreceded"
value="GenericWhitespace ''{0}'' is not preceded with whitespace."/>
</module>
<module name="Indentation">
<property name="basicOffset" value="2"/>
<property name="braceAdjustment" value="0"/>
<property name="caseIndent" value="2"/>
<property name="throwsIndent" value="4"/>
<property name="lineWrappingIndentation" value="4"/>
<property name="arrayInitIndent" value="2"/>
</module>
<module name="AbbreviationAsWordInName">
<property name="ignoreFinal" value="false"/>
<property name="allowedAbbreviationLength" value="1"/>
</module>
<module name="OverloadMethodsDeclarationOrder"/>
<module name="VariableDeclarationUsageDistance"/>
<module name="CustomImportOrder">
<property name="sortImportsInGroupAlphabetically" value="true"/>
<property name="separateLineBetweenGroups" value="true"/>
<property name="customImportOrderRules" value="STATIC###THIRD_PARTY_PACKAGE"/>
</module>
<module name="MethodParamPad"/>
<module name="NoWhitespaceBefore">
<property name="tokens"
value="COMMA, SEMI, POST_INC, POST_DEC, DOT, ELLIPSIS, METHOD_REF"/>
<property name="allowLineBreaks" value="true"/>
</module>
<module name="ParenPad"/>
<module name="OperatorWrap">
<property name="option" value="NL"/>
<property name="tokens"
value="BAND, BOR, BSR, BXOR, DIV, EQUAL, GE, GT, LAND, LE, LITERAL_INSTANCEOF, LOR,
LT, MINUS, MOD, NOT_EQUAL, PLUS, QUESTION, SL, SR, STAR, METHOD_REF "/>
</module>
<module name="AnnotationLocation">
<property name="id" value="AnnotationLocationMostCases"/>
<property name="tokens"
value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF"/>
</module>
<module name="AnnotationLocation">
<property name="id" value="AnnotationLocationVariables"/>
<property name="tokens" value="VARIABLE_DEF"/>
<property name="allowSamelineMultipleAnnotations" value="true"/>
</module>
<module name="NonEmptyAtclauseDescription"/>
<!-- Removed due to instantiation exception
<module name="InvalidJavadocPosition"/>
-->
<module name="JavadocTagContinuationIndentation"/>
<module name="SummaryJavadoc">
<property name="forbiddenSummaryFragments"
value="^@return the *|^This method returns |^A [{]@code [a-zA-Z0-9]+[}]( is a )"/>
</module>
<module name="JavadocParagraph"/>
<module name="AtclauseOrder">
<property name="tagOrder" value="@param, @return, @throws, @deprecated"/>
<property name="target"
value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF, VARIABLE_DEF"/>
</module>
<module name="JavadocMethod">
<property name="scope" value="public"/>
<property name="allowMissingParamTags" value="true"/>
<property name="allowMissingThrowsTags" value="true"/>
<property name="allowMissingReturnTag" value="true"/>
<property name="allowedAnnotations" value="Override, Test"/>
<property name="allowThrowsTagsForSubclasses" value="true"/>
</module>
<!-- Removed due to instantiation exception
<module name="MissingJavadocMethod">
<property name="scope" value="public"/>
<property name="minLineCount" value="2"/>
<property name="allowedAnnotations" value="Override, Test"/>
</module>
-->
<module name="MethodName">
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9_]*$"/>
<message key="name.invalidPattern"
value="Method name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="SingleLineJavadoc">
<property name="ignoreInlineTags" value="false"/>
</module>
<module name="EmptyCatchBlock">
<property name="exceptionVariableName" value="expected"/>
</module>
<module name="CommentsIndentation"/>
</module>
</module>
...@@ -10,15 +10,17 @@ import java.util.ArrayList; ...@@ -10,15 +10,17 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
/** /**
* Incomplete implementation of **IDocumentStorage**, to simplify implementing ones for specific document and location types. * Incomplete implementation of **IDocumentStorage**, to simplify implementing ones for specific
* The main missing methods are for getting and setting the current document, creating an empty one and * document and location types. The main missing methods are for getting and setting the current
* 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> implements IDocumentStorage<L>, IDocumentPersistence<D, L> { public abstract class AbstractDocumentStorageImpl<D, L>
implements IDocumentStorage<L>, IDocumentPersistence<D, L> {
private L documentLocation = null; private L documentLocation = null;
...@@ -41,27 +43,32 @@ public abstract class AbstractDocumentStorageImpl<D, L> implements IDocumentStor ...@@ -41,27 +43,32 @@ public abstract class AbstractDocumentStorageImpl<D, L> implements IDocumentStor
/** /**
* 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);
// //
private final Collection<IDocumentStorageListener<L>> documentListeners = new ArrayList<IDocumentStorageListener<L>>(); private final Collection<IDocumentStorageListener<L>> documentListeners =
new ArrayList<IDocumentStorageListener<L>>();
@Override @Override
public void addDocumentStorageListener(final IDocumentStorageListener<L> documentStorageListener) { public void addDocumentStorageListener(
final IDocumentStorageListener<L> documentStorageListener) {
documentListeners.add(documentStorageListener); documentListeners.add(documentStorageListener);
} }
@Override @Override
public void removeDocumentStorageListener(final IDocumentStorageListener<L> documentStorageListener) { public void removeDocumentStorageListener(
final IDocumentStorageListener<L> documentStorageListener) {
documentListeners.remove(documentStorageListener); documentListeners.remove(documentStorageListener);
} }
...@@ -81,6 +88,7 @@ public abstract class AbstractDocumentStorageImpl<D, L> implements IDocumentStor ...@@ -81,6 +88,7 @@ public abstract class AbstractDocumentStorageImpl<D, L> implements IDocumentStor
/** /**
* Creates a new and empty document. * Creates a new and empty document.
*
* @return * @return
*/ */
protected abstract D createDocument(); protected abstract D createDocument();
...@@ -92,6 +100,7 @@ public abstract class AbstractDocumentStorageImpl<D, L> implements IDocumentStor ...@@ -92,6 +100,7 @@ public abstract class AbstractDocumentStorageImpl<D, L> implements IDocumentStor
/** /**
* Creates an ImportStream from a location * Creates an ImportStream from a location
*
* @param location * @param location
* @return * @return
* @throws IOException * @throws IOException
......
...@@ -9,7 +9,6 @@ import java.net.URL; ...@@ -9,7 +9,6 @@ import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.Alert; import javafx.scene.control.Alert;
......
...@@ -4,14 +4,16 @@ import java.io.IOException; ...@@ -4,14 +4,16 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
/** /**
* An interface with a method for importing domain data from a location. * An interface with a method for importing domain data from a location. The main use is supporting
* 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
* @throws IOException * @throws IOException
*/ */
......
package fxutil.doc; package fxutil.doc;
/** /**
* Listener interface for the (contents of) the (current) document of an IDocumentStorage, e.g. * Listener interface for the (contents of) the (current) document of an IDocumentStorage, e.g. when
* when an **open** action is performed. * an **open** action is performed.
*
* @author hal * @author hal
* *
* @param <D> the document type * @param <D> the document type
...@@ -11,6 +12,7 @@ package fxutil.doc; ...@@ -11,6 +12,7 @@ package fxutil.doc;
public interface IDocumentListener<D, L> extends IDocumentStorageListener<L> { public interface IDocumentListener<D, L> extends IDocumentStorageListener<L> {
/** /**
* Notifies that the current document has changed. * Notifies that the current document has changed.
*
* @param document the new document * @param document the new document
* @param oldDocument the previous document * @param oldDocument the previous document
*/ */
......
...@@ -3,8 +3,10 @@ package fxutil.doc; ...@@ -3,8 +3,10 @@ package fxutil.doc;
import java.io.InputStream; import java.io.InputStream;
/** /**
* An interface with a method for loading and returning a document (domain data container) from an InputStream. * An interface with a method for loading and returning a document (domain data container) from an
* This allows various ways of loading or importing domain data, with different sources and formats. * InputStream. This allows various ways of loading or importing domain data, with different sources
* and formats.
*
* @author hal * @author hal
* *
* @param <D> the document type * @param <D> the document type
...@@ -12,6 +14,7 @@ import java.io.InputStream; ...@@ -12,6 +14,7 @@ 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
* @return * @return
* @throws Exception * @throws Exception
......
package fxutil.doc; package fxutil.doc;
/** /**
* An interface with a method for saving a document (domain data container) to a location. * An interface with a method for saving a document (domain data container) to a location. This
* 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
...@@ -11,6 +12,7 @@ package fxutil.doc; ...@@ -11,6 +12,7 @@ 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
* @param documentLocation * @param documentLocation
* @throws Exception * @throws Exception
......
...@@ -4,9 +4,11 @@ import java.io.IOException; ...@@ -4,9 +4,11 @@ import java.io.IOException;
import java.util.Collection; import java.util.Collection;
/** /**
* An interface with the methods necessary for supporting the standard File menu actions. * An interface with the methods necessary for supporting the standard File menu actions. The class
* The class representing the document (domain data container) is implicit in the implementation of this interface. * representing the document (domain data container) is implicit in the implementation of this
* The interface includes methods for getting and setting the location and creating, opening and saving the (current) document. * interface. The interface includes methods for getting and setting the location and creating,
* 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.
...@@ -14,24 +16,29 @@ import java.util.Collection; ...@@ -14,24 +16,29 @@ 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
*/ */
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
*/ */
public void addDocumentStorageListener(IDocumentStorageListener<L> documentStorageListener); public void addDocumentStorageListener(IDocumentStorageListener<L> documentStorageListener);
/** /**
* Removes an IDocumentStorageListener. * Removes an IDocumentStorageListener.
*
* @param documentStorageListener * @param documentStorageListener
*/ */
public void removeDocumentStorageListener(IDocumentStorageListener<L> documentStorageListener); public void removeDocumentStorageListener(IDocumentStorageListener<L> documentStorageListener);
...@@ -42,7 +49,8 @@ public interface IDocumentStorage<L> { ...@@ -42,7 +49,8 @@ public interface IDocumentStorage<L> {
public void newDocument(); public void newDocument();
/** /**
* Loads a documents from the provided location and sets it as the current one, can be used by an open action. * Loads a documents from the provided location and sets it as the current one, can be used by an
* open action.
*/ */
public void openDocument(L documentLocation) throws IOException; public void openDocument(L documentLocation) throws IOException;
...@@ -53,6 +61,7 @@ public interface IDocumentStorage<L> { ...@@ -53,6 +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();
......
package fxutil.doc; package fxutil.doc;
/** /**
* Listener interface for the (current) location of the (current) document of an IDocumentStorage, e.g. * Listener interface for the (current) location of the (current) document of an IDocumentStorage,
* when a **save-as** action is performed. * e.g. when a **save-as** action is performed.
*
* @author hal * @author hal
* *
* @param <L> * @param <L>
...@@ -10,6 +11,7 @@ package fxutil.doc; ...@@ -10,6 +11,7 @@ package fxutil.doc;
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
*/ */
......
...@@ -6,11 +6,11 @@ import java.io.InputStream; ...@@ -6,11 +6,11 @@ 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.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule; import com.fasterxml.jackson.databind.module.SimpleModule;
public abstract class SimpleJsonFileStorageImpl<T> extends AbstractDocumentStorageImpl<T, File> implements IDocumentStorage<File> { public abstract class SimpleJsonFileStorageImpl<T> extends AbstractDocumentStorageImpl<T, File>
implements IDocumentStorage<File> {
private T document; private T document;
......
...@@ -44,8 +44,8 @@ public class LatLong { ...@@ -44,8 +44,8 @@ public class LatLong {
return false; return false;
} }
final LatLong other = (LatLong) obj; final LatLong other = (LatLong) obj;
return (Double.doubleToLongBits(latitude) == Double.doubleToLongBits(other.latitude) && return (Double.doubleToLongBits(latitude) == Double.doubleToLongBits(other.latitude)
Double.doubleToLongBits(longitude) == Double.doubleToLongBits(other.longitude)); && Double.doubleToLongBits(longitude) == Double.doubleToLongBits(other.longitude));
} }
public static LatLong valueOf(final String s) { public static LatLong valueOf(final String s) {
...@@ -85,12 +85,14 @@ public class LatLong { ...@@ -85,12 +85,14 @@ public class LatLong {
/* :: GeoDataSource.com (C) All Rights Reserved 2015 : */ /* :: GeoDataSource.com (C) All Rights Reserved 2015 : */
/* :: : */ /* :: : */
/* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */ /* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
public static double distance(final double lat1, final double lon1, final double lat2, final double lon2) { public static double distance(final double lat1, final double lon1, final double lat2,
final double lon2) {
if (lon1 == lon2 && lat1 == lat2) { if (lon1 == lon2 && lat1 == lat2) {
return 0.0; return 0.0;
} }
final double theta = lon1 - lon2; final double theta = lon1 - lon2;
double dist = Math.sin(deg2rad(lat1)) * Math.sin(deg2rad(lat2)) + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.cos(deg2rad(theta)); double dist = Math.sin(deg2rad(lat1)) * Math.sin(deg2rad(lat2))
+ Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.cos(deg2rad(theta));
dist = Math.acos(dist); dist = Math.acos(dist);
// convert to degrees // convert to degrees
dist = rad2deg(dist); dist = rad2deg(dist);
......
...@@ -9,8 +9,7 @@ public class LatLongs implements Iterable<LatLong> { ...@@ -9,8 +9,7 @@ public class LatLongs implements Iterable<LatLong> {
final List<LatLong> latLongs = new ArrayList<>(); final List<LatLong> latLongs = new ArrayList<>();
public LatLongs() { public LatLongs() {}
}
public LatLongs(final double... latLongsArray) { public LatLongs(final double... latLongsArray) {
addLatLongs(latLongsArray); addLatLongs(latLongsArray);
......
package simpleex.json; package simpleex.json;
import java.io.IOException; 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;
...@@ -9,7 +8,6 @@ import com.fasterxml.jackson.databind.JsonDeserializer; ...@@ -9,7 +8,6 @@ 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 simpleex.core.LatLong; import simpleex.core.LatLong;
public class LatLongDeserializer extends JsonDeserializer<LatLong> { public class LatLongDeserializer extends JsonDeserializer<LatLong> {
...@@ -17,7 +15,8 @@ public class LatLongDeserializer extends JsonDeserializer<LatLong> { ...@@ -17,7 +15,8 @@ public class LatLongDeserializer extends JsonDeserializer<LatLong> {
private static final int ARRAY_JSON_NODE_SIZE = 2; private static final int ARRAY_JSON_NODE_SIZE = 2;
@Override @Override
public LatLong deserialize(final JsonParser jsonParser, final DeserializationContext deserContext) throws IOException, JsonProcessingException { public LatLong deserialize(final JsonParser jsonParser, final DeserializationContext deserContext)
throws IOException, JsonProcessingException {
final JsonNode jsonNode = jsonParser.getCodec().readTree(jsonParser); final JsonNode jsonNode = jsonParser.getCodec().readTree(jsonParser);
return deserialize(jsonNode); return deserialize(jsonNode);
} }
......
package simpleex.json; package simpleex.json;
import java.io.IOException; 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 simpleex.core.LatLong; import simpleex.core.LatLong;
public class LatLongSerializer extends JsonSerializer<LatLong> { public class LatLongSerializer extends JsonSerializer<LatLong> {
...@@ -14,7 +12,8 @@ public class LatLongSerializer extends JsonSerializer<LatLong> { ...@@ -14,7 +12,8 @@ public class LatLongSerializer extends JsonSerializer<LatLong> {
public static final String LATITUDE_FIELD_NAME = "latitude"; public static final String LATITUDE_FIELD_NAME = "latitude";
@Override @Override
public void serialize(final LatLong latLon, final JsonGenerator jsonGen, final SerializerProvider provider) throws IOException { public void serialize(final LatLong latLon, final JsonGenerator jsonGen,
final SerializerProvider provider) throws IOException {
jsonGen.writeStartObject(); jsonGen.writeStartObject();
jsonGen.writeFieldName(LATITUDE_FIELD_NAME); jsonGen.writeFieldName(LATITUDE_FIELD_NAME);
jsonGen.writeNumber(latLon.getLatitude()); jsonGen.writeNumber(latLon.getLatitude());
......
...@@ -3,14 +3,12 @@ package simpleex.json; ...@@ -3,14 +3,12 @@ package simpleex.json;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; 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 simpleex.core.LatLong; import simpleex.core.LatLong;
import simpleex.core.LatLongs; import simpleex.core.LatLongs;
...@@ -19,7 +17,8 @@ public class LatLongsDeserializer extends JsonDeserializer<LatLongs> { ...@@ -19,7 +17,8 @@ public class LatLongsDeserializer extends JsonDeserializer<LatLongs> {
private final LatLongDeserializer latLongDeserializer = new LatLongDeserializer(); private final LatLongDeserializer latLongDeserializer = new LatLongDeserializer();
@Override @Override
public LatLongs deserialize(final JsonParser jsonParser, final DeserializationContext deserContext) throws IOException, JsonProcessingException { public LatLongs deserialize(final JsonParser jsonParser,
final DeserializationContext deserContext) throws IOException, JsonProcessingException {
final JsonNode jsonNode = jsonParser.getCodec().readTree(jsonParser); final JsonNode jsonNode = jsonParser.getCodec().readTree(jsonParser);
if (jsonNode instanceof ArrayNode) { if (jsonNode instanceof ArrayNode) {
final ArrayNode latLongsArray = (ArrayNode) jsonNode; final ArrayNode latLongsArray = (ArrayNode) jsonNode;
......
package simpleex.json; package simpleex.json;
import java.io.IOException; 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 simpleex.core.LatLong; import simpleex.core.LatLong;
import simpleex.core.LatLongs; import simpleex.core.LatLongs;
public class LatLongsSerializer extends JsonSerializer<LatLongs> { public class LatLongsSerializer extends JsonSerializer<LatLongs> {
@Override @Override
public void serialize(final LatLongs latLongs, final JsonGenerator jsonGen, final SerializerProvider provider) throws IOException { public void serialize(final LatLongs latLongs, final JsonGenerator jsonGen,
final SerializerProvider provider) throws IOException {
jsonGen.writeStartArray(latLongs.getLatLongCount()); jsonGen.writeStartArray(latLongs.getLatLongCount());
for (final LatLong latLong : latLongs) { for (final LatLong latLong : latLongs) {
jsonGen.writeObject(latLong); jsonGen.writeObject(latLong);
......
package simpleex.ui; package simpleex.ui;
import java.util.Optional; import java.util.Optional;
import javafx.event.EventHandler; import javafx.event.EventHandler;
import javafx.geometry.Point2D; import javafx.geometry.Point2D;
import javafx.scene.Node; import javafx.scene.Node;
...@@ -9,8 +8,7 @@ import javafx.scene.input.MouseEvent; ...@@ -9,8 +8,7 @@ import javafx.scene.input.MouseEvent;
public class DraggableNodeController { public class DraggableNodeController {
public DraggableNodeController() { public DraggableNodeController() {}
}
public DraggableNodeController(final Optional<NodeDraggedHandler> nodeDraggedHandler) { public DraggableNodeController(final Optional<NodeDraggedHandler> nodeDraggedHandler) {
setNodeDraggedHandler(nodeDraggedHandler); setNodeDraggedHandler(nodeDraggedHandler);
...@@ -52,7 +50,8 @@ public class DraggableNodeController { ...@@ -52,7 +50,8 @@ public class DraggableNodeController {
if (currentNode.isEmpty() && mouseEvent.getSource() instanceof Node) { if (currentNode.isEmpty() && mouseEvent.getSource() instanceof Node) {
currentNode = Optional.of((Node) mouseEvent.getSource()); currentNode = Optional.of((Node) mouseEvent.getSource());
startPoint = new Point2D(mouseEvent.getSceneX(), mouseEvent.getSceneY()); startPoint = new Point2D(mouseEvent.getSceneX(), mouseEvent.getSceneY());
startTranslate = new Point2D(currentNode.get().getTranslateX(), currentNode.get().getTranslateY()); startTranslate =
new Point2D(currentNode.get().getTranslateX(), currentNode.get().getTranslateY());
mouseEvent.consume(); mouseEvent.consume();
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment