@Override @Test public void shouldReturnFalseForEqualsWhenGroupIsDifferent() { // Given final Entity entity1 = new Entity("group"); entity1.setVertex("vertex"); final Entity entity2 = new Entity("a different group"); entity2.setVertex(entity1.getVertex()); // When boolean isEqual = entity1.equals((Object) entity2); // Then assertFalse(isEqual); assertFalse(entity1.hashCode() == entity2.hashCode()); }
/** * Constructs a by wrapping the provided {@link uk.gov.gchq.gaffer.data.element.Entity} * and using the {@link uk.gov.gchq.gaffer.data.element.ElementValueLoader} to lazily load the element's identifiers and * properties when requested. * * @param entity the entity to wrap. * @param valueLoader the element value loader to use to lazily load the element's identifiers and properties */ public LazyEntity(final Entity entity, final ElementValueLoader valueLoader) { this(entity, valueLoader, new LazyProperties(entity.getProperties(), valueLoader)); }
public Builder entities(final Iterable<Entity> entities) { if (Iterables.isEmpty(entities)) { return this; } if (Iterables.size(entities) == 1) { return entity(entities.iterator().next()); } if (distinct(Streams.toStream(entities).map(EntityId::getVertex).collect(toList()))) { throw new IllegalArgumentException("Entities must all have the same vertex."); } final Entity entity = entities.iterator().next(); if (!edges.isEmpty()) { final Object root = edges.getLast().stream().findAny().orElseThrow(RuntimeException::new).getAdjacentMatchedVertexValue(); verifyEntity(root, entity); } if (!this.entities.isEmpty()) { final Entry<Object, Set<Entity>> entry = this.entities.getLast(); final Object root = entry.getKey(); verifyEntity(root, entity); final Set<Entity> currentEntities = entry.getValue(); currentEntities.addAll(Lists.newArrayList(entities)); entry.setValue(currentEntities); } else { this.entities.push(new AbstractMap.SimpleEntry<>(entity.getVertex(), Sets.newHashSet(entities))); } return this; }
@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; }
public Builder entity(final Entity entity) { if (!edges.isEmpty()) { final Object root = edges.getLast().stream().findAny().orElseThrow(RuntimeException::new).getAdjacentMatchedVertexValue(); verifyEntity(root, entity); } if (!entities.isEmpty()) { final Object root = entities.getLast().getKey(); verifyEntity(root, entity); final Entry<Object, Set<Entity>> entry = entities.getLast(); final Set<Entity> currentEntities = entry.getValue(); currentEntities.add(entity); entry.setValue(currentEntities); } else { entities.push(new AbstractMap.SimpleEntry<>(entity.getVertex(), Sets.newHashSet(entity))); } return this; }
@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;
@Test public void shouldConstructEntity() { // Given final String vertex = "vertex1"; final String propValue = "propValue"; // When final Entity entity = new Entity(TestGroups.ENTITY, vertex); entity.putProperty(TestPropertyNames.STRING, propValue); // Then assertEquals(TestGroups.ENTITY, entity.getGroup()); assertEquals(vertex, entity.getVertex()); assertEquals(propValue, entity.getProperty(TestPropertyNames.STRING)); }
public Entity build() { return new Entity(group, vertex, properties); } }
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); destinationEntity.putProperty("count", 1L); final HyperLogLogPlus destinationHLLPP = new HyperLogLogPlus(5, 5); destinationHLLPP.offer(destination); destinationEntity.putProperty("approxDegree", destinationHLLPP); results.add(destinationEntity);
@Test public void shouldDelegateSetIdentifierToEntity() { // Given final Entity entity = new Entity("group"); final ElementValueLoader entityLoader = mock(ElementValueLoader.class); final LazyEntity lazyEntity = new LazyEntity(entity, entityLoader); final String vertex = "vertex"; // When lazyEntity.setVertex(vertex); // Then verify(entityLoader, never()).loadIdentifiers(entity); assertEquals(vertex, entity.getVertex()); }
public Iterable<Entity> run() throws OperationException { final User user = new User("user01"); .build(); graph.execute(addOpChain, user); final Iterable<Edge> edges = graph.execute(new GetAllEdges(), user); log("GET_ALL_EDGES_RESULT", edge.toString()); .build(); final CloseableIterable<Entity> allCardinalities = graph.execute(getAllCardinalities, user); log("\nAll cardinalities"); for (final Entity cardinality : allCardinalities) { final String edgeGroup = (cardinality.getProperty("edgeGroup")).toString(); log("ALL_CARDINALITIES_RESULT", "Vertex " + cardinality.getVertex() + " " + edgeGroup + ": " + ((HyperLogLogPlus) cardinality.getProperty("hllp")).cardinality()); log("\nAll summarised cardinalities"); for (final Entity cardinality : allSummarisedCardinalities) { final String edgeGroup = (cardinality.getProperty("edgeGroup")).toString(); log("ALL_SUMMARISED_CARDINALITIES_RESULT", "Vertex " + cardinality.getVertex() + " " + edgeGroup + ": " + ((HyperLogLogPlus) cardinality.getProperty("hllp")).cardinality()); final String edgeGroup = (redCardinality.getProperty("edgeGroup")).toString(); log("CARDINALITY_OF_1_RESULT", "Vertex " + redCardinality.getVertex() + " " + edgeGroup + ": " + ((HyperLogLogPlus) redCardinality.getProperty("hllp")).cardinality());
@Override public Element getElement(final Review review) { final Entity entity = new Entity(Group.REVIEW, review.getFilmId()); entity.putProperty(Property.USER_ID, review.getUserId()); entity.putProperty(Property.RATING, (long) review.getRating()); entity.putProperty(Property.COUNT, 1); return entity; }
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); } } }
private void verifyEntity(final Object source, final Entity entity) { if (!Objects.equals(source, entity.getVertex())) { throw new IllegalArgumentException("Entity must be added to correct vertex."); } }