/** * 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; }
/** * Remove properties from the supplied element, according to the {@link ViewElementDefinition}. * * @param elDef the element definition to apply * @param element the element to modify */ public static void removeProperties(final ViewElementDefinition elDef, final Element element) { removeProperties(elDef, element.getProperties()); }
@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); }
public Element shallowClone() { final Element element = emptyClone(); element.setProperties(getProperties().clone()); return element; }
@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()); }
@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")); }
@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 shouldAggregateWithNoPropertiesOrFunctions() { // Given final ElementAggregator aggregator = new ElementAggregator(); final Edge edge1 = new Edge.Builder().group("group").build(); final Edge edge2 = new Edge.Builder().group("group").build(); // When - aggregate and set state final Element result = aggregator.apply(edge1, edge2); // Then assertEquals(edge2, result); assertTrue(result.getProperties().isEmpty()); }
/** * 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; }
/** * Remove properties from the supplied element, according to the {@link ViewElementDefinition}. * * @param elDef the element definition to apply * @param element the element to modify */ public static void removeProperties(final ViewElementDefinition elDef, final Element element) { removeProperties(elDef, element.getProperties()); }
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); }); }
@Override public Value getValueFromElement(final Element element) { return getValueFromProperties(element.getGroup(), element.getProperties()); }
@Override public Element next() { final double prob = random.nextDouble(); if (prob < repeatProb) { final Element element = cache.get(); return element == null ? elementIterator.next() : element; } final Element element = elementIterator.next(); final Element clonedElement = element.emptyClone(); clonedElement.copyProperties(element.getProperties()); cache.add(clonedElement); 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); }
Element getAggElement(final Element element) { final Element clone = element.emptyClone(); clone.copyProperties(element.getProperties()); clone.copyProperties(aggElements.get(element.getGroup()).get(element)); return clone; }
public Element shallowClone() { final Element element = emptyClone(); element.setProperties(getProperties().clone()); return element; }
/** * Clone an {@link Element}, based on a target {@link Schema}. * * @param element the element to clone * @param schema the schema * @return the cloned element */ public Element cloneElement(final Element element, final Schema schema) { try { final Element clone = element.emptyClone(); final SchemaElementDefinition sed = schema.getElement(clone.getGroup()); for (final String propertyName : element.getProperties().keySet()) { final Object property = element.getProperty(propertyName); if (null == sed.getPropertyTypeDef(propertyName) || null == sed.getPropertyTypeDef(propertyName).getSerialiser()) { // This can happen if transient properties are derived - they will not have serialisers. LOGGER.warn("Can't find Serialisation for {}, returning uncloned property", propertyName); clone.putProperty(propertyName, property); } else if (null != property) { final Serialiser serialiser = sed.getPropertyTypeDef(propertyName).getSerialiser(); clone.putProperty(propertyName, serialiser.deserialise(serialiser.serialise(property))); } else { clone.putProperty(propertyName, null); } } return clone; } catch (final SerialisationException e) { throw new RuntimeException("SerialisationException converting elements", e); } } }
final Object value = element.getProperties().get(property); if (null == value) { fields.appendElem(null); } else if (!ReservedPropertyNames.contains(property)) { if (!propertyNeedsConversion.get(property)) { fields.appendElem(element.getProperties().get(property)); } else { final Converter converter = convertersByProperty.get(property);