diff --git a/java/server/src/main/java/org/softwareheritage/graph/App.java b/java/server/src/main/java/org/softwareheritage/graph/App.java --- a/java/server/src/main/java/org/softwareheritage/graph/App.java +++ b/java/server/src/main/java/org/softwareheritage/graph/App.java @@ -21,7 +21,7 @@ import org.softwareheritage.graph.Endpoint; import org.softwareheritage.graph.Graph; -import org.softwareheritage.graph.SwhId; +import org.softwareheritage.graph.SwhPID; import org.softwareheritage.graph.algo.Stats; /** @@ -104,7 +104,7 @@ // By default the traversal is a forward DFS using all edges app.get("/leaves/:src", ctx -> { - SwhId src = new SwhId(ctx.pathParam("src")); + SwhPID src = new SwhPID(ctx.pathParam("src")); String direction = ctx.queryParam("direction", "forward"); String edgesFmt = ctx.queryParam("edges", "*"); @@ -114,7 +114,7 @@ }); app.get("/neighbors/:src", ctx -> { - SwhId src = new SwhId(ctx.pathParam("src")); + SwhPID src = new SwhPID(ctx.pathParam("src")); String direction = ctx.queryParam("direction", "forward"); String edgesFmt = ctx.queryParam("edges", "*"); @@ -124,7 +124,7 @@ }); app.get("/visit/nodes/:src", ctx -> { - SwhId src = new SwhId(ctx.pathParam("src")); + SwhPID src = new SwhPID(ctx.pathParam("src")); String direction = ctx.queryParam("direction", "forward"); String edgesFmt = ctx.queryParam("edges", "*"); @@ -134,7 +134,7 @@ }); app.get("/visit/paths/:src", ctx -> { - SwhId src = new SwhId(ctx.pathParam("src")); + SwhPID src = new SwhPID(ctx.pathParam("src")); String direction = ctx.queryParam("direction", "forward"); String edgesFmt = ctx.queryParam("edges", "*"); @@ -144,7 +144,7 @@ }); app.get("/walk/:src/:dst", ctx -> { - SwhId src = new SwhId(ctx.pathParam("src")); + SwhPID src = new SwhPID(ctx.pathParam("src")); String dstFmt = ctx.pathParam("dst"); String direction = ctx.queryParam("direction", "forward"); String edgesFmt = ctx.queryParam("edges", "*"); diff --git a/java/server/src/main/java/org/softwareheritage/graph/Endpoint.java b/java/server/src/main/java/org/softwareheritage/graph/Endpoint.java --- a/java/server/src/main/java/org/softwareheritage/graph/Endpoint.java +++ b/java/server/src/main/java/org/softwareheritage/graph/Endpoint.java @@ -3,7 +3,7 @@ import java.util.ArrayList; import org.softwareheritage.graph.Graph; -import org.softwareheritage.graph.SwhId; +import org.softwareheritage.graph.SwhPID; import org.softwareheritage.graph.SwhPath; import org.softwareheritage.graph.algo.Traversal; import org.softwareheritage.graph.utils.Timing; @@ -85,12 +85,12 @@ * @param nodeIds the list of long node ids * @return a list of corresponding SWH PIDs */ - private ArrayList convertNodesToSwhIds(ArrayList nodeIds) { - ArrayList swhIds = new ArrayList<>(); + private ArrayList convertNodesToSwhPIDs(ArrayList nodeIds) { + ArrayList swhPIDs = new ArrayList<>(); for (long nodeId : nodeIds) { - swhIds.add(graph.getSwhId(nodeId)); + swhPIDs.add(graph.getSwhPID(nodeId)); } - return swhIds; + return swhPIDs; } /** @@ -103,7 +103,7 @@ private SwhPath convertNodesToSwhPath(ArrayList nodeIds) { SwhPath path = new SwhPath(); for (long nodeId : nodeIds) { - path.add(graph.getSwhId(nodeId)); + path.add(graph.getSwhPID(nodeId)); } return path; } @@ -115,7 +115,7 @@ * @return a list of corresponding {@link SwhPath} * @see org.softwareheritage.graph.SwhPath */ - private ArrayList convertPathsToSwhIds(ArrayList> pathsNodeId) { + private ArrayList convertPathsToSwhPIDs(ArrayList> pathsNodeId) { ArrayList paths = new ArrayList<>(); for (ArrayList path : pathsNodeId) { paths.add(convertNodesToSwhPath(path)); @@ -126,13 +126,13 @@ /** * Leaves endpoint wrapper. * - * @param src source node of endpoint call specified as a {@link SwhId} - * @return the resulting list of {@link SwhId} from endpoint call and operation metadata - * @see org.softwareheritage.graph.SwhId + * @param src source node of endpoint call specified as a {@link SwhPID} + * @return the resulting list of {@link SwhPID} from endpoint call and operation metadata + * @see org.softwareheritage.graph.SwhPID * @see org.softwareheritage.graph.algo.Traversal#leaves(long) */ - public Output leaves(SwhId src) { - Output> output = new Output<>(); + public Output leaves(SwhPID src) { + Output> output = new Output<>(); long startTime; startTime = Timing.start(); @@ -144,7 +144,7 @@ output.meta.timings.traversal = Timing.stop(startTime); startTime = Timing.start(); - output.result = convertNodesToSwhIds(nodeIds); + output.result = convertNodesToSwhPIDs(nodeIds); output.meta.timings.node2pid = Timing.stop(startTime); return output; @@ -153,13 +153,13 @@ /** * Neighbors endpoint wrapper. * - * @param src source node of endpoint call specified as a {@link SwhId} - * @return the resulting list of {@link SwhId} from endpoint call and operation metadata - * @see org.softwareheritage.graph.SwhId + * @param src source node of endpoint call specified as a {@link SwhPID} + * @return the resulting list of {@link SwhPID} from endpoint call and operation metadata + * @see org.softwareheritage.graph.SwhPID * @see org.softwareheritage.graph.algo.Traversal#neighbors(long) */ - public Output neighbors(SwhId src) { - Output> output = new Output<>(); + public Output neighbors(SwhPID src) { + Output> output = new Output<>(); long startTime; startTime = Timing.start(); @@ -171,7 +171,7 @@ output.meta.timings.traversal = Timing.stop(startTime); startTime = Timing.start(); - output.result = convertNodesToSwhIds(nodeIds); + output.result = convertNodesToSwhPIDs(nodeIds); output.meta.timings.node2pid = Timing.stop(startTime); return output; @@ -180,16 +180,16 @@ /** * Walk endpoint wrapper. * - * @param src source node of endpoint call specified as a {@link SwhId} + * @param src source node of endpoint call specified as a {@link SwhPID} * @param dstFmt destination formatted string as described in the API * @param algorithm traversal algorithm used in endpoint call (either "dfs" or "bfs") * @return the resulting {@link SwhPath} from endpoint call and operation metadata - * @see org.softwareheritage.graph.SwhId + * @see org.softwareheritage.graph.SwhPID * @see org.softwareheritage.graph.SwhPath * @see org.softwareheritage.graph.algo.Traversal#walk */ - public Output walk(SwhId src, String dstFmt, String algorithm) { + public Output walk(SwhPID src, String dstFmt, String algorithm) { Output output = new Output<>(); long startTime; @@ -199,10 +199,10 @@ ArrayList nodeIds = new ArrayList(); - // Destination is either a SWH ID or a node type + // Destination is either a SWH PID or a node type try { - SwhId dstSwhId = new SwhId(dstFmt); - long dstNodeId = graph.getNodeId(dstSwhId); + SwhPID dstSwhPID = new SwhPID(dstFmt); + long dstNodeId = graph.getNodeId(dstSwhPID); startTime = Timing.start(); nodeIds = traversal.walk(srcNodeId, dstNodeId, algorithm); @@ -227,13 +227,13 @@ /** * VisitNodes endpoint wrapper. * - * @param src source node of endpoint call specified as a {@link SwhId} - * @return the resulting list of {@link SwhId} from endpoint call and operation metadata - * @see org.softwareheritage.graph.SwhId + * @param src source node of endpoint call specified as a {@link SwhPID} + * @return the resulting list of {@link SwhPID} from endpoint call and operation metadata + * @see org.softwareheritage.graph.SwhPID * @see org.softwareheritage.graph.algo.Traversal#visitNodes(long) */ - public Output visitNodes(SwhId src) { - Output> output = new Output<>(); + public Output visitNodes(SwhPID src) { + Output> output = new Output<>(); long startTime; startTime = Timing.start(); @@ -245,7 +245,7 @@ output.meta.timings.traversal = Timing.stop(startTime); startTime = Timing.start(); - output.result = convertNodesToSwhIds(nodeIds); + output.result = convertNodesToSwhPIDs(nodeIds); output.meta.timings.node2pid = Timing.stop(startTime); return output; @@ -254,13 +254,13 @@ /** * VisitPaths endpoint wrapper. * - * @param src source node of endpoint call specified as a {@link SwhId} + * @param src source node of endpoint call specified as a {@link SwhPID} * @return the resulting list of {@link SwhPath} from endpoint call and operation metadata - * @see org.softwareheritage.graph.SwhId + * @see org.softwareheritage.graph.SwhPID * @see org.softwareheritage.graph.SwhPath * @see org.softwareheritage.graph.algo.Traversal#visitPaths(long) */ - public Output visitPaths(SwhId src) { + public Output visitPaths(SwhPID src) { Output> output = new Output<>(); long startTime; @@ -273,7 +273,7 @@ output.meta.timings.traversal = Timing.stop(startTime); startTime = Timing.start(); - output.result = convertPathsToSwhIds(paths); + output.result = convertPathsToSwhPIDs(paths); output.meta.timings.node2pid = Timing.stop(startTime); return output; diff --git a/java/server/src/main/java/org/softwareheritage/graph/Graph.java b/java/server/src/main/java/org/softwareheritage/graph/Graph.java --- a/java/server/src/main/java/org/softwareheritage/graph/Graph.java +++ b/java/server/src/main/java/org/softwareheritage/graph/Graph.java @@ -6,7 +6,7 @@ import it.unimi.dsi.big.webgraph.LazyLongIterator; import org.softwareheritage.graph.Node; -import org.softwareheritage.graph.SwhId; +import org.softwareheritage.graph.SwhPID; import org.softwareheritage.graph.backend.NodeIdMap; import org.softwareheritage.graph.backend.NodeTypesMap; @@ -79,25 +79,25 @@ } /** - * Converts {@link SwhId} node to long. + * Converts {@link SwhPID} node to long. * - * @param swhId node specified as a {@link SwhId} + * @param swhPID node specified as a {@link SwhPID} * @return internal long node id - * @see org.softwareheritage.graph.SwhId + * @see org.softwareheritage.graph.SwhPID */ - public long getNodeId(SwhId swhId) { - return nodeIdMap.getNodeId(swhId); + public long getNodeId(SwhPID swhPID) { + return nodeIdMap.getNodeId(swhPID); } /** - * Converts long id node to {@link SwhId}. + * Converts long id node to {@link SwhPID}. * * @param nodeId node specified as a long id * @return external SWH PID - * @see org.softwareheritage.graph.SwhId + * @see org.softwareheritage.graph.SwhPID */ - public SwhId getSwhId(long nodeId) { - return nodeIdMap.getSwhId(nodeId); + public SwhPID getSwhPID(long nodeId) { + return nodeIdMap.getSwhPID(nodeId); } /** diff --git a/java/server/src/main/java/org/softwareheritage/graph/SwhId.java b/java/server/src/main/java/org/softwareheritage/graph/SwhPID.java rename from java/server/src/main/java/org/softwareheritage/graph/SwhId.java rename to java/server/src/main/java/org/softwareheritage/graph/SwhPID.java --- a/java/server/src/main/java/org/softwareheritage/graph/SwhId.java +++ b/java/server/src/main/java/org/softwareheritage/graph/SwhPID.java @@ -14,12 +14,12 @@ * @since 0.0.1 */ -public class SwhId { +public class SwhPID { /** Fixed hash length of the PID */ public static final int HASH_LENGTH = 40; /** Full PID as a string */ - String swhId; + String swhPID; /** PID node type */ Node.Type type; /** PID hex-encoded SHA1 hash */ @@ -28,42 +28,42 @@ /** * Constructor. * - * @param swhId full PID as a string + * @param swhPID full PID as a string */ - public SwhId(String swhId) { - this.swhId = swhId; + public SwhPID(String swhPID) { + this.swhPID = swhPID; // PID format: 'swh:1:type:hash' - String[] parts = swhId.split(":"); + String[] parts = swhPID.split(":"); if (parts.length != 4 || !parts[0].equals("swh") || !parts[1].equals("1")) { - throw new IllegalArgumentException("Expected SWH ID format to be 'swh:1:type:hash', got: " + swhId); + throw new IllegalArgumentException("Expected SWH PID format to be 'swh:1:type:hash', got: " + swhPID); } this.type = Node.Type.fromStr(parts[2]); this.hash = parts[3]; if (!hash.matches("[0-9a-f]{" + HASH_LENGTH + "}")) { - throw new IllegalArgumentException("Wrong SWH ID hash format in: " + swhId); + throw new IllegalArgumentException("Wrong SWH PID hash format in: " + swhPID); } } @Override public boolean equals(Object otherObj) { if (otherObj == this) return true; - if (!(otherObj instanceof SwhId)) return false; + if (!(otherObj instanceof SwhPID)) return false; - SwhId other = (SwhId) otherObj; - return swhId.equals(other.getSwhId()); + SwhPID other = (SwhPID) otherObj; + return swhPID.equals(other.getSwhPID()); } @Override public int hashCode() { - return swhId.hashCode(); + return swhPID.hashCode(); } @Override public String toString() { - return swhId; + return swhPID; } /** @@ -72,8 +72,8 @@ * @return full PID string */ @JsonValue - public String getSwhId() { - return swhId; + public String getSwhPID() { + return swhPID; } /** diff --git a/java/server/src/main/java/org/softwareheritage/graph/SwhPath.java b/java/server/src/main/java/org/softwareheritage/graph/SwhPath.java --- a/java/server/src/main/java/org/softwareheritage/graph/SwhPath.java +++ b/java/server/src/main/java/org/softwareheritage/graph/SwhPath.java @@ -4,82 +4,82 @@ import com.fasterxml.jackson.annotation.JsonValue; -import org.softwareheritage.graph.SwhId; +import org.softwareheritage.graph.SwhPID; /** - * Wrapper class to store a list of {@link SwhId}. + * Wrapper class to store a list of {@link SwhPID}. * * @author Thibault Allançon * @version 0.0.1 * @since 0.0.1 - * @see org.softwareheritage.graph.SwhId + * @see org.softwareheritage.graph.SwhPID */ public class SwhPath { - /** Internal list of {@link SwhId} */ - ArrayList path; + /** Internal list of {@link SwhPID} */ + ArrayList path; /** * Constructor. */ public SwhPath() { - this.path = new ArrayList(); + this.path = new ArrayList(); } /** * Constructor. * - * @param swhIds variable number of string PIDs to initialize this path with + * @param swhPIDs variable number of string PIDs to initialize this path with */ - public SwhPath(String ...swhIds) { + public SwhPath(String ...swhPIDs) { this(); - for (String swhId : swhIds) { - add(new SwhId(swhId)); + for (String swhPID : swhPIDs) { + add(new SwhPID(swhPID)); } } /** * Constructor. * - * @param swhIds variable number of {@link SwhId} to initialize this path with - * @see org.softwareheritage.graph.SwhId + * @param swhPIDs variable number of {@link SwhPID} to initialize this path with + * @see org.softwareheritage.graph.SwhPID */ - public SwhPath(SwhId ...swhIds) { + public SwhPath(SwhPID ...swhPIDs) { this(); - for (SwhId swhId : swhIds) { - add(swhId); + for (SwhPID swhPID : swhPIDs) { + add(swhPID); } } /** - * Returns this path as a list of {@link SwhId}. + * Returns this path as a list of {@link SwhPID}. * - * @return list of {@link SwhId} constituting the path - * @see org.softwareheritage.graph.SwhId + * @return list of {@link SwhPID} constituting the path + * @see org.softwareheritage.graph.SwhPID */ @JsonValue - public ArrayList getPath() { + public ArrayList getPath() { return path; } /** - * Adds a {@link SwhId} to this path. + * Adds a {@link SwhPID} to this path. * - * @param {@link SwhId} to add to this path - * @see org.softwareheritage.graph.SwhId + * @param {@link SwhPID} to add to this path + * @see org.softwareheritage.graph.SwhPID */ - public void add(SwhId swhId) { - path.add(swhId); + public void add(SwhPID swhPID) { + path.add(swhPID); } /** - * Returns the {@link SwhId} at the specified position in this path. + * Returns the {@link SwhPID} at the specified position in this path. * - * @param index position of the {@link SwhId} to return - * @return {@link SwhId} at the specified position - * @see org.softwareheritage.graph.SwhId + * @param index position of the {@link SwhPID} to return + * @return {@link SwhPID} at the specified position + * @see org.softwareheritage.graph.SwhPID */ - public SwhId get(int index) { + public SwhPID get(int index) { return path.get(index); } @@ -103,9 +103,9 @@ } for (int i = 0; i < size(); i++) { - SwhId thisSwhId = get(i); - SwhId otherSwhId = other.get(i); - if (!thisSwhId.equals(otherSwhId)) { + SwhPID thisSwhPID = get(i); + SwhPID otherSwhPID = other.get(i); + if (!thisSwhPID.equals(otherSwhPID)) { return false; } } @@ -116,8 +116,8 @@ @Override public String toString() { String str = new String(); - for (SwhId swhId : path) { - str += swhId + "/"; + for (SwhPID swhPID : path) { + str += swhPID + "/"; } return str; } diff --git a/java/server/src/main/java/org/softwareheritage/graph/backend/NodeIdMap.java b/java/server/src/main/java/org/softwareheritage/graph/backend/NodeIdMap.java --- a/java/server/src/main/java/org/softwareheritage/graph/backend/NodeIdMap.java +++ b/java/server/src/main/java/org/softwareheritage/graph/backend/NodeIdMap.java @@ -3,7 +3,7 @@ import java.io.IOException; import org.softwareheritage.graph.Graph; -import org.softwareheritage.graph.SwhId; +import org.softwareheritage.graph.SwhPID; import org.softwareheritage.graph.backend.MapFile; import org.softwareheritage.graph.backend.Setup; @@ -54,13 +54,13 @@ /** * Converts SWH PID to corresponding long node id. * - * @param swhId node represented as a {@link SwhId} + * @param swhPID node represented as a {@link SwhPID} * @return corresponding node as a long id - * @see org.softwareheritage.graph.SwhId + * @see org.softwareheritage.graph.SwhPID */ - public long getNodeId(SwhId swhId) { - // Each line in PID_TO_NODE is formatted as: swhId nodeId - // The file is sorted by swhId, hence we can binary search on swhId to get corresponding nodeId + public long getNodeId(SwhPID swhPID) { + // Each line in PID_TO_NODE is formatted as: swhPID nodeId + // The file is sorted by swhPID, hence we can binary search on swhPID to get corresponding nodeId long start = 0; long end = nbIds - 1; @@ -71,10 +71,10 @@ break; } - String currentSwhId = parts[0]; + String currentSwhPID = parts[0]; long currentNodeId = Long.parseLong(parts[1]); - int cmp = currentSwhId.compareTo(swhId.toString()); + int cmp = currentSwhPID.compareTo(swhPID.toString()); if (cmp == 0) { return currentNodeId; } else if (cmp < 0) { @@ -84,26 +84,26 @@ } } - throw new IllegalArgumentException("Unknown SWH id: " + swhId); + throw new IllegalArgumentException("Unknown SWH PID: " + swhPID); } /** * Converts a node long id to corresponding SWH PID. * * @param nodeId node as a long id - * @return corresponding node as a {@link SwhId} - * @see org.softwareheritage.graph.SwhId + * @return corresponding node as a {@link SwhPID} + * @see org.softwareheritage.graph.SwhPID */ - public SwhId getSwhId(long nodeId) { - // Each line in NODE_TO_PID is formatted as: swhId - // The file is ordered by nodeId, meaning node0's swhId is at line 0, hence we can read the - // nodeId-th line to get corresponding swhId + public SwhPID getSwhPID(long nodeId) { + // Each line in NODE_TO_PID is formatted as: swhPID + // The file is ordered by nodeId, meaning node0's swhPID is at line 0, hence we can read the + // nodeId-th line to get corresponding swhPID if (nodeId < 0 || nodeId >= nbIds) { throw new IllegalArgumentException("Node id " + nodeId + " should be between 0 and " + nbIds); } - String swhId = nodeToSwhMap.readAtLine(nodeId); - return new SwhId(swhId); + String swhPID = nodeToSwhMap.readAtLine(nodeId); + return new SwhPID(swhPID); } /** diff --git a/java/server/src/main/java/org/softwareheritage/graph/backend/Setup.java b/java/server/src/main/java/org/softwareheritage/graph/backend/Setup.java --- a/java/server/src/main/java/org/softwareheritage/graph/backend/Setup.java +++ b/java/server/src/main/java/org/softwareheritage/graph/backend/Setup.java @@ -21,7 +21,7 @@ import org.softwareheritage.graph.Graph; import org.softwareheritage.graph.Node; -import org.softwareheritage.graph.SwhId; +import org.softwareheritage.graph.SwhPID; import org.softwareheritage.graph.backend.NodeTypesMap; /** @@ -64,7 +64,7 @@ // Suppress warning for Object2LongFunction cast @SuppressWarnings("unchecked") static void precomputeNodeIdMap(String nodesPath, String graphPath) throws IOException { - // First internal mapping: SWH id (string) -> WebGraph MPH (long) + // First internal mapping: SWH PID (string) -> WebGraph MPH (long) Object2LongFunction mphMap = null; try { mphMap = (Object2LongFunction) BinIO.loadObject(graphPath + ".mph"); @@ -80,16 +80,16 @@ throw new IllegalArgumentException("Graph contains " + nbIds + " nodes, but read " + loaded); } - // Dump complete mapping for all nodes: SWH id (string) <=> WebGraph node id (long) + // Dump complete mapping for all nodes: SWH PID (string) <=> WebGraph node id (long) InputStream nodesStream = new GZIPInputStream(new FileInputStream(nodesPath)); FastBufferedReader buffer = new FastBufferedReader(new InputStreamReader(nodesStream, "UTF-8")); - LineIterator swhIdIterator = new LineIterator(buffer); + LineIterator swhPIDIterator = new LineIterator(buffer); try (Writer swhToNodeMap = new BufferedWriter(new FileWriter(graphPath + Graph.PID_TO_NODE)); Writer nodeToSwhMap = new BufferedWriter(new FileWriter(graphPath + Graph.NODE_TO_PID))) { - // nodeToSwhMap needs to write SWH id in order of node id, so use a temporary array - Object[][] nodeToSwhId = ObjectBigArrays.newBigArray(nbIds); + // nodeToSwhMap needs to write SWH PID in order of node id, so use a temporary array + Object[][] nodeToSwhPID = ObjectBigArrays.newBigArray(nbIds); // To effectively run edge restriction during graph traversals, we store node id (long) -> SWH // type map. This is represented as a bitmap using minimum number of bits per Node.Type. @@ -99,25 +99,25 @@ LongArrayBitVector.ofLength(nbBitsPerNodeType * nbIds); LongBigList nodeTypesMap = nodeTypesBitVector.asLongBigList(nbBitsPerNodeType); - for (long iNode = 0; iNode < nbIds && swhIdIterator.hasNext(); iNode++) { - String strSwhId = swhIdIterator.next().toString(); - long mphId = mphMap.getLong(strSwhId); + for (long iNode = 0; iNode < nbIds && swhPIDIterator.hasNext(); iNode++) { + String strSwhPID = swhPIDIterator.next().toString(); + long mphId = mphMap.getLong(strSwhPID); long nodeId = LongBigArrays.get(bfsMap, mphId); String paddedNodeId = String.format("%0" + NodeIdMap.NODE_ID_LENGTH + "d", nodeId); - String line = strSwhId + " " + paddedNodeId + "\n"; + String line = strSwhPID + " " + paddedNodeId + "\n"; swhToNodeMap.write(line); - ObjectBigArrays.set(nodeToSwhId, nodeId, strSwhId); + ObjectBigArrays.set(nodeToSwhPID, nodeId, strSwhPID); - SwhId swhId = new SwhId(strSwhId); - nodeTypesMap.set(nodeId, swhId.getType().ordinal()); + SwhPID swhPID = new SwhPID(strSwhPID); + nodeTypesMap.set(nodeId, swhPID.getType().ordinal()); } BinIO.storeObject(nodeTypesMap, graphPath + Graph.NODE_TO_TYPE); for (long iNode = 0; iNode < nbIds; iNode++) { - String line = ObjectBigArrays.get(nodeToSwhId, iNode).toString() + "\n"; + String line = ObjectBigArrays.get(nodeToSwhPID, iNode).toString() + "\n"; nodeToSwhMap.write(line); } } diff --git a/java/server/src/test/java/org/softwareheritage/graph/LeavesTest.java b/java/server/src/test/java/org/softwareheritage/graph/LeavesTest.java --- a/java/server/src/test/java/org/softwareheritage/graph/LeavesTest.java +++ b/java/server/src/test/java/org/softwareheritage/graph/LeavesTest.java @@ -7,7 +7,7 @@ import org.softwareheritage.graph.Endpoint; import org.softwareheritage.graph.Graph; import org.softwareheritage.graph.GraphTest; -import org.softwareheritage.graph.SwhId; +import org.softwareheritage.graph.SwhPID; // Avoid warnings concerning Endpoint.Output.result manual cast @SuppressWarnings("unchecked") @@ -15,14 +15,14 @@ @Test public void forwardFromSnp() { Graph graph = getGraph(); - SwhId src = new SwhId("swh:1:snp:0000000000000000000000000000000000000020"); + SwhPID src = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); Endpoint endpoint = new Endpoint(graph, "forward", "*"); - ArrayList expectedLeaves = new ArrayList<>(); - expectedLeaves.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000001")); - expectedLeaves.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000004")); - expectedLeaves.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000005")); - expectedLeaves.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000007")); + ArrayList expectedLeaves = new ArrayList<>(); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001")); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004")); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000005")); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007")); GraphTest.assertEqualsAnyOrder(expectedLeaves, (ArrayList) endpoint.leaves(src).result); } @@ -30,17 +30,17 @@ @Test public void forwardFromRel() { Graph graph = getGraph(); - SwhId src = new SwhId("swh:1:rel:0000000000000000000000000000000000000019"); + SwhPID src = new SwhPID("swh:1:rel:0000000000000000000000000000000000000019"); Endpoint endpoint = new Endpoint(graph, "forward", "*"); - ArrayList expectedLeaves = new ArrayList<>(); - expectedLeaves.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000015")); - expectedLeaves.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000014")); - expectedLeaves.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000001")); - expectedLeaves.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000004")); - expectedLeaves.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000005")); - expectedLeaves.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000007")); - expectedLeaves.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000011")); + ArrayList expectedLeaves = new ArrayList<>(); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000015")); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000014")); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001")); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004")); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000005")); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007")); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000011")); GraphTest.assertEqualsAnyOrder(expectedLeaves, (ArrayList) endpoint.leaves(src).result); } @@ -50,26 +50,26 @@ Graph graph = getGraph(); Endpoint endpoint = new Endpoint(graph, "backward", "*"); - SwhId src1 = new SwhId("swh:1:cnt:0000000000000000000000000000000000000015"); - ArrayList expectedLeaves1 = new ArrayList<>(); - expectedLeaves1.add(new SwhId("swh:1:rel:0000000000000000000000000000000000000019")); + SwhPID src1 = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000015"); + ArrayList expectedLeaves1 = new ArrayList<>(); + expectedLeaves1.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000019")); GraphTest.assertEqualsAnyOrder(expectedLeaves1, (ArrayList) endpoint.leaves(src1).result); - SwhId src2 = new SwhId("swh:1:cnt:0000000000000000000000000000000000000004"); - ArrayList expectedLeaves2 = new ArrayList<>(); - expectedLeaves2.add(new SwhId("swh:1:ori:0000000000000000000000000000000000000021")); - expectedLeaves2.add(new SwhId("swh:1:rel:0000000000000000000000000000000000000019")); + SwhPID src2 = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004"); + ArrayList expectedLeaves2 = new ArrayList<>(); + expectedLeaves2.add(new SwhPID("swh:1:ori:0000000000000000000000000000000000000021")); + expectedLeaves2.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000019")); GraphTest.assertEqualsAnyOrder(expectedLeaves2, (ArrayList) endpoint.leaves(src2).result); } @Test public void forwardRevToRevOnly() { Graph graph = getGraph(); - SwhId src = new SwhId("swh:1:rev:0000000000000000000000000000000000000018"); + SwhPID src = new SwhPID("swh:1:rev:0000000000000000000000000000000000000018"); Endpoint endpoint = new Endpoint(graph, "forward", "rev:rev"); - ArrayList expectedLeaves = new ArrayList<>(); - expectedLeaves.add(new SwhId("swh:1:rev:0000000000000000000000000000000000000003")); + ArrayList expectedLeaves = new ArrayList<>(); + expectedLeaves.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000003")); GraphTest.assertEqualsAnyOrder(expectedLeaves, (ArrayList) endpoint.leaves(src).result); } @@ -77,14 +77,14 @@ @Test public void forwardDirToAll() { Graph graph = getGraph(); - SwhId src = new SwhId("swh:1:dir:0000000000000000000000000000000000000008"); + SwhPID src = new SwhPID("swh:1:dir:0000000000000000000000000000000000000008"); Endpoint endpoint = new Endpoint(graph, "forward", "dir:*"); - ArrayList expectedLeaves = new ArrayList<>(); - expectedLeaves.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000004")); - expectedLeaves.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000005")); - expectedLeaves.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000001")); - expectedLeaves.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000007")); + ArrayList expectedLeaves = new ArrayList<>(); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004")); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000005")); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001")); + expectedLeaves.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007")); GraphTest.assertEqualsAnyOrder(expectedLeaves, (ArrayList) endpoint.leaves(src).result); } @@ -92,11 +92,11 @@ @Test public void backwardCntToDirDirToDir() { Graph graph = getGraph(); - SwhId src = new SwhId("swh:1:cnt:0000000000000000000000000000000000000005"); + SwhPID src = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000005"); Endpoint endpoint = new Endpoint(graph, "backward", "cnt:dir,dir:dir"); - ArrayList expectedLeaves = new ArrayList<>(); - expectedLeaves.add(new SwhId("swh:1:dir:0000000000000000000000000000000000000012")); + ArrayList expectedLeaves = new ArrayList<>(); + expectedLeaves.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000012")); GraphTest.assertEqualsAnyOrder(expectedLeaves, (ArrayList) endpoint.leaves(src).result); } diff --git a/java/server/src/test/java/org/softwareheritage/graph/NeighborsTest.java b/java/server/src/test/java/org/softwareheritage/graph/NeighborsTest.java --- a/java/server/src/test/java/org/softwareheritage/graph/NeighborsTest.java +++ b/java/server/src/test/java/org/softwareheritage/graph/NeighborsTest.java @@ -7,7 +7,7 @@ import org.softwareheritage.graph.Endpoint; import org.softwareheritage.graph.Graph; import org.softwareheritage.graph.GraphTest; -import org.softwareheritage.graph.SwhId; +import org.softwareheritage.graph.SwhPID; // Avoid warnings concerning Endpoint.Output.result manual cast @SuppressWarnings("unchecked") @@ -15,25 +15,25 @@ @Test public void zeroNeighbor() { Graph graph = getGraph(); - ArrayList expectedNodes = new ArrayList<>(); + ArrayList expectedNodes = new ArrayList<>(); - SwhId src1 = new SwhId("swh:1:ori:0000000000000000000000000000000000000021"); + SwhPID src1 = new SwhPID("swh:1:ori:0000000000000000000000000000000000000021"); Endpoint endpoint1 = new Endpoint(graph, "backward", "*"); GraphTest.assertEqualsAnyOrder(expectedNodes, (ArrayList) endpoint1.neighbors(src1).result); - SwhId src2 = new SwhId("swh:1:cnt:0000000000000000000000000000000000000004"); + SwhPID src2 = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004"); Endpoint endpoint2 = new Endpoint(graph, "forward", "*"); GraphTest.assertEqualsAnyOrder(expectedNodes, (ArrayList) endpoint2.neighbors(src2).result); - SwhId src3 = new SwhId("swh:1:cnt:0000000000000000000000000000000000000015"); + SwhPID src3 = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000015"); Endpoint endpoint3 = new Endpoint(graph, "forward", "*"); GraphTest.assertEqualsAnyOrder(expectedNodes, (ArrayList) endpoint3.neighbors(src3).result); - SwhId src4 = new SwhId("swh:1:rel:0000000000000000000000000000000000000019"); + SwhPID src4 = new SwhPID("swh:1:rel:0000000000000000000000000000000000000019"); Endpoint endpoint4 = new Endpoint(graph, "backward", "*"); GraphTest.assertEqualsAnyOrder(expectedNodes, (ArrayList) endpoint4.neighbors(src4).result); - SwhId src5 = new SwhId("swh:1:dir:0000000000000000000000000000000000000008"); + SwhPID src5 = new SwhPID("swh:1:dir:0000000000000000000000000000000000000008"); Endpoint endpoint5 = new Endpoint(graph, "forward", "snp:*,rev:*,rel:*"); GraphTest.assertEqualsAnyOrder(expectedNodes, (ArrayList) endpoint5.neighbors(src5).result); } @@ -42,34 +42,34 @@ public void oneNeighbor() { Graph graph = getGraph(); - SwhId src1 = new SwhId("swh:1:rev:0000000000000000000000000000000000000003"); + SwhPID src1 = new SwhPID("swh:1:rev:0000000000000000000000000000000000000003"); Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); - ArrayList expectedNodes1 = new ArrayList<>(); - expectedNodes1.add(new SwhId("swh:1:dir:0000000000000000000000000000000000000002")); + ArrayList expectedNodes1 = new ArrayList<>(); + expectedNodes1.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000002")); GraphTest.assertEqualsAnyOrder(expectedNodes1, (ArrayList) endpoint1.neighbors(src1).result); - SwhId src2 = new SwhId("swh:1:dir:0000000000000000000000000000000000000017"); + SwhPID src2 = new SwhPID("swh:1:dir:0000000000000000000000000000000000000017"); Endpoint endpoint2 = new Endpoint(graph, "forward", "dir:cnt"); - ArrayList expectedNodes2 = new ArrayList<>(); - expectedNodes2.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000014")); + ArrayList expectedNodes2 = new ArrayList<>(); + expectedNodes2.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000014")); GraphTest.assertEqualsAnyOrder(expectedNodes2, (ArrayList) endpoint2.neighbors(src2).result); - SwhId src3 = new SwhId("swh:1:dir:0000000000000000000000000000000000000012"); + SwhPID src3 = new SwhPID("swh:1:dir:0000000000000000000000000000000000000012"); Endpoint endpoint3 = new Endpoint(graph, "backward", "*"); - ArrayList expectedNodes3 = new ArrayList<>(); - expectedNodes3.add(new SwhId("swh:1:rev:0000000000000000000000000000000000000013")); + ArrayList expectedNodes3 = new ArrayList<>(); + expectedNodes3.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000013")); GraphTest.assertEqualsAnyOrder(expectedNodes3, (ArrayList) endpoint3.neighbors(src3).result); - SwhId src4 = new SwhId("swh:1:rev:0000000000000000000000000000000000000009"); + SwhPID src4 = new SwhPID("swh:1:rev:0000000000000000000000000000000000000009"); Endpoint endpoint4 = new Endpoint(graph, "backward", "rev:rev"); - ArrayList expectedNodes4 = new ArrayList<>(); - expectedNodes4.add(new SwhId("swh:1:rev:0000000000000000000000000000000000000013")); + ArrayList expectedNodes4 = new ArrayList<>(); + expectedNodes4.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000013")); GraphTest.assertEqualsAnyOrder(expectedNodes4, (ArrayList) endpoint4.neighbors(src4).result); - SwhId src5 = new SwhId("swh:1:snp:0000000000000000000000000000000000000020"); + SwhPID src5 = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); Endpoint endpoint5 = new Endpoint(graph, "backward", "*"); - ArrayList expectedNodes5 = new ArrayList<>(); - expectedNodes5.add(new SwhId("swh:1:ori:0000000000000000000000000000000000000021")); + ArrayList expectedNodes5 = new ArrayList<>(); + expectedNodes5.add(new SwhPID("swh:1:ori:0000000000000000000000000000000000000021")); GraphTest.assertEqualsAnyOrder(expectedNodes5, (ArrayList) endpoint5.neighbors(src5).result); } @@ -77,32 +77,32 @@ public void twoNeighbors() { Graph graph = getGraph(); - SwhId src1 = new SwhId("swh:1:snp:0000000000000000000000000000000000000020"); + SwhPID src1 = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); - ArrayList expectedNodes1 = new ArrayList<>(); - expectedNodes1.add(new SwhId("swh:1:rel:0000000000000000000000000000000000000010")); - expectedNodes1.add(new SwhId("swh:1:rev:0000000000000000000000000000000000000009")); + ArrayList expectedNodes1 = new ArrayList<>(); + expectedNodes1.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000010")); + expectedNodes1.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000009")); GraphTest.assertEqualsAnyOrder(expectedNodes1, (ArrayList) endpoint1.neighbors(src1).result); - SwhId src2 = new SwhId("swh:1:dir:0000000000000000000000000000000000000008"); + SwhPID src2 = new SwhPID("swh:1:dir:0000000000000000000000000000000000000008"); Endpoint endpoint2 = new Endpoint(graph, "forward", "dir:cnt"); - ArrayList expectedNodes2 = new ArrayList<>(); - expectedNodes2.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000001")); - expectedNodes2.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000007")); + ArrayList expectedNodes2 = new ArrayList<>(); + expectedNodes2.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001")); + expectedNodes2.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007")); GraphTest.assertEqualsAnyOrder(expectedNodes2, (ArrayList) endpoint2.neighbors(src2).result); - SwhId src3 = new SwhId("swh:1:cnt:0000000000000000000000000000000000000001"); + SwhPID src3 = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001"); Endpoint endpoint3 = new Endpoint(graph, "backward", "*"); - ArrayList expectedNodes3 = new ArrayList<>(); - expectedNodes3.add(new SwhId("swh:1:dir:0000000000000000000000000000000000000008")); - expectedNodes3.add(new SwhId("swh:1:dir:0000000000000000000000000000000000000002")); + ArrayList expectedNodes3 = new ArrayList<>(); + expectedNodes3.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000008")); + expectedNodes3.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000002")); GraphTest.assertEqualsAnyOrder(expectedNodes3, (ArrayList) endpoint3.neighbors(src3).result); - SwhId src4 = new SwhId("swh:1:rev:0000000000000000000000000000000000000009"); + SwhPID src4 = new SwhPID("swh:1:rev:0000000000000000000000000000000000000009"); Endpoint endpoint4 = new Endpoint(graph, "backward", "rev:snp,rev:rel"); - ArrayList expectedNodes4 = new ArrayList<>(); - expectedNodes4.add(new SwhId("swh:1:snp:0000000000000000000000000000000000000020")); - expectedNodes4.add(new SwhId("swh:1:rel:0000000000000000000000000000000000000010")); + ArrayList expectedNodes4 = new ArrayList<>(); + expectedNodes4.add(new SwhPID("swh:1:snp:0000000000000000000000000000000000000020")); + expectedNodes4.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000010")); GraphTest.assertEqualsAnyOrder(expectedNodes4, (ArrayList) endpoint4.neighbors(src4).result); } @@ -110,20 +110,20 @@ public void threeNeighbors() { Graph graph = getGraph(); - SwhId src1 = new SwhId("swh:1:dir:0000000000000000000000000000000000000008"); + SwhPID src1 = new SwhPID("swh:1:dir:0000000000000000000000000000000000000008"); Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); - ArrayList expectedNodes1 = new ArrayList<>(); - expectedNodes1.add(new SwhId("swh:1:dir:0000000000000000000000000000000000000006")); - expectedNodes1.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000001")); - expectedNodes1.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000007")); + ArrayList expectedNodes1 = new ArrayList<>(); + expectedNodes1.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000006")); + expectedNodes1.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001")); + expectedNodes1.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007")); GraphTest.assertEqualsAnyOrder(expectedNodes1, (ArrayList) endpoint1.neighbors(src1).result); - SwhId src2 = new SwhId("swh:1:rev:0000000000000000000000000000000000000009"); + SwhPID src2 = new SwhPID("swh:1:rev:0000000000000000000000000000000000000009"); Endpoint endpoint2 = new Endpoint(graph, "backward", "*"); - ArrayList expectedNodes2 = new ArrayList<>(); - expectedNodes2.add(new SwhId("swh:1:snp:0000000000000000000000000000000000000020")); - expectedNodes2.add(new SwhId("swh:1:rel:0000000000000000000000000000000000000010")); - expectedNodes2.add(new SwhId("swh:1:rev:0000000000000000000000000000000000000013")); + ArrayList expectedNodes2 = new ArrayList<>(); + expectedNodes2.add(new SwhPID("swh:1:snp:0000000000000000000000000000000000000020")); + expectedNodes2.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000010")); + expectedNodes2.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000013")); GraphTest.assertEqualsAnyOrder(expectedNodes2, (ArrayList) endpoint2.neighbors(src2).result); } } diff --git a/java/server/src/test/java/org/softwareheritage/graph/VisitTest.java b/java/server/src/test/java/org/softwareheritage/graph/VisitTest.java --- a/java/server/src/test/java/org/softwareheritage/graph/VisitTest.java +++ b/java/server/src/test/java/org/softwareheritage/graph/VisitTest.java @@ -9,16 +9,16 @@ import org.softwareheritage.graph.Endpoint; import org.softwareheritage.graph.Graph; import org.softwareheritage.graph.GraphTest; -import org.softwareheritage.graph.SwhId; +import org.softwareheritage.graph.SwhPID; import org.softwareheritage.graph.SwhPath; // Avoid warnings concerning Endpoint.Output.result manual cast @SuppressWarnings("unchecked") public class VisitTest extends GraphTest { - private void assertSameNodesFromPaths(ArrayList paths, ArrayList nodes) { - Set expectedNodes = new HashSet(); + private void assertSameNodesFromPaths(ArrayList paths, ArrayList nodes) { + Set expectedNodes = new HashSet(); for (SwhPath path : paths) { - for (SwhId node : path.getPath()) { + for (SwhPID node : path.getPath()) { expectedNodes.add(node); } } @@ -28,10 +28,10 @@ @Test public void forwardFromRoot() { Graph graph = getGraph(); - SwhId swhId = new SwhId("swh:1:ori:0000000000000000000000000000000000000021"); + SwhPID swhPID = new SwhPID("swh:1:ori:0000000000000000000000000000000000000021"); Endpoint endpoint = new Endpoint(graph, "forward", "*"); - ArrayList paths = (ArrayList) endpoint.visitPaths(swhId).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhId).result; + ArrayList paths = (ArrayList) endpoint.visitPaths(swhPID).result; + ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( @@ -133,10 +133,10 @@ @Test public void forwardFromMiddle() { Graph graph = getGraph(); - SwhId swhId = new SwhId("swh:1:dir:0000000000000000000000000000000000000012"); + SwhPID swhPID = new SwhPID("swh:1:dir:0000000000000000000000000000000000000012"); Endpoint endpoint = new Endpoint(graph, "forward", "*"); - ArrayList paths = (ArrayList) endpoint.visitPaths(swhId).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhId).result; + ArrayList paths = (ArrayList) endpoint.visitPaths(swhPID).result; + ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( @@ -178,10 +178,10 @@ @Test public void forwardFromLeaf() { Graph graph = getGraph(); - SwhId swhId = new SwhId("swh:1:cnt:0000000000000000000000000000000000000004"); + SwhPID swhPID = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004"); Endpoint endpoint = new Endpoint(graph, "forward", "*"); - ArrayList paths = (ArrayList) endpoint.visitPaths(swhId).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhId).result; + ArrayList paths = (ArrayList) endpoint.visitPaths(swhPID).result; + ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( @@ -196,10 +196,10 @@ @Test public void backwardFromRoot() { Graph graph = getGraph(); - SwhId swhId = new SwhId("swh:1:ori:0000000000000000000000000000000000000021"); + SwhPID swhPID = new SwhPID("swh:1:ori:0000000000000000000000000000000000000021"); Endpoint endpoint = new Endpoint(graph, "backward", "*"); - ArrayList paths = (ArrayList) endpoint.visitPaths(swhId).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhId).result; + ArrayList paths = (ArrayList) endpoint.visitPaths(swhPID).result; + ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( @@ -214,10 +214,10 @@ @Test public void backwardFromMiddle() { Graph graph = getGraph(); - SwhId swhId = new SwhId("swh:1:dir:0000000000000000000000000000000000000012"); + SwhPID swhPID = new SwhPID("swh:1:dir:0000000000000000000000000000000000000012"); Endpoint endpoint = new Endpoint(graph, "backward", "*"); - ArrayList paths = (ArrayList) endpoint.visitPaths(swhId).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhId).result; + ArrayList paths = (ArrayList) endpoint.visitPaths(swhPID).result; + ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( @@ -235,10 +235,10 @@ @Test public void backwardFromLeaf() { Graph graph = getGraph(); - SwhId swhId = new SwhId("swh:1:cnt:0000000000000000000000000000000000000004"); + SwhPID swhPID = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004"); Endpoint endpoint = new Endpoint(graph, "backward", "*"); - ArrayList paths = (ArrayList) endpoint.visitPaths(swhId).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhId).result; + ArrayList paths = (ArrayList) endpoint.visitPaths(swhPID).result; + ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( @@ -288,10 +288,10 @@ @Test public void forwardSnpToRev() { Graph graph = getGraph(); - SwhId swhId = new SwhId("swh:1:snp:0000000000000000000000000000000000000020"); + SwhPID swhPID = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); Endpoint endpoint = new Endpoint(graph, "forward", "snp:rev"); - ArrayList paths = (ArrayList) endpoint.visitPaths(swhId).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhId).result; + ArrayList paths = (ArrayList) endpoint.visitPaths(swhPID).result; + ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( @@ -307,10 +307,10 @@ @Test public void forwardRelToRevRevToRev() { Graph graph = getGraph(); - SwhId swhId = new SwhId("swh:1:rel:0000000000000000000000000000000000000010"); + SwhPID swhPID = new SwhPID("swh:1:rel:0000000000000000000000000000000000000010"); Endpoint endpoint = new Endpoint(graph, "forward", "rel:rev,rev:rev"); - ArrayList paths = (ArrayList) endpoint.visitPaths(swhId).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhId).result; + ArrayList paths = (ArrayList) endpoint.visitPaths(swhPID).result; + ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( @@ -327,10 +327,10 @@ @Test public void forwardRevToAllDirToAll() { Graph graph = getGraph(); - SwhId swhId = new SwhId("swh:1:rev:0000000000000000000000000000000000000013"); + SwhPID swhPID = new SwhPID("swh:1:rev:0000000000000000000000000000000000000013"); Endpoint endpoint = new Endpoint(graph, "forward", "rev:*,dir:*"); - ArrayList paths = (ArrayList) endpoint.visitPaths(swhId).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhId).result; + ArrayList paths = (ArrayList) endpoint.visitPaths(swhPID).result; + ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( @@ -415,10 +415,10 @@ @Test public void forwardSnpToAllRevToAll() { Graph graph = getGraph(); - SwhId swhId = new SwhId("swh:1:snp:0000000000000000000000000000000000000020"); + SwhPID swhPID = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); Endpoint endpoint = new Endpoint(graph, "forward", "snp:*,rev:*"); - ArrayList paths = (ArrayList) endpoint.visitPaths(swhId).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhId).result; + ArrayList paths = (ArrayList) endpoint.visitPaths(swhPID).result; + ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( @@ -447,10 +447,10 @@ @Test public void forwardNoEdges() { Graph graph = getGraph(); - SwhId swhId = new SwhId("swh:1:snp:0000000000000000000000000000000000000020"); + SwhPID swhPID = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); Endpoint endpoint = new Endpoint(graph, "forward", ""); - ArrayList paths = (ArrayList) endpoint.visitPaths(swhId).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhId).result; + ArrayList paths = (ArrayList) endpoint.visitPaths(swhPID).result; + ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( @@ -465,10 +465,10 @@ @Test public void backwardRevToRevRevToRel() { Graph graph = getGraph(); - SwhId swhId = new SwhId("swh:1:rev:0000000000000000000000000000000000000003"); + SwhPID swhPID = new SwhPID("swh:1:rev:0000000000000000000000000000000000000003"); Endpoint endpoint = new Endpoint(graph, "backward", "rev:rev,rev:rel"); - ArrayList paths = (ArrayList) endpoint.visitPaths(swhId).result; - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhId).result; + ArrayList paths = (ArrayList) endpoint.visitPaths(swhPID).result; + ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; ArrayList expectedPaths = new ArrayList(); expectedPaths.add( @@ -493,23 +493,23 @@ @Test public void forwardFromRootNodesOnly() { Graph graph = getGraph(); - SwhId swhId = new SwhId("swh:1:ori:0000000000000000000000000000000000000021"); + SwhPID swhPID = new SwhPID("swh:1:ori:0000000000000000000000000000000000000021"); Endpoint endpoint = new Endpoint(graph, "forward", "*"); - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhId).result; - - ArrayList expectedNodes = new ArrayList(); - expectedNodes.add(new SwhId("swh:1:ori:0000000000000000000000000000000000000021")); - expectedNodes.add(new SwhId("swh:1:snp:0000000000000000000000000000000000000020")); - expectedNodes.add(new SwhId("swh:1:rel:0000000000000000000000000000000000000010")); - expectedNodes.add(new SwhId("swh:1:rev:0000000000000000000000000000000000000009")); - expectedNodes.add(new SwhId("swh:1:rev:0000000000000000000000000000000000000003")); - expectedNodes.add(new SwhId("swh:1:dir:0000000000000000000000000000000000000002")); - expectedNodes.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000001")); - expectedNodes.add(new SwhId("swh:1:dir:0000000000000000000000000000000000000008")); - expectedNodes.add(new SwhId("swh:1:dir:0000000000000000000000000000000000000006")); - expectedNodes.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000004")); - expectedNodes.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000005")); - expectedNodes.add(new SwhId("swh:1:cnt:0000000000000000000000000000000000000007")); + ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; + + ArrayList expectedNodes = new ArrayList(); + expectedNodes.add(new SwhPID("swh:1:ori:0000000000000000000000000000000000000021")); + expectedNodes.add(new SwhPID("swh:1:snp:0000000000000000000000000000000000000020")); + expectedNodes.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000010")); + expectedNodes.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000009")); + expectedNodes.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000003")); + expectedNodes.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000002")); + expectedNodes.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001")); + expectedNodes.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000008")); + expectedNodes.add(new SwhPID("swh:1:dir:0000000000000000000000000000000000000006")); + expectedNodes.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000004")); + expectedNodes.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000005")); + expectedNodes.add(new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007")); GraphTest.assertEqualsAnyOrder(expectedNodes, nodes); } @@ -517,18 +517,18 @@ @Test public void backwardRevToAllNodesOnly() { Graph graph = getGraph(); - SwhId swhId = new SwhId("swh:1:rev:0000000000000000000000000000000000000003"); + SwhPID swhPID = new SwhPID("swh:1:rev:0000000000000000000000000000000000000003"); Endpoint endpoint = new Endpoint(graph, "backward", "rev:*"); - ArrayList nodes = (ArrayList) endpoint.visitNodes(swhId).result; - - ArrayList expectedNodes = new ArrayList(); - expectedNodes.add(new SwhId("swh:1:rev:0000000000000000000000000000000000000003")); - expectedNodes.add(new SwhId("swh:1:rev:0000000000000000000000000000000000000009")); - expectedNodes.add(new SwhId("swh:1:snp:0000000000000000000000000000000000000020")); - expectedNodes.add(new SwhId("swh:1:rel:0000000000000000000000000000000000000010")); - expectedNodes.add(new SwhId("swh:1:rev:0000000000000000000000000000000000000013")); - expectedNodes.add(new SwhId("swh:1:rev:0000000000000000000000000000000000000018")); - expectedNodes.add(new SwhId("swh:1:rel:0000000000000000000000000000000000000019")); + ArrayList nodes = (ArrayList) endpoint.visitNodes(swhPID).result; + + ArrayList expectedNodes = new ArrayList(); + expectedNodes.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000003")); + expectedNodes.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000009")); + expectedNodes.add(new SwhPID("swh:1:snp:0000000000000000000000000000000000000020")); + expectedNodes.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000010")); + expectedNodes.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000013")); + expectedNodes.add(new SwhPID("swh:1:rev:0000000000000000000000000000000000000018")); + expectedNodes.add(new SwhPID("swh:1:rel:0000000000000000000000000000000000000019")); GraphTest.assertEqualsAnyOrder(expectedNodes, nodes); } diff --git a/java/server/src/test/java/org/softwareheritage/graph/WalkTest.java b/java/server/src/test/java/org/softwareheritage/graph/WalkTest.java --- a/java/server/src/test/java/org/softwareheritage/graph/WalkTest.java +++ b/java/server/src/test/java/org/softwareheritage/graph/WalkTest.java @@ -10,7 +10,7 @@ import org.softwareheritage.graph.Endpoint; import org.softwareheritage.graph.Graph; import org.softwareheritage.graph.GraphTest; -import org.softwareheritage.graph.SwhId; +import org.softwareheritage.graph.SwhPID; import org.softwareheritage.graph.SwhPath; public class WalkTest extends GraphTest { @@ -18,7 +18,7 @@ public void forwardRootToLeaf() { Graph graph = getGraph(); Endpoint endpoint = new Endpoint(graph, "forward", "*"); - SwhId src = new SwhId("swh:1:snp:0000000000000000000000000000000000000020"); + SwhPID src = new SwhPID("swh:1:snp:0000000000000000000000000000000000000020"); String dstFmt = "swh:1:cnt:0000000000000000000000000000000000000005"; SwhPath solution1 = @@ -51,7 +51,7 @@ public void forwardLeafToLeaf() { Graph graph = getGraph(); Endpoint endpoint = new Endpoint(graph, "forward", "*"); - SwhId src = new SwhId("swh:1:cnt:0000000000000000000000000000000000000007"); + SwhPID src = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000007"); String dstFmt = "cnt"; SwhPath expectedPath = @@ -70,7 +70,7 @@ public void forwardRevToRev() { Graph graph = getGraph(); Endpoint endpoint = new Endpoint(graph, "forward", "rev:rev"); - SwhId src = new SwhId("swh:1:rev:0000000000000000000000000000000000000018"); + SwhPID src = new SwhPID("swh:1:rev:0000000000000000000000000000000000000018"); String dstFmt = "swh:1:rev:0000000000000000000000000000000000000003"; SwhPath expectedPath = @@ -92,7 +92,7 @@ public void backwardRevToRev() { Graph graph = getGraph(); Endpoint endpoint = new Endpoint(graph, "backward", "rev:rev"); - SwhId src = new SwhId("swh:1:rev:0000000000000000000000000000000000000003"); + SwhPID src = new SwhPID("swh:1:rev:0000000000000000000000000000000000000003"); String dstFmt = "swh:1:rev:0000000000000000000000000000000000000018"; SwhPath expectedPath = @@ -114,7 +114,7 @@ public void backwardCntToFirstSnp() { Graph graph = getGraph(); Endpoint endpoint = new Endpoint(graph, "backward", "*"); - SwhId src = new SwhId("swh:1:cnt:0000000000000000000000000000000000000001"); + SwhPID src = new SwhPID("swh:1:cnt:0000000000000000000000000000000000000001"); String dstFmt = "snp"; SwhPath solution1 = @@ -162,7 +162,7 @@ public void forwardRevToFirstCnt() { Graph graph = getGraph(); Endpoint endpoint = new Endpoint(graph, "forward", "rev:*,dir:*"); - SwhId src = new SwhId("swh:1:rev:0000000000000000000000000000000000000009"); + SwhPID src = new SwhPID("swh:1:rev:0000000000000000000000000000000000000009"); String dstFmt = "cnt"; SwhPath solution1 = @@ -212,7 +212,7 @@ public void backwardDirToFirstRel() { Graph graph = getGraph(); Endpoint endpoint = new Endpoint(graph, "backward", "dir:dir,dir:rev,rev:*"); - SwhId src = new SwhId("swh:1:dir:0000000000000000000000000000000000000016"); + SwhPID src = new SwhPID("swh:1:dir:0000000000000000000000000000000000000016"); String dstFmt = "rel"; SwhPath expectedPath =