/** * Returns the wrapped value as object. * * @return value or {@code null} if the value is empty */ public Object getObject() { return isBoolean() ? getBoolean() : isShort() ? getShort() : isInt() ? getInt() : isLong() ? getLong() : isFloat() ? getFloat() : isDouble() ? getDouble() : isString() ? getString() : isBigDecimal() ? getBigDecimal() : isGradoopId() ? getGradoopId() : isMap() ? getMap() : isList() ? getList() : isDate() ? getDate() : isTime() ? getTime() : isDateTime() ? getDateTime() : isSet() ? getSet() : null; } /**
@Test public void testIsFloat() throws Exception { PropertyValue p = PropertyValue.create(FLOAT_VAL_4); assertFalse(p.isNull()); assertFalse(p.isBoolean()); assertFalse(p.isShort()); assertFalse(p.isInt()); assertFalse(p.isLong()); assertTrue(p.isFloat()); assertFalse(p.isDouble()); assertFalse(p.isString()); assertFalse(p.isBigDecimal()); assertFalse(p.isGradoopId()); assertFalse(p.isMap()); assertFalse(p.isList()); assertFalse(p.isDate()); assertFalse(p.isTime()); assertFalse(p.isDateTime()); assertFalse(p.isSet()); }
if (propertyValue.isNull()) { return TypeString.NULL.getTypeString(); } else if (propertyValue.isShort()) { return TypeString.SHORT.getTypeString(); } else if (propertyValue.isInt()) { return TypeString.INTEGER.getTypeString(); } else if (propertyValue.isLong()) { return TypeString.LONG.getTypeString(); } else if (propertyValue.isFloat()) { return TypeString.FLOAT.getTypeString(); } else if (propertyValue.isDouble()) { return TypeString.DOUBLE.getTypeString(); } else if (propertyValue.isBoolean()) { return TypeString.BOOLEAN.getTypeString(); } else if (propertyValue.isString()) { return TypeString.STRING.getTypeString(); } else if (propertyValue.isBigDecimal()) { return TypeString.BIGDECIMAL.getTypeString(); } else if (propertyValue.isGradoopId()) { return TypeString.GRADOOPID.getTypeString(); } else if (propertyValue.isMap()) { getTypeString(propertyValue.getMap().keySet().iterator().next()) + PROPERTY_TOKEN_DELIMITER + getTypeString(propertyValue.getMap().values().iterator().next()); } else if (propertyValue.isList()) { getTypeString(propertyValue.getList().get(0)); } else if (propertyValue.isDate()) {
int a = aType == INT ? aValue.getInt() : aValue.getShort(); int b = bType == INT ? bValue.getInt() : bValue.getShort(); aValue.setInt(a * b); a = aValue.getFloat(); b = bValue.getFloat(); } else { a = aType == FLOAT ? aValue.getFloat() : floatValue(aValue, aType); b = bType == FLOAT ? bValue.getFloat() : floatValue(bValue, bType); aValue.setFloat(a * b); a = aValue.getLong(); b = bValue.getLong(); } else { a = aType == LONG ? aValue.getLong() : longValue(aValue, aType); b = bType == LONG ? bValue.getLong() : longValue(bValue, bType); aValue.setLong(a * b); a = aValue.getDouble(); b = bValue.getDouble(); } else { a = aType == DOUBLE ? aValue.getDouble() : doubleValue(aValue, aType); b = bType == DOUBLE ? bValue.getDouble() : doubleValue(bValue, bType); aValue.setDouble(a * b);
/** * 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); } }
@Test public void testAppendSingleIdAndProperties() { GradoopId id = GradoopId.get(); Embedding embedding = new Embedding(); embedding.add(id, PropertyValue.create("String"), PropertyValue.create(42)); assertEquals(1, embedding.size()); assertEquals(id, embedding.getId(0)); assertEquals("String", embedding.getProperty(0).getString()); assertEquals(42, embedding.getProperty(1).getInt()); }
@Override public GraphHead map(GraphHead graphHead) throws Exception { PropertyValue averageProperty = graphHead.getPropertyValue(propertyKeySumLocal); double sumLocal = averageProperty.isNull() ? 0.0 : averageProperty.getDouble(); long vertexCount = graphHead.getPropertyValue(propertyKeyVertexCount).getLong(); graphHead.setProperty(propertyKeyAverage, vertexCount == 0L ? 0.0 : (sumLocal / (double) vertexCount)); return graphHead; } }
p = add(create(BIG_DECIMAL_VAL_7), create(BIG_DECIMAL_VAL_7)); assertTrue(p.isBigDecimal()); assertEquals(BIG_DECIMAL_VAL_7.add(BIG_DECIMAL_VAL_7).compareTo(p.getBigDecimal()), 0); p = add(create(BIG_DECIMAL_VAL_7), create(DOUBLE_VAL_5)); assertTrue(p.isBigDecimal()); assertEquals(BIG_DECIMAL_VAL_7.add(BigDecimal.valueOf(DOUBLE_VAL_5)).compareTo(p.getBigDecimal()), 0); p = add(create(DOUBLE_VAL_5), create(BIG_DECIMAL_VAL_7)); assertTrue(p.isBigDecimal()); assertEquals((BigDecimal.valueOf(DOUBLE_VAL_5)).add(BIG_DECIMAL_VAL_7).compareTo(p.getBigDecimal()), 0); p = add(create(BIG_DECIMAL_VAL_7), create(FLOAT_VAL_4)); assertTrue(p.isBigDecimal()); assertEquals(BIG_DECIMAL_VAL_7.add(BigDecimal.valueOf(FLOAT_VAL_4)).compareTo(p.getBigDecimal()), 0); p = add(create(FLOAT_VAL_4), create(BIG_DECIMAL_VAL_7)); assertTrue(p.isBigDecimal()); assertEquals((BigDecimal.valueOf(FLOAT_VAL_4)).add(BIG_DECIMAL_VAL_7).compareTo(p.getBigDecimal()), 0); p = add(create(BIG_DECIMAL_VAL_7), create(LONG_VAL_3)); assertTrue(p.isBigDecimal()); assertEquals(BIG_DECIMAL_VAL_7.add(BigDecimal.valueOf(LONG_VAL_3)).compareTo(p.getBigDecimal()), 0); p = add(create(LONG_VAL_3), create(BIG_DECIMAL_VAL_7)); assertTrue(p.isBigDecimal()); assertEquals((BigDecimal.valueOf(LONG_VAL_3)).add(BIG_DECIMAL_VAL_7).compareTo(p.getBigDecimal()), 0); p = add(create(BIG_DECIMAL_VAL_7), create(INT_VAL_2)); assertTrue(p.isBigDecimal()); assertEquals(BIG_DECIMAL_VAL_7.add(BigDecimal.valueOf(INT_VAL_2)).compareTo(p.getBigDecimal()), 0); p = add(create(INT_VAL_2), create(BIG_DECIMAL_VAL_7));
@Test public void testFailedBigDecimalConversion() { exception.expect(ClassCastException.class); create(BOOL_VAL_1).getBigDecimal(); }
@Test public void testAddReturningInteger() { PropertyValue p; // int p = add(create(INT_VAL_2), create(INT_VAL_2)); assertTrue(p.isInt()); assertEquals(INT_VAL_2 + INT_VAL_2, p.getInt(), 0); // short p = add(create(INT_VAL_2), create(SHORT_VAL_e)); assertTrue(p.isInt()); assertEquals(INT_VAL_2 + SHORT_VAL_e, p.getInt(), 0); p = add(create(SHORT_VAL_e), create(INT_VAL_2)); assertTrue(p.isInt()); assertEquals(SHORT_VAL_e + INT_VAL_2, p.getInt(), 0); p = add(create(SHORT_VAL_e), create(SHORT_VAL_e)); assertTrue(p.isInt()); assertEquals(SHORT_VAL_e + SHORT_VAL_e, p.getInt(), 0); }
/** * {@inheritDoc} */ @Override public Tuple3<Edge, Boolean, Boolean> join(Tuple3<Edge, GradoopId, Boolean> interim, Vertex vertex) { reuse.f0 = interim.f0; reuse.f1 = interim.f2; reuse.f2 = vertex.getPropertyValue(propertyKey).getBoolean(); return reuse; } }
@Override public boolean filter(Edge edge) { PropertyValue value = edge.getPropertyValue("count"); return value.getLong() > 500; } }
@Test public void testVariableMappingCreation() throws Exception { AddGraphElementToNewGraph<Vertex> udf = new AddGraphElementToNewGraph<>(new GraphHeadFactory(), "a"); Vertex vertex = new VertexFactory().createVertex(); Tuple2<Vertex, GraphHead> result = udf.map(vertex); assertTrue(result.f1.hasProperty(PatternMatching.VARIABLE_MAPPING_KEY)); Map<PropertyValue, PropertyValue> variableMapping = result.f1.getPropertyValue(PatternMatching.VARIABLE_MAPPING_KEY).getMap(); assertEquals(vertex.getId(), variableMapping.get(PropertyValue.create("a")).getGradoopId()); } }
@Override public boolean filter(V v) throws Exception { return v.getPropertyValue(BusinessTransactionGraphs.SUPERTYPE_KEY) .getString().equals( BusinessTransactionGraphs.SUPERCLASS_VALUE_MASTER); } }
@Override public void testNonConnectedGraph() throws Exception { validateGraphProperties(nonConnectedGraph); GraphHead head = nonConnectedGraph.getGraphHead().collect().get(0); double global = head.getPropertyValue(ClusteringCoefficientBase.PROPERTY_KEY_GLOBAL) .getDouble(); assertTrue("Wrong global value for not connected graph, should be 0 or NaN", Double.isNaN(global)); }