EdgeStore implements Collection<Edge>, EdgeIterable { @Override public boolean remove(final Object o) { checkNonNullEdgeObject(o); EdgeImpl edge = (EdgeImpl) o; int id = edge.storeId; if (id != EdgeStore.NULL_ID) { checkEdgeExists(edge); incrementVersion(); if (viewStore != null) { viewStore.removeEdge(edge); } edge.clearAttributes(); int storeIndex = id / GraphStoreConfiguration.EDGESTORE_BLOCK_SIZE; EdgeBlock block = blocks[storeIndex]; block.remove(edge); removeOutEdge(edge); removeInEdge(edge); boolean directed = edge.isDirected(); NodeImpl source = edge.source; NodeImpl target = edge.target; source.outDegree--; target.inDegree--; size--; garbageSize++; dictionary.remove(edge.getId()); trimDictionary(); for (int i = storeIndex; i == (blocksCount - 1) && block.garbageLength == block.nodeLength && i >= 0;) { if (i != 0) { blocks[i] = null; blocksCount--; garbageSize -= block.nodeLength; block = blocks[--i]; currentBlock = block; currentBlockIndex--; } else { currentBlock.clear(); garbageSize = 0; break; } } int type = edge.type; Long2ObjectOpenCustomHashMap<int[]> dico = longDictionary[type]; long longId = getLongId(source, target, directed); int[] dicoValue = dico.get(longId); if (dicoValue.length == 1) { dico.remove(longId); } else { int[] newDicoValue = new int[dicoValue.length - 1]; int j = 0; for (int i = 0; i < dicoValue.length; i++) { int v = dicoValue[i]; if (v != id) { newDicoValue[j++] = v; } } dico.put(longId, newDicoValue); } 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()) { edge.setMutual(true); mutual.setMutual(false); source.mutualDegree--; target.mutualDegree--; mutualEdgesSize--; mutualEdgesTypeSize[type]--; break; } } } } if (!directed) { undirectedSize--; } if (edgeTypeStore != null) { } return true; } return false; } 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();  }
@Test public void testRemove() { EdgeStore edgeStore = new EdgeStore(); EdgeImpl edge = GraphGenerator.generateSingleEdge(); edgeStore.add(edge); boolean a = edgeStore.remove(edge); boolean b = edgeStore.remove(edge); Assert.assertEquals(a, true); Assert.assertEquals(b, false); Assert.assertEquals(edgeStore.isEmpty(), true); Assert.assertEquals(edgeStore.size(), 0); Assert.assertFalse(edgeStore.contains(edge)); Assert.assertSame(edge.getStoreId(), EdgeStore.NULL_ID); }
@Test(expectedExceptions = NullPointerException.class) public void testRemoveNull() { EdgeStore edgeStore = new EdgeStore(); edgeStore.remove(null); }