Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code-cleanup: static methods, @override #407

Merged
merged 2 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private File checkFile(File file) {
}

@SuppressWarnings({"unused"})
private void debugStore(DataStore store, String[] layerNames) throws IOException {
private static void debugStore(DataStore store, String[] layerNames) throws IOException {
for (String layerName : layerNames) {
System.out.println(asList(store.getTypeNames()));
System.out.println(Collections.singletonList(store.getSchema(layerName).getAttributeDescriptors()));
Expand Down Expand Up @@ -244,7 +244,7 @@ public void saveLayerImage(String[] layerNames, String sldFile, File imagefile,
}
}

private Style getStyleFromSLDFile(String sldFile) {
private static Style getStyleFromSLDFile(String sldFile) {
Style style = null;
if (sldFile != null) {
style = createStyleFromSLD(sldFile);
Expand Down Expand Up @@ -283,7 +283,7 @@ private void saveMapContentToImageFile(MapContent mapContent, File imagefile, Re
/**
* Create a Style object from a definition in a SLD document
*/
private Style createStyleFromSLD(String sldFile) {
private static Style createStyleFromSLD(String sldFile) {
try {
SLDParser stylereader = new SLDParser(styleFactory, new File(sldFile).toURI().toURL());
Style[] style = stylereader.readXML();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public Envelope decodeEnvelope(Entity container) {

protected abstract void encodeGeometryShape(Transaction tx, Geometry geometry, Entity container);

protected Integer encodeGeometryType(String jtsGeometryType) {
protected static Integer encodeGeometryType(String jtsGeometryType) {
// TODO: Consider alternatives for specifying type, like relationship to type category objects (or similar indexing structure)
return switch (jtsGeometryType) {
case "Point" -> GTYPE_POINT;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/neo4j/gis/spatial/DynamicLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ public DynamicLayerConfig addCQLDynamicLayerOnGeometryType(Transaction tx, int g
}

public DynamicLayerConfig addCQLDynamicLayerOnAttribute(Transaction tx, String key, String value, int gtype) {
// TODO: Better escaping here
//return addLayerConfig("CQL:" + key + "-" + value, gtype, key + " = '" + value + "' AND " + makeGeometryCQL(gtype));
if (value == null) {
return addLayerConfig(tx, "CQL:" + key, gtype, key + " IS NOT NULL AND " + makeGeometryCQL(gtype));
}
// TODO: Better escaping here
//return addLayerConfig("CQL:" + key + "-" + value, gtype, key + " = '" + value + "' AND " + makeGeometryCQL(gtype));
return addCQLDynamicLayerOnAttributes(tx, new String[]{key, value}, gtype);
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/neo4j/gis/spatial/DynamicLayerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,12 @@ public Integer getGeometryType(Transaction tx) {
public LayerIndexReader getIndex() {
if (parent.indexReader instanceof LayerTreeIndexReader) {
String query = getQuery();
// Make a CQL based dynamic layer
// Make a standard JSON based dynamic layer
if (query.startsWith("{")) {
// Make a standard JSON based dynamic layer
return new DynamicIndexReader((LayerTreeIndexReader) parent.indexReader, query);
}
try {
// Make a CQL based dynamic layer
return new CQLIndexReader((LayerTreeIndexReader) parent.indexReader, this, query);
} catch (CQLException e) {
throw new SpatialDatabaseException("Error while creating CQL based DynamicLayer", e);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/neo4j/gis/spatial/ShapefileImporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ record = shpReader.nextRecord();
return added;
}

private CoordinateReferenceSystem readCRS(ShpFiles shpFiles, ShapefileReader shpReader) {
private static CoordinateReferenceSystem readCRS(ShpFiles shpFiles, ShapefileReader shpReader) {
try (PrjFileReader prjReader = new PrjFileReader(shpFiles.getReadChannel(ShpFileType.PRJ, shpReader))) {
return prjReader.getCoordinateReferenceSystem();
} catch (IOException | FactoryException e) {
Expand All @@ -235,11 +235,11 @@ private CoordinateReferenceSystem readCRS(ShpFiles shpFiles, ShapefileReader shp
}
}

private void log(String message) {
private static void log(String message) {
System.out.println(message);
}

private void log(String message, Exception e) {
private static void log(String message, Exception e) {
System.out.println(message);
e.printStackTrace();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/neo4j/gis/spatial/SimplePointLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public SpatialDatabaseRecord add(Transaction tx, double x, double y, String[] fi
return add(tx, new Coordinate(x, y), fieldsName, fields);
}

public Integer getGeometryType() {
public static Integer getGeometryType() {
return GTYPE_POINT;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ protected SpatialDatabaseRecord(Layer layer, Node geomNode, Geometry geometry) {

// Private methods

private void checkIsNotReservedProperty(String name) {
private static void checkIsNotReservedProperty(String name) {
for (String property : RESERVED_PROPS) {
if (property.equals(name)) {
throw new SpatialDatabaseException("Updating not allowed for Reserved Property: " + name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public EditableLayer getOrCreateEditableLayer(Transaction tx, String name, Strin
public static final String RTREE_INDEX_NAME = "rtree";
public static final String GEOHASH_INDEX_NAME = "geohash";

public Class<? extends LayerIndexReader> resolveIndexClass(String index) {
public static Class<? extends LayerIndexReader> resolveIndexClass(String index) {
if (index == null) {
return LayerRTreeIndex.class;
}
Expand Down Expand Up @@ -333,7 +333,7 @@ public SimplePointLayer createPointLayer(Transaction tx, String name, Class<? ex
makeEncoderConfig(encoderConfig), org.geotools.referencing.crs.DefaultGeographicCRS.WGS84);
}

public String makeEncoderConfig(String... args) {
public static String makeEncoderConfig(String... args) {
StringBuilder sb = new StringBuilder();
if (args != null) {
for (String arg : args) {
Expand Down Expand Up @@ -555,13 +555,13 @@ public Layer getOrCreateRegisteredTypeLayer(Transaction tx, String name, Registe
(config == null) ? registeredLayerType.defaultConfig : config);
}

public Map<String, String> getRegisteredLayerTypes() {
public static Map<String, String> getRegisteredLayerTypes() {
Map<String, String> results = new LinkedHashMap<>();
registeredLayerTypes.forEach((s, definition) -> results.put(s, definition.getSignature()));
return results;
}

public Class<? extends Layer> suggestLayerClassForEncoder(Class<? extends GeometryEncoder> encoderClass) {
public static Class<? extends Layer> suggestLayerClassForEncoder(Class<? extends GeometryEncoder> encoderClass) {
for (RegisteredLayerType type : registeredLayerTypes.values()) {
if (type.geometryEncoder == encoderClass) {
return type.layerClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public int compareTo(PointResult other) {
return Double.compare(this.distance, other.distance);
}

@Override
public String toString() {
return "Point[" + point + "] distance[" + distance + "] record[" + record + "]";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public PropertyMapper(String from, String to, String type, String params) {
this.params = params;
}

@Override
public boolean equals(Object obj) {
if (obj instanceof PropertyMapper other) {
return this.key().equals(other.key());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class NativePointEncoder extends AbstractGeometryEncoder implements Confi
private String locationProperty = DEFAULT_GEOM;
private Neo4jCRS crs = Neo4jCRS.findCRS("WGS-84");

protected GeometryFactory getGeometryFactory() {
protected static GeometryFactory getGeometryFactory() {
if (geometryFactory == null) {
geometryFactory = new GeometryFactory();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private GeometryFactory getGeometryFactory() {
return geometryFactory;
}

private Node testIsNode(Entity container) {
private static Node testIsNode(Entity container) {
if (!(container instanceof Node)) {
throw new SpatialDatabaseException("Cannot decode non-node geometry: " + container);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public static String coordinateString(List<org.neo4j.graphdb.spatial.Coordinate>
.collect(Collectors.joining(", "));
}

@Override
public String toString() {
return geometryType + "(" + coordinateString(coordinates) + ")[" + crs + "]";
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/neo4j/gis/spatial/index/IndexManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ public void deleteIndex(IndexDefinition index) {
}
}

public void waitForDeletions() {
public static void waitForDeletions() {
waitForThreads("IndexMaker");
waitForThreads("IndexRemover");
}

private void waitForThreads(String prefix) {
private static void waitForThreads(String prefix) {
Thread found;
while ((found = findThread(prefix)) != null) {
try {
Expand All @@ -146,7 +146,7 @@ private void waitForThreads(String prefix) {
}
}

private Thread findThread(String prefix) {
private static Thread findThread(String prefix) {
ThreadGroup rootGroup = Thread.currentThread().getThreadGroup();
Thread found = findThread(rootGroup, prefix);
if (found != null) {
Expand All @@ -165,7 +165,7 @@ private Thread findThread(String prefix) {
return null;
}

private Thread findThread(ThreadGroup group, String prefix) {
private static Thread findThread(ThreadGroup group, String prefix) {
Thread[] threads = new Thread[group.activeCount()];
while (group.enumerate(threads, true) == threads.length) {
threads = new Thread[threads.length * 2];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected String getIndexValueFor(Transaction tx, Node geomNode) {
return geoTermToString(encoded);
}

private String greatestCommonPrefix(String a, String b) {
private static String greatestCommonPrefix(String a, String b) {
int minLength = Math.min(a.length(), b.length());
for (int i = 0; i < minLength; i++) {
if (a.charAt(i) != b.charAt(i)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import org.neo4j.gis.spatial.Layer;
import org.neo4j.gis.spatial.filter.SearchRecords;
import org.neo4j.gis.spatial.rtree.RTreeIndex;
import org.neo4j.gis.spatial.rtree.SpatialIndexVisitor;
import org.neo4j.gis.spatial.rtree.filter.SearchFilter;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Transaction;

/**
Expand All @@ -47,6 +49,11 @@ public void init(Transaction tx, Layer layer, int maxNodeReferences) {
this.layer = layer;
}

@Override
public void visit(Transaction tx, SpatialIndexVisitor visitor, Node indexNode) {
super.visit(tx, visitor, indexNode);
}

@Override
public Layer getLayer() {
return layer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ private SpaceFillingCurve getCurve(Transaction tx) {

protected abstract SpaceFillingCurve makeCurve(Envelope envelope, int maxLevels);

private double getMin(CoordinateSystemAxis axis) {
private static double getMin(CoordinateSystemAxis axis) {
double min = axis.getMinimumValue();
if (Double.isInfinite(min)) {
return 0.0;
}
return min;
}

private double getMax(CoordinateSystemAxis axis) {
private static double getMax(CoordinateSystemAxis axis) {
double max = axis.getMaximumValue();
if (Double.isInfinite(max)) {
return 1.0;
Expand Down Expand Up @@ -143,7 +143,7 @@ public Iterator<Node> search(KernelTransaction ktx, Label label, String property
return Iterators.concat(results.iterator());
}

private ResourceIterator<Node> nodesByLabelAndProperty(KernelTransaction transaction, int labelId,
private static ResourceIterator<Node> nodesByLabelAndProperty(KernelTransaction transaction, int labelId,
PropertyIndexQuery query) {
Read read = transaction.dataRead();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public DynamicIndexReader(LayerTreeIndexReader index, String query) {
this.query = (JSONObject) JSONValue.parse(query);
}

private boolean queryIndexNode(Envelope indexNodeEnvelope) {
private static boolean queryIndexNode(Envelope indexNodeEnvelope) {
// TODO: Support making the query on each index node for performance
return true;
}
Expand All @@ -107,7 +107,7 @@ private boolean queryLeafNode(Node geomNode) {
return queryNodeProperties(geomNode, properties) && stepAndQuery(geomNode, step);
}

private boolean stepAndQuery(Node source, JSONObject step) {
private static boolean stepAndQuery(Node source, JSONObject step) {
if (step != null) {
JSONObject properties = (JSONObject) step.get("properties");
RelationshipType relType = RelationshipType.withName(step.get("type").toString());
Expand All @@ -123,7 +123,7 @@ private boolean stepAndQuery(Node source, JSONObject step) {
return true;
}

private boolean queryNodeProperties(Node node, JSONObject properties) {
private static boolean queryNodeProperties(Node node, JSONObject properties) {
if (properties != null) {
if (properties.containsKey("geometry")) {
System.out.println("Unexpected 'geometry' in query string");
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/org/neo4j/gis/spatial/osm/OSMDataset.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public Iterable<Node> getAllPointNodes(Transaction tx) {
return td.traverse(tx.getNodeByElementId(datasetNodeId)).nodes();
}

public Iterable<Node> getWayNodes(Node way) {
public static Iterable<Node> getWayNodes(Node way) {
TraversalDescription td = new MonoDirectionalTraversalDescription()
.depthFirst()
.relationships(OSMRelation.NEXT, Direction.OUTGOING)
Expand All @@ -136,7 +136,7 @@ public Iterable<Node> getWayNodes(Node way) {
).nodes();
}

public Node getChangeset(Node way) {
public static Node getChangeset(Node way) {
try {
return way.getSingleRelationship(OSMRelation.CHANGESET, Direction.OUTGOING).getEndNode();
} catch (Exception e) {
Expand All @@ -145,7 +145,7 @@ public Node getChangeset(Node way) {
}
}

public Node getUser(Node nodeWayOrChangeset) {
public static Node getUser(Node nodeWayOrChangeset) {
TraversalDescription td = new MonoDirectionalTraversalDescription()
.depthFirst()
.relationships(OSMRelation.CHANGESET, Direction.OUTGOING)
Expand Down Expand Up @@ -208,6 +208,7 @@ public Node getNode() {
return node;
}

@Override
public String toString() {
if (node.hasProperty("name")) {
return node.getProperty("name").toString();
Expand All @@ -228,7 +229,7 @@ public class Way extends OSMNode implements Iterable<WayPoint>, Iterator<WayPoin
}

Iterable<Node> getWayNodes() {
return OSMDataset.this.getWayNodes(this.node);
return OSMDataset.getWayNodes(this.node);
}

public Iterable<WayPoint> getWayPoints() {
Expand Down
Loading