private Edge cloneCoreFields(final Edge edge) { return new Edge.Builder() .group(edge.getGroup()) .source(edge.getSource()) .dest(edge.getDestination()) .directed(edge.isDirected()) .build(); }
@Override public Edge emptyClone() { return new Edge( getGroup(), getSource(), getDestination(), isDirected(), getMatchedVertex(), new Properties() ); }
/** * Constructs a by wrapping the provided {@link uk.gov.gchq.gaffer.data.element.Edge} * and using the {@link uk.gov.gchq.gaffer.data.element.ElementValueLoader} to lazily load the element's identifiers and * properties when requested. * * @param edge the edge to wrap. * @param valueLoader the element value loader to use to lazily load the element's identifiers and properties */ public LazyEdge(final Edge edge, final ElementValueLoader valueLoader) { this(edge, valueLoader, new LazyProperties(edge.getProperties(), valueLoader)); }
@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; } }
/** * Note this does not include the matchedVertex field. * * @param edge the reference Edge with which to compare. * @return {@code true} if this object is the same as the edge * argument; {@code false} otherwise. */ public boolean equals(final Edge edge) { return null != edge && new EqualsBuilder() .append(isDirected(), edge.isDirected()) .append(getSource(), edge.getSource()) .append(getDestination(), edge.getDestination()) .appendSuper(super.equals(edge)) .isEquals(); }
&& ((Edge) e).isDirected() && (EdgeId.MatchedVertex.SOURCE == ((Edge) e).getMatchedVertex())); } else if (inOutType == IncludeIncomingOutgoingType.OUTGOING) { isFiltered = isFiltered.or(e -> e instanceof Edge && ((Edge) e).isDirected() && (EdgeId.MatchedVertex.DESTINATION == ((Edge) e).getMatchedVertex())); .filter(e -> e instanceof Entity) .forEach(relevantElements::add); mapImpl.lookup(new EntitySeed(edgeId.getDestination())) .stream() .filter(e -> e instanceof Entity) .forEach(relevantElements::add); isFiltered = isFiltered.or(e -> e instanceof Edge && !((Edge) e).isDirected()); } else if (directedType == DirectedType.UNDIRECTED) { isFiltered = isFiltered.or(e -> e instanceof Edge && ((Edge) e).isDirected());
public static Stream<Element> applyDirectedTypeFilter(final Stream<Element> elements, final boolean includeEdges, final DirectedType directedType) { Stream<Element> filteredElements = elements; if (includeEdges) { if (directedType == DirectedType.DIRECTED) { filteredElements = elements.filter(e -> e instanceof Entity || ((Edge) e).isDirected()); } else if (directedType == DirectedType.UNDIRECTED) { filteredElements = elements.filter(e -> e instanceof Entity || !((Edge) e).isDirected()); } } return filteredElements; }
@Override public Element _apply(final Row row) { final Element element; final String group = row.getAs(SchemaToStructTypeConverter.GROUP); final Object source = ArrayUtils.contains(row.schema().fieldNames(), SchemaToStructTypeConverter.SRC_COL_NAME) ? row.getAs(SchemaToStructTypeConverter.SRC_COL_NAME) : null; if (null != source) { final Object destination = row.getAs(SchemaToStructTypeConverter.DST_COL_NAME); final boolean directed = row.getAs(SchemaToStructTypeConverter.DIRECTED_COL_NAME); final MatchedVertex matchedVertex; if (ArrayUtils.contains(row.schema().fieldNames(), SchemaToStructTypeConverter.MATCHED_VERTEX_COL_NAME)) { final String matchedVertexStr = row.getAs(SchemaToStructTypeConverter.MATCHED_VERTEX_COL_NAME); matchedVertex = null != matchedVertexStr ? MatchedVertex.valueOf(matchedVertexStr) : null; } else { matchedVertex = null; } element = new Edge(group, source, destination, directed, matchedVertex, null); } else { final Object vertex = ArrayUtils.contains(row.schema().fieldNames(), SchemaToStructTypeConverter.VERTEX_COL_NAME) ? row.getAs(SchemaToStructTypeConverter.VERTEX_COL_NAME) : row.getAs(SchemaToStructTypeConverter.ID); element = new Entity(group, vertex); } getPropertyNames(row).forEach(n -> { element.putProperty(n, row.getAs(n)); }); return element; }
@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()); }
@SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST", justification = "If an element is not an Entity it must be an Edge") @Override public String getObject(final Element element) { if (element instanceof Entity) { final Entity entity = ((Entity) element); return entity.getVertex() + "," + entity.getProperty("count"); } else { final Edge edge = ((Edge) element); return edge.getSource() + "," + edge.getDestination() + "," + edge.getProperty("count"); } } }
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); } } }
if (!((Entity) element).getVertex().equals(((Entity) element2).getVertex())) { return false; if (!((Edge) element).getSource().equals(((Edge) element2).getSource())) { return false; if (!((Edge) element).getDestination().equals(((Edge) element2).getDestination())) { return false; if (!((Edge) element).getDirectedType().equals(((Edge) element2).getDirectedType())) { return false;
@Test public void shouldNotSwapVerticesIfSourceIsLessThanDestination_comparable() { // Given final Edge edge = new Edge.Builder().group(TestGroups.EDGE) .directed(false) .source(new Integer(1)) .dest(new Integer(2)) .build(); // Then assertThat(edge.getSource(), equalTo(new Integer(1))); assertThat(edge.getDestination(), equalTo(new Integer(2))); }
@Override public Element getElement(final String line) { final String[] t = line.split(","); final Edge edge = new Edge(t[2]); edge.setSource(t[0]); edge.setDestination(t[1]); edge.putProperty("count", 1); edge.putProperty("visibility", t[3]); return edge; }
@Override public String toString() { return new ToStringBuilder(this) .append("source", getSource()) .append("destination", getDestination()) .append("directed", isDirected()) .append("matchedVertex", getMatchedVertex()) .appendSuper(super.toString()) .build(); }
@Test public void shouldSetIdentifiers() { // Given final Edge edge1 = new Edge(TestGroups.EDGE, 1, 2, false); final Edge edge2 = new Edge(TestGroups.EDGE_2, 4, 3, false); // When edge1.setIdentifiers(4, 3, false); edge1.setGroup(TestGroups.EDGE_2); // Then assertEquals(3, edge1.getSource()); assertThat(edge1, equalTo(edge2)); }
final Element e; if (isEntity) { e = new Entity(group); } else { e = new Edge(group); if (isEntity) { if (ParquetStoreConstants.VERTEX.equals(column)) { ((Entity) e).setVertex(gafferObject); } else { e.putProperty(column, gafferObject); ((Edge) e).setIdentifiers(src, dst, isDir);
final Edge edge = new Edge("edgeGroup", source, destination, true); edge.putProperty("count", 1L); results.add(edge); if (includeEntities) { final Entity sourceEntity = new Entity("entityGroup", source); sourceEntity.putProperty("count", 1L); final HyperLogLogPlus sourceHLLPP = new HyperLogLogPlus(5, 5); sourceHLLPP.offer(destination); sourceEntity.putProperty("approxDegree", sourceHLLPP); results.add(sourceEntity); final Entity destinationEntity = new Entity("entityGroup", destination);
public Edge build() { return new Edge(group, source, dest, directed, matchedVertex, properties); } }
private void _writeElements(final Iterator<? extends Element> elements) throws OperationException, IOException { while (elements.hasNext()) { final Element element = elements.next(); final String group = element.getGroup(); ParquetWriter<Element> writer = null; final Map<Integer, ParquetWriter<Element>> splitToWriter; if (groupSplitToWriter.containsKey(group)) { splitToWriter = groupSplitToWriter.get(group); } else { splitToWriter = new HashMap<>(); groupSplitToWriter.put(group, splitToWriter); } if (schemaUtils.getEntityGroups().contains(group)) { writer = getWriter(splitToWriter, groupToSplitPoints.get(group), ((Entity) element).getVertex(), group, ParquetStoreConstants.VERTEX); } else if (schemaUtils.getEdgeGroups().contains(group)) { writer = getWriter(splitToWriter, groupToSplitPoints.get(group), ((Edge) element).getSource(), group, ParquetStoreConstants.SOURCE); } if (null != writer) { writer.write(element); } else { LOGGER.warn("Skipped the adding of an Element with Group = {} as that group does not exist in the schema.", group); } } }