/** * Returns a list of properties. * * @return List of properties */ public List<Property> toList() { return properties.entrySet().stream() .map(e -> Property.create(e.getKey(), e.getValue())) .collect(Collectors.toList()); }
/** * Creates a new property from the given arguments. * * @param key property key * @param value property value * @return property */ public static Property create(String key, PropertyValue value) { return new Property(key, value); }
@Test public void testCompareTo() throws Exception { Property p1 = new Property("key1", PropertyValue.create(10)); Property p2 = new Property("key1", PropertyValue.create(10)); Property p3 = new Property("key2", PropertyValue.create(10)); assertEquals(0, p1.compareTo(p1)); assertEquals(0, p1.compareTo(p2)); assertTrue(p1.compareTo(p3) < 0); assertTrue(p3.compareTo(p1) > 0); }
@Test public void testEqualsAndHashCode() throws Exception { Property p1 = new Property("key1", PropertyValue.create(10)); Property p2 = new Property("key1", PropertyValue.create(10)); Property p3 = new Property("key1", PropertyValue.create(11)); Property p4 = new Property("key2", PropertyValue.create(10)); Property p5 = new Property("key2", PropertyValue.create(11)); assertEquals(p1, p1); assertEquals(p1, p2); assertNotEquals(p1, p3); assertNotEquals(p1, p4); assertNotEquals(p1, p5); assertEquals(p1.hashCode(), p1.hashCode()); assertEquals(p1.hashCode(), p2.hashCode()); assertNotEquals(p1.hashCode(), p3.hashCode()); assertNotEquals(p1.hashCode(), p4.hashCode()); assertNotEquals(p1.hashCode(), p5.hashCode()); }
/** * Removes the given property from the list. * * @param property property * @return the previous value associated with <tt>key</tt>, or * <tt>null</tt> if there was no mapping for <tt>key</tt>. */ public PropertyValue remove(Property property) { Objects.requireNonNull(property); return remove(property.getKey()); }
@Test public void testPropertySerialization() throws Exception { Property pIn = Property.create("key1", 10L); assertEquals("Properties were not equal", pIn, GradoopFlinkTestUtils.writeAndRead(pIn, getExecutionEnvironment())); }
/** * Creates a new property from the given arguments. Note that the given * value type must be supported by {@link PropertyValue}. * * @param key property key * @param value property value * @return property */ public static Property create(String key, Object value) { return new Property(key, PropertyValue.create(value)); }
@Test public void testSet() throws Exception { Properties properties = Properties.create(); properties.set(Property.create(KEY_1, BOOL_VAL_1)); assertEquals(BOOL_VAL_1, properties.get(KEY_1).getObject()); // override properties.set(Property.create(KEY_1, INT_VAL_2)); assertEquals(INT_VAL_2, properties.get(KEY_1).getObject()); }
@Test (expected = NullPointerException.class) public void testSetValueNull2() { new Property("key", null); }