-
Notifications
You must be signed in to change notification settings - Fork 494
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Extended versions of common classes removed from common
- Loading branch information
Showing
87 changed files
with
5,601 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
[submodule "apoc-core"] | ||
path = apoc-core | ||
url = https://github.com/neo4j/apoc | ||
branch = dev | ||
branch = dev_reduce_common_reliance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
extended/src/main/java/apoc/algo/PathFindingUtilsExtended.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Copyright (c) "Neo4j" | ||
* Neo4j Sweden AB [http://neo4j.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package apoc.algo; | ||
|
||
import apoc.path.RelationshipTypeAndDirectionsExtended; | ||
import org.apache.commons.lang3.tuple.Pair; | ||
import org.neo4j.graphalgo.EstimateEvaluator; | ||
import org.neo4j.graphdb.Direction; | ||
import org.neo4j.graphdb.Node; | ||
import org.neo4j.graphdb.PathExpander; | ||
import org.neo4j.graphdb.PathExpanderBuilder; | ||
import org.neo4j.graphdb.RelationshipType; | ||
import org.neo4j.values.storable.PointValue; | ||
|
||
public class PathFindingUtilsExtended { | ||
public static class GeoEstimateEvaluatorPointCustom implements EstimateEvaluator<Double> { | ||
// -- from org.neo4j.graphalgo.impl.util.GeoEstimateEvaluator | ||
private static final double EARTH_RADIUS = 6371 * 1000; // Meters | ||
private Node cachedGoal; | ||
private final String pointPropertyKey; | ||
private double[] cachedGoalCoordinates; | ||
|
||
public GeoEstimateEvaluatorPointCustom(String pointPropertyKey) { | ||
this.pointPropertyKey = pointPropertyKey; | ||
} | ||
|
||
@Override | ||
public Double getCost(Node node, Node goal) { | ||
double[] nodeCoordinates = getCoordinates(node); | ||
if (cachedGoal == null || !cachedGoal.equals(goal)) { | ||
cachedGoalCoordinates = getCoordinates(goal); | ||
cachedGoal = goal; | ||
} | ||
return distance(nodeCoordinates[0], nodeCoordinates[1], cachedGoalCoordinates[0], cachedGoalCoordinates[1]); | ||
} | ||
|
||
private static double distance(double latitude1, double longitude1, double latitude2, double longitude2) { | ||
latitude1 = Math.toRadians(latitude1); | ||
longitude1 = Math.toRadians(longitude1); | ||
latitude2 = Math.toRadians(latitude2); | ||
longitude2 = Math.toRadians(longitude2); | ||
double cLa1 = Math.cos(latitude1); | ||
double xA = EARTH_RADIUS * cLa1 * Math.cos(longitude1); | ||
double yA = EARTH_RADIUS * cLa1 * Math.sin(longitude1); | ||
double zA = EARTH_RADIUS * Math.sin(latitude1); | ||
double cLa2 = Math.cos(latitude2); | ||
double xB = EARTH_RADIUS * cLa2 * Math.cos(longitude2); | ||
double yB = EARTH_RADIUS * cLa2 * Math.sin(longitude2); | ||
double zB = EARTH_RADIUS * Math.sin(latitude2); | ||
return Math.sqrt((xA - xB) * (xA - xB) + (yA - yB) * (yA - yB) + (zA - zB) * (zA - zB)); | ||
} | ||
// -- end from org.neo4j.graphalgo.impl.util.GeoEstimateEvaluator | ||
|
||
private double[] getCoordinates(Node node) { | ||
return ((PointValue) node.getProperty(pointPropertyKey)).coordinate(); | ||
} | ||
} | ||
|
||
public static PathExpander<Double> buildPathExpander(String relationshipsAndDirections) { | ||
PathExpanderBuilder builder = PathExpanderBuilder.empty(); | ||
for (Pair<RelationshipType, Direction> pair : RelationshipTypeAndDirectionsExtended.parse(relationshipsAndDirections)) { | ||
if (pair.getLeft() == null) { | ||
if (pair.getRight() == null) { | ||
builder = PathExpanderBuilder.allTypesAndDirections(); | ||
} else { | ||
builder = PathExpanderBuilder.allTypes(pair.getRight()); | ||
} | ||
} else { | ||
if (pair.getRight() == null) { | ||
builder = builder.add(pair.getLeft()); | ||
} else { | ||
builder = builder.add(pair.getLeft(), pair.getRight()); | ||
} | ||
} | ||
} | ||
return builder.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
extended/src/main/java/apoc/coll/SetBackedListExtended.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/* | ||
* Copyright (c) "Neo4j" | ||
* Neo4j Sweden AB [http://neo4j.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package apoc.coll; | ||
|
||
import java.util.AbstractSequentialList; | ||
import java.util.Iterator; | ||
import java.util.ListIterator; | ||
import java.util.NoSuchElementException; | ||
import java.util.Set; | ||
import java.util.Spliterator; | ||
|
||
/** | ||
* @author mh | ||
* @since 10.04.16 | ||
*/ | ||
public class SetBackedListExtended<T> extends AbstractSequentialList<T> implements Set<T> { | ||
|
||
private final Set<T> set; | ||
|
||
public SetBackedListExtended(Set<T> set) { | ||
this.set = set; | ||
} | ||
|
||
@Override | ||
public int size() { | ||
return set.size(); | ||
} | ||
|
||
public ListIterator<T> listIterator(int index) { | ||
return new ListIterator<T>() { | ||
Iterator<T> it = set.iterator(); | ||
T current = null; | ||
int idx = 0; | ||
|
||
{ | ||
moveTo(index); | ||
} | ||
|
||
@Override | ||
public boolean hasNext() { | ||
return it.hasNext(); | ||
} | ||
|
||
@Override | ||
public T next() { | ||
idx++; | ||
return current = it.next(); | ||
} | ||
|
||
@Override | ||
public boolean hasPrevious() { | ||
return idx > 0; | ||
} | ||
|
||
@Override | ||
public T previous() { | ||
if (!hasPrevious()) throw new NoSuchElementException(); | ||
T tmp = current; | ||
moveTo(idx - 1); | ||
return tmp; | ||
} | ||
|
||
private void moveTo(int pos) { | ||
Iterator<T> it2 = set.iterator(); | ||
T value = null; | ||
int i = 0; | ||
while (i++ < pos) { | ||
value = it2.next(); | ||
} | ||
; | ||
this.it = it2; | ||
this.idx = pos; | ||
this.current = value; | ||
} | ||
|
||
@Override | ||
public int nextIndex() { | ||
return idx; | ||
} | ||
|
||
@Override | ||
public int previousIndex() { | ||
return idx - 1; | ||
} | ||
|
||
@Override | ||
public void remove() { | ||
throw new UnsupportedOperationException("remove"); | ||
} | ||
|
||
@Override | ||
public void set(Object o) { | ||
throw new UnsupportedOperationException("set"); | ||
} | ||
|
||
@Override | ||
public void add(Object o) { | ||
throw new UnsupportedOperationException("add"); | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public boolean contains(Object o) { | ||
return set.contains(o); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return set.hashCode(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (o instanceof Set) return set.equals(o); | ||
return o instanceof Iterable && super.equals(o); | ||
} | ||
|
||
@Override | ||
public Spliterator<T> spliterator() { | ||
return set.spliterator(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.