Skip to content

Commit

Permalink
remove usage of apache commons collections
Browse files Browse the repository at this point in the history
  • Loading branch information
jbarrasa committed Jan 20, 2024
1 parent 3822d08 commit 276382c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 26 deletions.
39 changes: 15 additions & 24 deletions src/main/java/n10s/result/VirtualPath.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package n10s.result;

import org.apache.commons.collections.CollectionUtils;
import org.neo4j.graphdb.*;
import org.neo4j.graphdb.traversal.Paths;

Expand All @@ -10,9 +9,6 @@
import java.util.concurrent.atomic.AtomicReference;


//import static org.apache.commons.collections4.IterableUtils.reversedIterable;


public class VirtualPath implements Path {
private final Node start;
private final List<Relationship> relationships;
Expand Down Expand Up @@ -124,36 +120,31 @@ public String toString() {

private void requireConnected(Relationship relationship) {
final List<Node> previousNodes = getPreviousNodes();
boolean isRelConnectedToPrevious = CollectionUtils.containsAny( previousNodes, Arrays.asList(relationship.getNodes()) );
boolean isRelConnectedToPrevious = containsAny( previousNodes, Arrays.asList(relationship.getNodes()));
if (!isRelConnectedToPrevious) {
throw new IllegalArgumentException("Relationship is not part of current path.");
}
}

public static boolean containsAny(Collection<?> coll1, Collection<?> coll2) {
if (coll1 == null || coll2 == null) {
return false;
}

for (Object obj : coll1) {
if (coll2.contains(obj)) {
return true;
}
}

return false;
}

private List<Node> getPreviousNodes() {
Relationship previousRelationship = lastRelationship();
if (previousRelationship != null) {
return Arrays.asList(previousRelationship.getNodes());
}
return List.of(endNode());
}

public static final class Builder {
private final Node start;
private final List<Relationship> relationships = new ArrayList<>();

public Builder(Node start) {
this.start = start;
}

public Builder push(Relationship relationship) {
this.relationships.add(relationship);
return this;
}

public VirtualPath build() {
return new VirtualPath(start, relationships);
}

}
}
3 changes: 1 addition & 2 deletions src/main/java/n10s/similarity/Similarities.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ public Stream<SemanticSearchResult> lchSimSearch(@Name("node1") Node elem1, @Nam
Long worst_case_total_depth = (Long) tx.execute(String.format(globalMaxDepthQuery, subclassOfRel), queryParams).next().get("len");

queryParams.put("threshold_length", ((2.0 * worst_case_total_depth)/ Math.pow(10,minSim)));
//TODO: THIS IS NOT EFFICIENT: EXTRACT THE DEPTH COMPUTATION AND CACHE
System.out.println(String.format(shortestPathSearchWithMaxDepth, classLabel, subclassOfRel));
//TODO: MAKE THIS MORE EFFICIENT: EXTRACT THE DEPTH COMPUTATION AND CACHE
return tx.execute(String.format(shortestPathSearchWithMaxDepth, classLabel, subclassOfRel), queryParams).stream().map(SemanticSearchResult::new);
}

Expand Down

0 comments on commit 276382c

Please sign in to comment.