/** * Creates a new property value list containing no elements. * * @return empty property value list */ public static PropertyValueList createEmptyList() { return new PropertyValueList(new byte[0]); }
/** * Returns the aggregate values as property value list * * @return aggregate values * @throws IOException on failure */ public PropertyValueList getAggregateValueList() throws IOException { return PropertyValueList.fromPropertyValues(getAggregateValues()); }
@Override public String toString() { return StringUtils.join(iterator(), ','); }
/** * Returns the property values of the given element which are used for * aggregation. If the EPGM element does not have a property, it uses the * default value or {@code PropertyValue.NULL_VALUE} instead. * * @param element attributed EPGM element * @return property values for aggregation */ public PropertyValueList getIncrementValues(EPGMElement element) throws IOException { if (f3.isEmpty()) { return PropertyValueList.createEmptyList(); } List<PropertyValue> propertyValues = getAggregateFunctions().stream() .map(f -> getIncrement(f, element)) .collect(Collectors.toList()); return PropertyValueList.fromPropertyValues(propertyValues); }
@Test public void testEqualsAndHashCode() throws IOException { PropertyValueList p1 = PropertyValueList.fromPropertyValues( Lists.newArrayList(PropertyValue.create(1L), PropertyValue.create(2L)) ); PropertyValueList p2 = PropertyValueList.fromPropertyValues( Lists.newArrayList(PropertyValue.create(1L), PropertyValue.create(2L)) ); PropertyValueList p3 = PropertyValueList.fromPropertyValues( Lists.newArrayList(PropertyValue.create(1L), PropertyValue.create(3L)) ); assertTrue(p1.equals(p2)); assertFalse(p1.equals(p3)); assertTrue(p1.hashCode() == p2.hashCode()); assertFalse(p1.hashCode() == p3.hashCode()); }
@Test public void testCompareTo() throws Exception { PropertyValueList p1 = PropertyValueList.fromPropertyValues( Lists.newArrayList(PropertyValue.create(1L), PropertyValue.create(3L)) ); PropertyValueList p2 = PropertyValueList.fromPropertyValues( Lists.newArrayList(PropertyValue.create(1L), PropertyValue.create(3L)) ); PropertyValueList p3 = PropertyValueList.fromPropertyValues( Lists.newArrayList(PropertyValue.create(1L), PropertyValue.create(4L)) ); assertTrue(p1.compareTo(p2) == 0); assertTrue(p1.compareTo(p3) < 0); assertTrue(p3.compareTo(p1) > 0); }
/** * Returns the property values of the given element which are used for * aggregation. If the EPGM element does not have a property, it uses the * default value or {@code PropertyValue.NULL_VALUE} instead. * * @param element attributed EPGM element * @return property values for aggregation */ public PropertyValueList getIncrementValues(EPGMElement element) throws IOException { if (f3.isEmpty()) { return PropertyValueList.createEmptyList(); } List<PropertyValue> propertyValues = getAggregateFunctions().stream() .map(f -> getIncrement(f, element)) .collect(Collectors.toList()); return PropertyValueList.fromPropertyValues(propertyValues); }
/** * Sets the aggregate values * * @param aggregateValues aggregate value list */ public void setAggregateValues(PropertyValueList aggregateValues) { List<PropertyValue> aggregate = new ArrayList<>(); aggregateValues.iterator().forEachRemaining(aggregate::add); setAggregateValues(aggregate); }
/** * Returns the aggregate values as property value list * * @return aggregate values * @throws IOException on failure */ public PropertyValueList getAggregateValueList() throws IOException { return PropertyValueList.fromPropertyValues(getAggregateValues()); }
/** * Creates a Property value list from a collection of property values. * * @param propertyValues property values * * @return property value list containing the given properties */ public static PropertyValueList fromPropertyValues( Collection<PropertyValue> propertyValues) throws IOException { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); DataOutputStream outputStream = new DataOutputStream(byteStream); DataOutputView outputView = new DataOutputViewStreamWrapper(outputStream); for (PropertyValue propertyValue : propertyValues) { propertyValue.write(outputView); } outputStream.flush(); return new PropertyValueList(byteStream.toByteArray()); }
/** * Sets the aggregate values * * @param aggregateValues aggregate value list */ public void setAggregateValues(PropertyValueList aggregateValues) { List<PropertyValue> aggregate = new ArrayList<>(); aggregateValues.iterator().forEachRemaining(aggregate::add); setAggregateValues(aggregate); }
groupItem.setGroupingValues(PropertyValueList.fromPropertyValues(groupingValues)); groupingValues.clear();
@Test public void testEmptyIterator() throws Exception { PropertyValueList p = new PropertyValueList(); List<PropertyValue> expected = Lists.newArrayList(p); assertEquals(0, expected.size()); } }
/** * Adds the given group properties to the attributed element. * * @param attributed attributed element * @param groupPropertyValues group property values * @param vertexLabelGroup vertex label group */ protected void setGroupProperties(EPGMAttributed attributed, PropertyValueList groupPropertyValues, LabelGroup vertexLabelGroup) { Iterator<PropertyValue> valueIterator = groupPropertyValues.iterator(); for (String groupPropertyKey : vertexLabelGroup.getPropertyKeys()) { attributed.setProperty(groupPropertyKey, valueIterator.next()); } }
groupItem.setGroupingValues(PropertyValueList.fromPropertyValues(groupingValues)); groupingValues.clear();
/** * Sets the given property values as new properties at the given element. * @param element attributed element * @param values aggregate values * @param valueAggregators aggregate functions */ protected void setAggregateProperties(EPGMAttributed element, PropertyValueList values, List<AggregateFunction> valueAggregators) { if (!valueAggregators.isEmpty()) { Iterator<PropertyValue> valueIt = values.iterator(); for (AggregateFunction valueAggregator : valueAggregators) { element.setProperty(valueAggregator.getAggregatePropertyKey(), valueIt.next()); } } } }
@Test public void testIterator() throws Exception { PropertyValueList p = PropertyValueList.fromPropertyValues( Lists.newArrayList( PropertyValue.create(GradoopTestUtils.NULL_VAL_0),
/** * Adds the given group properties to the attributed element. * * @param attributed attributed element * @param groupPropertyValues group property values * @param vertexLabelGroup vertex label group */ protected void setGroupProperties(EPGMAttributed attributed, PropertyValueList groupPropertyValues, LabelGroup vertexLabelGroup) { Iterator<PropertyValue> valueIterator = groupPropertyValues.iterator(); for (String groupPropertyKey : vertexLabelGroup.getPropertyKeys()) { attributed.setProperty(groupPropertyKey, valueIterator.next()); } }
@Test public void testWriteAndReadFields() throws Exception { PropertyValueList p1 = PropertyValueList.fromPropertyValues( Lists.newArrayList( PropertyValue.create(GradoopTestUtils.NULL_VAL_0), PropertyValue.create(GradoopTestUtils.BOOL_VAL_1), PropertyValue.create(GradoopTestUtils.INT_VAL_2), PropertyValue.create(GradoopTestUtils.LONG_VAL_3), PropertyValue.create(GradoopTestUtils.FLOAT_VAL_4), PropertyValue.create(GradoopTestUtils.DOUBLE_VAL_5), PropertyValue.create(GradoopTestUtils.STRING_VAL_6), PropertyValue.create(GradoopTestUtils.BIG_DECIMAL_VAL_7) ) ); PropertyValueList p2 = writeAndReadFields(PropertyValueList.class, p1); assertEquals(p1, p2); }
/** * Sets the given property values as new properties at the given element. * @param element attributed element * @param values aggregate values * @param valueAggregators aggregate functions */ protected void setAggregateProperties(EPGMAttributed element, PropertyValueList values, List<AggregateFunction> valueAggregators) { if (!valueAggregators.isEmpty()) { Iterator<PropertyValue> valueIt = values.iterator(); for (AggregateFunction valueAggregator : valueAggregators) { element.setProperty(valueAggregator.getAggregatePropertyKey(), valueIt.next()); } } } }