/** * Creates a deep copy of the property value. * * @return property value */ public PropertyValue copy() { return create(getObject()); }
/** * Checks if a property value is boolean. * * @param value property value */ private static void checkBoolean(PropertyValue value) { if (!value.isBoolean()) { throw new UnsupportedTypeException(value.getObject().getClass()); } } }
/** * Returns a CSV string representation of the property value. * * @param p property value * @return CSV string */ private String propertyValueToCsvString(PropertyValue p) { if (p.isList() || p.isSet()) { return collectionToCsvString((Collection) p.getObject()); } else if (p.isMap()) { return p.getMap().entrySet().stream() .map(e -> escape(e.getKey()) + CSVConstants.MAP_SEPARATOR + escape(e.getValue())) .collect(Collectors.joining(CSVConstants.LIST_DELIMITER, "{", "}")); } else { return escape(p); } }
/** * Returns a CSV string representation of the property value. * * @param p property value * @return CSV string */ private String propertyValueToCsvString(PropertyValue p) { if (p.isList() || p.isSet()) { return collectionToCsvString((Collection) p.getObject()); } else if (p.isMap()) { return p.getMap().entrySet().stream() .map(e -> escape(e.getKey()) + CSVConstants.MAP_SEPARATOR + escape(e.getValue())) .collect(Collectors.joining(CSVConstants.LIST_DELIMITER, "{", "}")); } else { return escape(p); } }
boolean validKey = dbElement.hasProperty(queryProperty.getKey()); boolean validValue = dbElement.getPropertyValue( queryProperty.getKey()).getObject().equals(queryProperty.getValue()); match = validKey && validValue;
boolean validKey = dbElement.hasProperty(queryProperty.getKey()); boolean validValue = dbElement.getPropertyValue( queryProperty.getKey()).getObject().equals(queryProperty.getValue()); match = validKey && validValue;
/** * Checks a property value for numerical type and returns its type. * * @param value property value * * @return numerical type */ private static int checkNumericalAndGetType(PropertyValue value) { checkNotNull(value); int type; if (value.isShort()) { type = SHORT; } else if (value.isInt()) { type = INT; } else if (value.isLong()) { type = LONG; } else if (value.isFloat()) { type = FLOAT; } else if (value.isDouble()) { type = DOUBLE; } else if (value.isBigDecimal()) { type = BIG_DECIMAL; } else { throw new UnsupportedTypeException(value.getObject().getClass()); } return type; }
/** * Writes all key-value properties to a json object and returns it. * * @param entity entity with key-value properties * @return json object containing the properties * @throws JSONException */ protected JSONObject writeProperties(EPGMAttributed entity) throws JSONException { JSONObject data = new JSONObject(); if (entity.getPropertyCount() > 0) { for (String propertyKey : entity.getPropertyKeys()) { data.put( propertyKey, entity.getPropertyValue(propertyKey).getObject()); } } return data; }
/** * Writes all key-value properties to a json object and returns it. * * @param entity entity with key-value properties * @return json object containing the properties * @throws JSONException */ protected JSONObject writeProperties(EPGMAttributed entity) throws JSONException { JSONObject data = new JSONObject(); if (entity.getPropertyCount() > 0) { for (String propertyKey : entity.getPropertyKeys()) { data.put( propertyKey, entity.getPropertyValue(propertyKey).getObject()); } } return data; }
@Test public void testCreateFromMap() throws Exception { Properties properties = Properties.createFromMap(SUPPORTED_PROPERTIES); assertEquals(SUPPORTED_PROPERTIES.size(), properties.size()); for (Map.Entry<String, Object> entry : SUPPORTED_PROPERTIES.entrySet()) { String k = entry.getKey(); assertTrue(properties.containsKey(k)); assertEquals(entry.getValue(), properties.get(k).getObject()); } }
@Test public void testIterator() throws Exception { Properties properties = Properties.createFromMap(SUPPORTED_PROPERTIES); for (Property property : properties) { assertTrue(SUPPORTED_PROPERTIES.containsKey(property.getKey())); assertEquals(SUPPORTED_PROPERTIES.get(property.getKey()), property.getValue().getObject()); } }
@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 public void testSet1() throws Exception { Properties properties = Properties.create(); properties.set(KEY_1, PropertyValue.create(BOOL_VAL_1)); assertEquals(BOOL_VAL_1, properties.get(KEY_1).getObject()); // override properties.set(KEY_1, PropertyValue.create(INT_VAL_2)); assertEquals(INT_VAL_2, properties.get(KEY_1).getObject()); }
/** * Test HasEdgeLabel with a single edgeless graph. * * @throws Exception if the execution fails. */ @Test public void testEdgelessGraphHasEdgeLabel() throws Exception { LogicalGraph graph = getLoaderFromString("g0[(v0)(v1)]") .getLogicalGraphByVariable("g0"); HasEdgeLabel hasLabel = new HasEdgeLabel("anyLabel"); graph = graph.aggregate(hasLabel); EPGMGraphHead graphHead = graph.getGraphHead().collect().get(0); assertTrue("Property hasEdgeLabel_anyLabel not set", graphHead.hasProperty(hasLabel.getAggregatePropertyKey())); assertNull("Property hasEdgeLabel_anyLabel is not NULL", graphHead.getPropertyValue(hasLabel.getAggregatePropertyKey()).getObject()); }
/** * Test HasLabel with a single empty graph. * * @throws Exception if the execution fails. */ @Test public void testEmptyGraphHasElementLabel() throws Exception { LogicalGraph graph = getLoaderFromString("g0[]") .getLogicalGraphByVariable("g0"); HasLabel hasLabel = new HasLabel("anyLabel"); graph = graph.aggregate(hasLabel); EPGMGraphHead graphHead = graph.getGraphHead().collect().get(0); assertTrue("Property hasLabel_anyLabel not set", graphHead.hasProperty(hasLabel.getAggregatePropertyKey())); assertNull("Property hasLabel_anyLabel is not NULL", graphHead.getPropertyValue(hasLabel.getAggregatePropertyKey()).getObject()); }
assertNull(p.getObject()); assertEquals(BOOL_VAL_1, p.getObject()); assertEquals(SHORT_VAL_e, p.getObject()); assertEquals(INT_VAL_2, p.getObject()); assertEquals(LONG_VAL_3, p.getObject()); assertEquals(FLOAT_VAL_4, p.getObject()); assertEquals(DOUBLE_VAL_5, p.getObject()); assertEquals(STRING_VAL_6, p.getObject()); assertEquals(BIG_DECIMAL_VAL_7, p.getObject()); assertEquals(GRADOOP_ID_VAL_8, p.getObject()); assertEquals(MAP_VAL_9, p.getObject()); assertEquals(LIST_VAL_a, p.getObject());
/** * Test copying the property value */ @Test public void testCopy() { // copy primitive value PropertyValue p = create(BOOL_VAL_1); PropertyValue copy = p.copy(); assertEquals(p, copy); assertNotSame(p, copy); // deep copy complex value p = create(LIST_VAL_a); copy = p.copy(); assertEquals(p, copy); assertNotSame(p, copy); assertNotSame(LIST_VAL_a, copy.getObject()); }
assertNull(p.getObject());