@Test(expectedExceptions = RuntimeException.class) public void testInvalidEdges() { NodeImpl n1 = new NodeImpl("0"); NodeImpl n2 = new NodeImpl("1"); EdgeImpl e1 = new EdgeImpl("0", n1, n2, 0, 1.0, true); EdgeStore edgeStore = new EdgeStore(); edgeStore.add(e1); }
@Override public boolean add(final Edge e) { checkNonNullEdgeObject(e); EdgeImpl edge = (EdgeImpl) e; if (edge.storeId == EdgeStore.NULL_ID) { checkIdDoesntExist(e.getId()); checkSourceTargets(edge); checkUndirectedNotExist(edge); int type = edge.type; boolean directed = edge.isDirected(); NodeImpl source = edge.source; NodeImpl target = edge.target; ensureLongDictionaryCapacity(type); Long2ObjectOpenCustomHashMap<int[]> dico = longDictionary[type]; long longId = getLongId(source, target, directed); int[] dicoValue = dico.get(longId); if (dicoValue != null && !GraphStoreConfiguration.ENABLE_PARALLEL_EDGES) { return false; } incrementVersion(); if (garbageSize > 0) { for (int i = 0; i < blocksCount; i++) { EdgeBlock edgeBlock = blocks[i]; if (edgeBlock.hasGarbage()) { edgeBlock.set(edge); garbageSize--; dictionary.put(edge.getId(), edge.storeId); break; } } } else { ensureCapacity(1); currentBlock.add(edge); dictionary.put(edge.getId(), edge.storeId); } insertOutEdge(edge); insertInEdge(edge); source.outDegree++; target.inDegree++; if (dicoValue == null) { dicoValue = new int[] { edge.storeId }; } else { dicoValue = Arrays.copyOf(dicoValue, dicoValue.length + 1); dicoValue[dicoValue.length - 1] = edge.storeId; } dico.put(longId, dicoValue); if (viewStore != null) { viewStore.addEdge(edge); } edge.indexAttributes(); if (directed && !edge.isSelfLoop()) { int[] index = longDictionary[type].get(getLongId(edge.target, edge.source, true)); if (index != null) { for (int i = 0; i < index.length; i++) { EdgeImpl mutual = get(index[i]); if (!mutual.isMutual()) { mutual.setMutual(true); edge.setMutual(true); source.mutualDegree++; target.mutualDegree++; mutualEdgesSize++; mutualEdgesTypeSize[type]++; break; } } } } if (!directed) { undirectedSize++; } size++; return true; } else if (isValidIndex(edge.storeId) && get(edge.storeId) == edge) { return false; } else { throw new IllegalArgumentException("The edge already belongs to another store"); } }
EdgeStore implements Collection<Edge>, EdgeIterable { @Override public boolean add(final Edge e) { checkNonNullEdgeObject(e); EdgeImpl edge = (EdgeImpl) e; if (edge.storeId == EdgeStore.NULL_ID) { checkIdDoesntExist(e.getId()); checkSourceTargets(edge); checkUndirectedNotExist(edge); int type = edge.type; boolean directed = edge.isDirected(); NodeImpl source = edge.source; NodeImpl target = edge.target; ensureLongDictionaryCapacity(type); Long2ObjectOpenCustomHashMap<int[]> dico = longDictionary[type]; long longId = getLongId(source, target, directed); int[] dicoValue = dico.get(longId); if (dicoValue != null && !GraphStoreConfiguration.ENABLE_PARALLEL_EDGES) { return false; } incrementVersion(); if (garbageSize > 0) { for (int i = 0; i < blocksCount; i++) { EdgeBlock edgeBlock = blocks[i]; if (edgeBlock.hasGarbage()) { edgeBlock.set(edge); garbageSize--; dictionary.put(edge.getId(), edge.storeId); break; } } } else { ensureCapacity(1); currentBlock.add(edge); dictionary.put(edge.getId(), edge.storeId); } insertOutEdge(edge); insertInEdge(edge); source.outDegree++; target.inDegree++; if (dicoValue == null) { dicoValue = new int[] { edge.storeId }; } else { dicoValue = Arrays.copyOf(dicoValue, dicoValue.length + 1); dicoValue[dicoValue.length - 1] = edge.storeId; } dico.put(longId, dicoValue); if (viewStore != null) { viewStore.addEdge(edge); } edge.indexAttributes(); if (directed && !edge.isSelfLoop()) { int[] index = longDictionary[type].get(getLongId(edge.target, edge.source, true)); if (index != null) { for (int i = 0; i < index.length; i++) { EdgeImpl mutual = get(index[i]); if (!mutual.isMutual()) { mutual.setMutual(true); edge.setMutual(true); source.mutualDegree++; target.mutualDegree++; mutualEdgesSize++; mutualEdgesTypeSize[type]++; break; } } } } if (!directed) { undirectedSize++; } size++; return true; } else if (isValidIndex(edge.storeId) && get(edge.storeId) == edge) { return false; } else { throw new IllegalArgumentException("The edge already belongs to another store"); } } }
EdgeStore implements Collection<Edge>, EdgeIterable { @Override public boolean add(final Edge e) { checkNonNullEdgeObject(e); EdgeImpl edge = (EdgeImpl) e; if (edge.storeId == EdgeStore.NULL_ID) { checkIdDoesntExist(e.getId()); checkSourceTargets(edge); checkUndirectedNotExist(edge); int type = edge.type; boolean directed = edge.isDirected(); NodeImpl source = edge.source; NodeImpl target = edge.target; ensureLongDictionaryCapacity(type); Long2ObjectOpenCustomHashMap<int[]> dico = longDictionary[type]; long longId = getLongId(source, target, directed); int[] dicoValue = dico.get(longId); if (dicoValue != null && !GraphStoreConfiguration.ENABLE_PARALLEL_EDGES) { return false; } incrementVersion(); if (garbageSize > 0) { for (int i = 0; i < blocksCount; i++) { EdgeBlock edgeBlock = blocks[i]; if (edgeBlock.hasGarbage()) { edgeBlock.set(edge); garbageSize--; dictionary.put(edge.getId(), edge.storeId); break; } } } else { ensureCapacity(1); currentBlock.add(edge); dictionary.put(edge.getId(), edge.storeId); } insertOutEdge(edge); insertInEdge(edge); source.outDegree++; target.inDegree++; if (dicoValue == null) { dicoValue = new int[] { edge.storeId }; } else { dicoValue = Arrays.copyOf(dicoValue, dicoValue.length + 1); dicoValue[dicoValue.length - 1] = edge.storeId; } dico.put(longId, dicoValue); if (viewStore != null) { viewStore.addEdge(edge); } edge.indexAttributes(); if (directed && !edge.isSelfLoop()) { int[] index = longDictionary[type].get(getLongId(edge.target, edge.source, true)); if (index != null) { for (int i = 0; i < index.length; i++) { EdgeImpl mutual = get(index[i]); if (!mutual.isMutual()) { mutual.setMutual(true); edge.setMutual(true); source.mutualDegree++; target.mutualDegree++; mutualEdgesSize++; mutualEdgesTypeSize[type]++; break; } } } } if (!directed) { undirectedSize++; } size++; return true; } else if (isValidIndex(edge.storeId) && get(edge.storeId) == edge) { return false; } else { throw new IllegalArgumentException("The edge already belongs to another store"); } } EdgeStore();  EdgeStore(final EdgeTypeStore edgeTypeStore, final GraphLock lock, final GraphViewStore viewStore, final GraphVersion graphVersion); }
EdgeStore implements Collection<Edge>, EdgeIterable { @Override public boolean add(final Edge e) { checkNonNullEdgeObject(e); EdgeImpl edge = (EdgeImpl) e; if (edge.storeId == EdgeStore.NULL_ID) { checkIdDoesntExist(e.getId()); checkSourceTargets(edge); checkUndirectedNotExist(edge); int type = edge.type; boolean directed = edge.isDirected(); NodeImpl source = edge.source; NodeImpl target = edge.target; ensureLongDictionaryCapacity(type); Long2ObjectOpenCustomHashMap<int[]> dico = longDictionary[type]; long longId = getLongId(source, target, directed); int[] dicoValue = dico.get(longId); if (dicoValue != null && !GraphStoreConfiguration.ENABLE_PARALLEL_EDGES) { return false; } incrementVersion(); if (garbageSize > 0) { for (int i = 0; i < blocksCount; i++) { EdgeBlock edgeBlock = blocks[i]; if (edgeBlock.hasGarbage()) { edgeBlock.set(edge); garbageSize--; dictionary.put(edge.getId(), edge.storeId); break; } } } else { ensureCapacity(1); currentBlock.add(edge); dictionary.put(edge.getId(), edge.storeId); } insertOutEdge(edge); insertInEdge(edge); source.outDegree++; target.inDegree++; if (dicoValue == null) { dicoValue = new int[] { edge.storeId }; } else { dicoValue = Arrays.copyOf(dicoValue, dicoValue.length + 1); dicoValue[dicoValue.length - 1] = edge.storeId; } dico.put(longId, dicoValue); if (viewStore != null) { viewStore.addEdge(edge); } edge.indexAttributes(); if (directed && !edge.isSelfLoop()) { int[] index = longDictionary[type].get(getLongId(edge.target, edge.source, true)); if (index != null) { for (int i = 0; i < index.length; i++) { EdgeImpl mutual = get(index[i]); if (!mutual.isMutual()) { mutual.setMutual(true); edge.setMutual(true); source.mutualDegree++; target.mutualDegree++; mutualEdgesSize++; mutualEdgesTypeSize[type]++; break; } } } } if (!directed) { undirectedSize++; } size++; return true; } else if (isValidIndex(edge.storeId) && get(edge.storeId) == edge) { return false; } else { throw new IllegalArgumentException("The edge already belongs to another store"); } } EdgeStore();  EdgeStore(final EdgeTypeStore edgeTypeStore, final GraphLock lock, final GraphViewStore viewStore, final GraphVersion graphVersion); @Override void clear(); @Override int size(); int undirectedSize(); int size(int type); int undirectedSize(int type); @Override boolean isEmpty(); @Override EdgeStoreIterator iterator(); EdgeStoreIterator iteratorUndirected(); SelfLoopIterator iteratorSelfLoop(); EdgeOutIterator edgeOutIterator(final Node node); EdgeInIterator edgeInIterator(final Node node); EdgeInOutIterator edgeIterator(final Node node); Iterator<Edge> edgeUndirectedIterator(final Node node); EdgeTypeOutIterator edgeOutIterator(final Node node, int type); Iterator<Edge> edgeUndirectedIterator(final Node node, int type); EdgeTypeInIterator edgeInIterator(final Node node, int type); EdgeTypeInOutIterator edgeIterator(final Node node, int type); NeighborsIterator neighborOutIterator(final Node node); NeighborsIterator neighborOutIterator(final Node node, int type); NeighborsIterator neighborInIterator(final Node node); NeighborsIterator neighborInIterator(final Node node, int type); NeighborsIterator neighborIterator(Node node); NeighborsIterator neighborIterator(final Node node, int type); Iterator<Edge> edgesUndirectedIterator(final Node node1, final Node node2); Iterator<Edge> edgesUndirectedIterator(final Node node1, final Node node2, int type); EdgeImpl get(int id); EdgeImpl get(final Object id); EdgeImpl get(final Node source, final Node target, boolean undirectedDecorator); Iterator<Edge> getAll(final Node source, final Node target, boolean undirectedDecorator); EdgeImpl get(final Node source, final Node target, final int type, boolean undirectedDecorator); Iterator<Edge> getAll(final Node source, final Node target, final int type, boolean undirectedDecorator); EdgeImpl getMutualEdge(final Edge e); @Override boolean add(final Edge e); @Override boolean remove(final Object o); @Override boolean contains(Object o); boolean containsId(final Object id); boolean contains(NodeImpl source, NodeImpl target, int type); @Override EdgeImpl[] toArray(); @Override T[] toArray(T[] array); @Override Collection<Edge> toCollection(); @Override boolean containsAll(Collection<?> c); @Override boolean addAll(Collection<? extends Edge> c); @Override boolean removeAll(Collection<?> c); @Override boolean retainAll(Collection<?> c); int deepHashCode(); boolean deepEquals(EdgeStore obj); boolean isAdjacent(Node node1, Node node2, int type); boolean isAdjacent(Node node1, Node node2); boolean isIncident(EdgeImpl edge1, EdgeImpl edge2); boolean isIncident(NodeImpl node, EdgeImpl edge); @Override void doBreak(); }
EdgeStore implements Collection<Edge>, EdgeIterable { @Override public boolean add(final Edge e) { checkNonNullEdgeObject(e); EdgeImpl edge = (EdgeImpl) e; if (edge.storeId == EdgeStore.NULL_ID) { checkIdDoesntExist(e.getId()); checkSourceTargets(edge); checkUndirectedNotExist(edge); int type = edge.type; boolean directed = edge.isDirected(); NodeImpl source = edge.source; NodeImpl target = edge.target; ensureLongDictionaryCapacity(type); Long2ObjectOpenCustomHashMap<int[]> dico = longDictionary[type]; long longId = getLongId(source, target, directed); int[] dicoValue = dico.get(longId); if (dicoValue != null && !GraphStoreConfiguration.ENABLE_PARALLEL_EDGES) { return false; } incrementVersion(); if (garbageSize > 0) { for (int i = 0; i < blocksCount; i++) { EdgeBlock edgeBlock = blocks[i]; if (edgeBlock.hasGarbage()) { edgeBlock.set(edge); garbageSize--; dictionary.put(edge.getId(), edge.storeId); break; } } } else { ensureCapacity(1); currentBlock.add(edge); dictionary.put(edge.getId(), edge.storeId); } insertOutEdge(edge); insertInEdge(edge); source.outDegree++; target.inDegree++; if (dicoValue == null) { dicoValue = new int[] { edge.storeId }; } else { dicoValue = Arrays.copyOf(dicoValue, dicoValue.length + 1); dicoValue[dicoValue.length - 1] = edge.storeId; } dico.put(longId, dicoValue); if (viewStore != null) { viewStore.addEdge(edge); } edge.indexAttributes(); if (directed && !edge.isSelfLoop()) { int[] index = longDictionary[type].get(getLongId(edge.target, edge.source, true)); if (index != null) { for (int i = 0; i < index.length; i++) { EdgeImpl mutual = get(index[i]); if (!mutual.isMutual()) { mutual.setMutual(true); edge.setMutual(true); source.mutualDegree++; target.mutualDegree++; mutualEdgesSize++; mutualEdgesTypeSize[type]++; break; } } } } if (!directed) { undirectedSize++; } size++; return true; } else if (isValidIndex(edge.storeId) && get(edge.storeId) == edge) { return false; } else { throw new IllegalArgumentException("The edge already belongs to another store"); } } EdgeStore();  EdgeStore(final EdgeTypeStore edgeTypeStore, final GraphLock lock, final GraphViewStore viewStore, final GraphVersion graphVersion); @Override void clear(); @Override int size(); int undirectedSize(); int size(int type); int undirectedSize(int type); @Override boolean isEmpty(); @Override EdgeStoreIterator iterator(); EdgeStoreIterator iteratorUndirected(); SelfLoopIterator iteratorSelfLoop(); EdgeOutIterator edgeOutIterator(final Node node); EdgeInIterator edgeInIterator(final Node node); EdgeInOutIterator edgeIterator(final Node node); Iterator<Edge> edgeUndirectedIterator(final Node node); EdgeTypeOutIterator edgeOutIterator(final Node node, int type); Iterator<Edge> edgeUndirectedIterator(final Node node, int type); EdgeTypeInIterator edgeInIterator(final Node node, int type); EdgeTypeInOutIterator edgeIterator(final Node node, int type); NeighborsIterator neighborOutIterator(final Node node); NeighborsIterator neighborOutIterator(final Node node, int type); NeighborsIterator neighborInIterator(final Node node); NeighborsIterator neighborInIterator(final Node node, int type); NeighborsIterator neighborIterator(Node node); NeighborsIterator neighborIterator(final Node node, int type); Iterator<Edge> edgesUndirectedIterator(final Node node1, final Node node2); Iterator<Edge> edgesUndirectedIterator(final Node node1, final Node node2, int type); EdgeImpl get(int id); EdgeImpl get(final Object id); EdgeImpl get(final Node source, final Node target, boolean undirectedDecorator); Iterator<Edge> getAll(final Node source, final Node target, boolean undirectedDecorator); EdgeImpl get(final Node source, final Node target, final int type, boolean undirectedDecorator); Iterator<Edge> getAll(final Node source, final Node target, final int type, boolean undirectedDecorator); EdgeImpl getMutualEdge(final Edge e); @Override boolean add(final Edge e); @Override boolean remove(final Object o); @Override boolean contains(Object o); boolean containsId(final Object id); boolean contains(NodeImpl source, NodeImpl target, int type); @Override EdgeImpl[] toArray(); @Override T[] toArray(T[] array); @Override Collection<Edge> toCollection(); @Override boolean containsAll(Collection<?> c); @Override boolean addAll(Collection<? extends Edge> c); @Override boolean removeAll(Collection<?> c); @Override boolean retainAll(Collection<?> c); int deepHashCode(); boolean deepEquals(EdgeStore obj); boolean isAdjacent(Node node1, Node node2, int type); boolean isAdjacent(Node node1, Node node2); boolean isIncident(EdgeImpl edge1, EdgeImpl edge2); boolean isIncident(NodeImpl node, EdgeImpl edge); @Override void doBreak();  }