@Override public int compare(final Element e1, final Element e2) { count++; if (null == e1) { if (null == e2) { return 0; } return 1; } if (null == e2) { return -1; } if (!groups.contains(e1.getGroup())) { if (!groups.contains(e2.getGroup())) { return 0; } return 1; } if (!groups.contains(e2.getGroup())) { return -1; } return _compare(e1.getProperty(property), e2.getProperty(property)); }
@Test public void shouldRemoveProperty() { // Given final Element element1 = newElement("group"); element1.putProperty("property1", "propertyValue1"); element1.putProperty("property2", "propertyValue2"); // When element1.removeProperty("property1"); // Then assertEquals(1, element1.getProperties().size()); assertEquals(null, element1.getProperty("property1")); assertEquals("propertyValue2", element1.getProperty("property2")); }
@Test public void shouldCopyProperties() { // Given final Element element1 = newElement("group"); final Properties newProperties = new Properties("property1", "propertyValue1"); // When element1.copyProperties(newProperties); // Then assertEquals(1, element1.getProperties().size()); assertEquals("propertyValue1", element1.getProperty("property1")); }
public Element shallowClone() { final Element element = emptyClone(); element.setProperties(getProperties().clone()); return element; }
@Override public Object get(final String reference) { if (ELEMENT.equals(reference)) { return element; } if (PROPERTIES.equals(reference)) { return element.getProperties(); } final IdentifierType idType = IdentifierType.fromName(reference); if (null == idType) { return element.getProperty(reference); } return element.getIdentifier(idType); }
@Override public void put(final String reference, final Object value) { if (ELEMENT.equals(reference)) { throw new IllegalArgumentException("You are not allowed to set an entire Element on this ElementTuple"); } if (PROPERTIES.equals(reference)) { element.copyProperties(((Properties) value)); } final IdentifierType idType = IdentifierType.fromName(reference); if (null == idType) { element.putProperty(reference, value); } else { element.putIdentifier(idType, value); } }
private Element addNonAggElement(final Element element, final Schema schema, final MapImpl mapImpl) { final Element elementClone = element.emptyClone(); // Copy properties that exist in the schema final SchemaElementDefinition elementDef = schema.getElement(element.getGroup()); for (final String property : elementDef.getProperties()) { elementClone.putProperty(property, element.getProperty(property)); } mapImpl.addNonAggElement(elementClone); return elementClone; }
@Override public String apply(final Element element) { return null != element ? element.getGroup() : null; } }
/** * Attempts to find the value of a field from a given {@link Element}, * corresponding to a provided key, where the key is the name of the field. * * @param element the Element from which to retrieve a field value * @param key the name of the field to be retrieved * @return the value of the field */ private Object getFieldValue(final Element element, final String key) { final IdentifierType idType = IdentifierType.fromName(key); final Object value; if (null == idType) { if (GROUP.equals(key)) { value = element.getGroup(); } else { value = element.getProperty(key); } } else { value = element.getIdentifier(idType); } return value; }
@Test public void shouldSetAndGetFields() { // Given final String group = "group"; final Properties properties = new Properties(); final Element element = newElement(); // When element.setGroup(group); element.setProperties(properties); // Then assertEquals(group, element.getGroup()); assertSame(properties, element.getProperties()); }
log("GET_A-B_EDGE_RESULT", edge.toString()); final CloseableIterable<? extends Element> edges = graph.execute(query, user); final Element edge = edges.iterator().next(); final ReservoirItemsSketch<String> stringsSketch = ((com.yahoo.sketches.sampling.ReservoirItemsUnion) edge.getProperty("stringsSample")) .getResult(); final String[] samples = stringsSketch.getSamples(); final CloseableIterable<? extends Element> entities = graph.execute(query2, user); final Element entity = entities.iterator().next(); final ReservoirItemsSketch<String> neighboursSketch = ((com.yahoo.sketches.sampling.ReservoirItemsUnion) entity.getProperty("neighboursSample")) .getResult(); final String[] neighboursSample = neighboursSketch.getSamples();
Element getAggElement(final Element element) { final Element clone = element.emptyClone(); clone.copyProperties(element.getProperties()); clone.copyProperties(aggElements.get(element.getGroup()).get(element)); return clone; }
@Override public Object apply(final Element element) { return null != element ? element.getProperty(name) : null; }
@Override public Value getValueFromElement(final Element element) { return getValueFromProperties(element.getGroup(), element.getProperties()); }
@Override public Element getFullElement(final Key key, final Value value, final boolean includeMatchedVertex) { final Element element = getElementFromKey(key, includeMatchedVertex); element.copyProperties(getPropertiesFromValue(element.getGroup(), value)); return element; }
Stream<Element> getAllAggElements(final Set<String> groups) { return aggElements.entrySet().stream() .filter(entry -> groups.contains(entry.getKey())) .map(Map.Entry::getValue) .flatMap(map -> map.entrySet().stream()) .map(x -> { final Element element = x.getKey().emptyClone(); element.copyProperties(x.getKey().getProperties()); element.copyProperties(x.getValue()); return cloneElement(element, schema); }); }
/** * Aggregates the element. Note - only the element properties are aggregated. * Aggregation requires elements to have the same identifiers and group. * * @param state the other element to aggregate. This is normally the 'state' where the aggregated results will be set. * @param element the element to aggregated * @return Element - the aggregated element */ public Element apply(final Element state, final Element element) { if (null == state) { return element; } apply(state.getProperties(), element.getProperties()); return state; }
while (dataIter.hasNext()) { final Element element = dataIter.next(); if (group.equals(element.getGroup())) { if (counter == sampleRate) { if (isEntity) { sample.add(element.getIdentifier(IdentifierType.VERTEX)); } else { sample.add(element.getIdentifier(IdentifierType.SOURCE));
@Override public String toString() { return new ToStringBuilder(this) .append("source", getSource()) .append("destination", getDestination()) .append("directed", isDirected()) .append("matchedVertex", getMatchedVertex()) .appendSuper(super.toString()) .build(); }
private Boolean isVisible(final Element e) throws VisibilityParseException { if (e.getProperty(visibility) != null) { final VisibilityEvaluator visibilityEvaluator = new VisibilityEvaluator(auths); final ElementVisibility elementVisibility = new ElementVisibility((String) e.getProperty(visibility)); return visibilityEvaluator.evaluate(elementVisibility); } else { e.putProperty(visibility, new String()); return true; } } }