@Override public String apply(final Element element) { return null != element ? element.getGroup() : null; } }
public boolean shallowEquals(final Element element) { return null != element && new EqualsBuilder() .append(group, element.getGroup()) .isEquals(); }
@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)); }
/** * Remove properties from the supplied element, according to the {@link ViewElementDefinition} * in the {@link View}. * * @param view the view to apply * @param element the element to modify */ public static void removeProperties(final View view, final Element element) { if (null != view && null != element) { removeProperties(view.getElement(element.getGroup()), element); } }
/** * 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; }
/** * 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 shouldCreateElementWithGroup() { // Given final String group = "group"; // When final Element element = newElement(group); // Then assertEquals("group", element.getGroup()); }
@Test public void shouldCreateElementWithUnknownGroup() { // Given // When final Element element = newElement(); // Then assertEquals(Element.DEFAULT_GROUP, element.getGroup()); }
@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()); }
@Override public String apply(final Element element) { return null != element ? element.getGroup() : null; } }
Iterable<Element> getNonAggElements(final Element element) { final Long count = nonAggElements.get(element.getGroup()).get(element); if (null == count || count < 1) { return Collections.emptyList(); } return new RepeatItemIterable<>(element, count); }
@Override public Person getObject(final Element element) { if (Group.PERSON.equals(element.getGroup()) && element instanceof Entity) { return new Person(((Entity) element).getVertex().toString(), element.getProperty(Property.NAME).toString(), (Integer) element.getProperty(Property.AGE)); } throw new UnsupportedOperationException("Cannot generate Person object from " + element); } }
@Override public String _apply(final Element element) { if (!(element instanceof Edge && "RoadUse".equals(element.getGroup()))) { throw new UnsupportedOperationException("Only RoadUse edges should be used"); } final Edge edge = ((Edge) element); return edge.getSource() + "," + edge.getDestination() + "," + edge.getProperty("count"); } }
@Override public Review getObject(final Element element) { if (Group.REVIEW.equals(element.getGroup()) && element instanceof Entity) { final int rating = (int) ((long) element.getProperty(Property.RATING) / (int) element.getProperty(Property.COUNT)); return new Review(((Entity) element).getVertex().toString(), element.getProperty(Property.USER_ID).toString(), rating); } throw new UnsupportedOperationException("Cannot generate Review object from " + element); } }
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 static boolean doPostFilter(final Element element, final View view) { final ViewElementDefinition viewDef = view.getElement(element.getGroup()); if (null != viewDef) { return postFilter(element, viewDef.getPostTransformFilter()); } return true; }
protected void addPropertiesToElement(final Element element, final Key key) { element.copyProperties( getPropertiesFromColumnQualifier(element.getGroup(), key.getColumnQualifierData().getBackingArray())); element.copyProperties( getPropertiesFromColumnVisibility(element.getGroup(), key.getColumnVisibilityData().getBackingArray())); element.copyProperties( getPropertiesFromTimestamp(element.getGroup(), key.getTimestamp())); }
@Override public Element call(final Element v1, final Element v2) { if (null == gafferSchema) { gafferSchema = Schema.fromJson(jsonGafferSchema); } final ElementAggregator aggregator = gafferSchema.getElement(v2.getGroup()).getIngestAggregator(); return aggregator.apply(v1, v2); } }
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; }