protected LazyEdge(final Edge edge, final ElementValueLoader valueLoader, final LazyProperties lazyProperties) { super(edge.getGroup(), null, null, false); this.edge = edge; this.valueLoader = valueLoader; this.lazyProperties = lazyProperties; }
@Override public String getGroup() { return edge.getGroup(); }
@Override public Object getIdentifier(final IdentifierType identifierType) { switch (identifierType) { case GROUP: return getGroup(); case SOURCE: return getSource(); case DESTINATION: return getDestination(); case DIRECTED: return isDirected(); case MATCHED_VERTEX: return getMatchedVertexValue(); case ADJACENT_MATCHED_VERTEX: return getAdjacentMatchedVertexValue(); default: return null; } }
@Override public Edge emptyClone() { return new Edge( getGroup(), getSource(), getDestination(), isDirected(), getMatchedVertex(), new Properties() ); }
private Edge cloneCoreFields(final Edge edge) { return new Edge.Builder() .group(edge.getGroup()) .source(edge.getSource()) .dest(edge.getDestination()) .directed(edge.isDirected()) .build(); }
@Override @Test public void shouldSetAndGetFields() { // Given final Edge edge = new Edge.Builder() .group("group") .source("source vertex") .dest("destination vertex") .directed(true) .build(); // When/Then assertEquals("group", edge.getGroup()); assertEquals("source vertex", edge.getSource()); assertEquals("destination vertex", edge.getDestination()); assertTrue(edge.isDirected()); }
@Test public void shouldBuildEdge() { // Given final String source = "source vertex"; final String destination = "dest vertex"; final boolean directed = true; final String propValue = "propValue"; // When final Edge edge = new Edge.Builder() .group(TestGroups.EDGE) .source(source) .dest(destination) .directed(directed) .property(TestPropertyNames.STRING, propValue) .build(); // Then assertEquals(TestGroups.EDGE, edge.getGroup()); assertEquals(source, edge.getSource()); assertEquals(destination, edge.getDestination()); assertTrue(edge.isDirected()); assertEquals(propValue, edge.getProperty(TestPropertyNames.STRING)); }
@Test public void shouldConstructEdge() { // Given final String source = "source vertex"; final String destination = "dest vertex"; final boolean directed = true; final String propValue = "propValue"; // When final Edge edge = new Edge.Builder() .group(TestGroups.EDGE) .source(source) .dest(destination) .directed(directed) .build(); edge.putProperty(TestPropertyNames.STRING, propValue); // Then assertEquals(TestGroups.EDGE, edge.getGroup()); assertEquals(source, edge.getSource()); assertEquals(destination, edge.getDestination()); assertTrue(edge.isDirected()); assertEquals(propValue, edge.getProperty(TestPropertyNames.STRING)); }
@Test public void shouldReturnFalseForEqualsWhenSourceIsDifferent() { // Given final Edge edge1 = new Edge.Builder() .group("group") .source("source vertex") .dest("dest vertex") .directed(true) .build(); final Edge edge2 = new Edge.Builder() .group(edge1.getGroup()) .source("different source") .dest(edge1.getDestination()) .directed(edge1.isDirected()) .build(); // When boolean isEqual = edge1.equals((Object) edge2); // Then assertFalse(isEqual); assertFalse(edge1.hashCode() == edge2.hashCode()); }
@Test public void shouldReturnFalseForEqualsWhenDestinationIsDifferent() { // Given final Edge edge1 = new Edge.Builder().group("group") .source("source vertex") .dest("dest vertex") .directed(true) .build(); final Edge edge2 = new Edge.Builder() .group(edge1.getGroup()) .source(edge1.getSource()) .dest("different destination") .directed(edge1.isDirected()) .build(); // When boolean isEqual = edge1.equals((Object) edge2); // Then assertFalse(isEqual); assertFalse(edge1.hashCode() == edge2.hashCode()); }
@Test public void shouldReturnFalseForEqualsWhenDirectedIsDifferent() { // Given final Edge edge1 = new Edge.Builder() .group("group") .source("source vertex") .dest("dest vertex") .directed(true) .build(); final Edge edge2 = new Edge.Builder() .group(edge1.getGroup()) .source(edge1.getSource()) .dest(edge1.getDestination()) .directed(!edge1.isDirected()) .build(); // When boolean isEqual = edge1.equals((Object) edge2); // Then assertFalse(isEqual); assertFalse(edge1.hashCode() == edge2.hashCode()); }
protected LazyEdge(final Edge edge, final ElementValueLoader valueLoader, final LazyProperties lazyProperties) { super(edge.getGroup(), null, null, false); this.edge = edge; this.valueLoader = valueLoader; this.lazyProperties = lazyProperties; }
@Override public String getGroup() { return edge.getGroup(); }
@Override public Pair<Key, Key> getKeysFromEdge(final Edge edge) { // Get pair of row keys final Pair<byte[], byte[]> rowKeys = getRowKeysFromEdge(edge); final byte[] columnFamily = buildColumnFamily(edge.getGroup()); final byte[] columnQualifier = buildColumnQualifier(edge.getGroup(), edge.getProperties()); final byte[] columnVisibility = buildColumnVisibility(edge.getGroup(), edge.getProperties()); final long timeStamp = buildTimestamp(edge.getGroup(), edge.getProperties()); // Create Accumulo keys - note that second row key may be null (if it's // a self-edge) and // in that case we should return null second key final Key key1 = new Key(rowKeys.getFirst(), columnFamily, columnQualifier, columnVisibility, timeStamp); final Key key2 = null != rowKeys.getSecond() ? new Key(rowKeys.getSecond(), columnFamily, columnQualifier, columnVisibility, timeStamp) : null; // Return pair of keys return new Pair<>(key1, key2); }
@Override public void write(final Kryo kryo, final Output output, final Edge edge) { output.writeString(edge.getGroup()); kryo.writeClass(output, edge.getSource().getClass()); kryo.writeObject(output, edge.getSource()); kryo.writeClass(output, edge.getDestination().getClass()); kryo.writeObject(output, edge.getDestination()); output.writeBoolean(edge.isDirected()); kryo.writeObjectOrNull(output, edge.getProperties(), Properties.class); }
@Override public Edge emptyClone() { return new Edge( getGroup(), getSource(), getDestination(), isDirected(), getMatchedVertex(), new Properties() ); }
protected Entity createCardinality(final Object source, final Object destination, final Edge edge) { final HyperLogLogPlus hllp = new HyperLogLogPlus(5, 5); hllp.offer(destination); return new Entity.Builder() .vertex(source) .group("Cardinality") .property("edgeGroup", CollectionUtil.treeSet(edge.getGroup())) .property("hllp", hllp) .property("count", 1L) .build(); }
private Entity createCardinalityEntity(final Object source, final Object destination, final Edge edge) { final HyperLogLogPlus hllp = new HyperLogLogPlus(5, 5); hllp.offer(destination); return new Entity.Builder() .vertex(source) .group("Cardinality") .property("edgeGroup", CollectionUtil.treeSet(edge.getGroup())) .property("hllp", hllp) .property("count", 1) .build(); }
private Entity createCardinality(final Object source, final Object destination, final Edge edge) { final HyperLogLogPlus hllp = new HyperLogLogPlus(5, 5); hllp.offer(destination); return new Entity.Builder() .vertex(source) .group("Cardinality") .property("edgeGroup", CollectionUtil.treeSet(edge.getGroup())) .property("hllp", hllp) .property("count", 1L) .build(); } }
private void updateElementIndex(final Element element, final MapImpl mapImpl) { if (element instanceof Entity) { final Entity entity = (Entity) element; final EntityId entityId = new EntitySeed(entity.getVertex()); mapImpl.addIndex(entityId, element); } else { final Edge edge = (Edge) element; edge.setIdentifiers(edge.getSource(), edge.getDestination(), edge.isDirected(), EdgeId.MatchedVertex.SOURCE); final EntityId sourceEntityId = new EntitySeed(edge.getSource()); mapImpl.addIndex(sourceEntityId, edge); final Edge destMatchedEdge = new Edge(edge.getGroup(), edge.getSource(), edge.getDestination(), edge.isDirected(), EdgeId.MatchedVertex.DESTINATION, edge.getProperties()); final EntityId destinationEntityId = new EntitySeed(edge.getDestination()); mapImpl.addIndex(destinationEntityId, destMatchedEdge); final EdgeId edgeId = new EdgeSeed(edge.getSource(), edge.getDestination(), edge.isDirected()); mapImpl.addIndex(edgeId, edge); } } }