/** * Converts a value of a lower domain numerical type to Long. * * @param value value * @param type type * * @return converted value */ private static long longValue(PropertyValue value, int type) { switch (type) { case SHORT: return value.getShort(); default: return value.getInt(); } }
/** * Converts a value of a lower domain numerical type to BigDecimal. * * @param value value * @param type type * * @return converted value */ private static BigDecimal bigDecimalValue(PropertyValue value, int type) { switch (type) { case SHORT: return BigDecimal.valueOf(value.getShort()); case INT: return BigDecimal.valueOf(value.getInt()); case LONG: return BigDecimal.valueOf(value.getLong()); case FLOAT: return BigDecimal.valueOf(value.getFloat()); default: return BigDecimal.valueOf(value.getDouble()); } }
/** * Converts a value of a lower domain numerical type to Float. * * @param value value * @param type type * * @return converted value */ private static float floatValue(PropertyValue value, int type) { switch (type) { case SHORT: return value.getShort(); case INT: return value.getInt(); default: return value.getLong(); } } }
/** * Converts a value of a lower domain numerical type to Double. * * @param value value * @param type type * * @return converted value */ private static double doubleValue(PropertyValue value, int type) { switch (type) { case SHORT: return value.getShort(); case INT: return value.getInt(); case LONG: return value.getLong(); default: return value.getFloat(); } }
/** * Returns the wrapped value as {@code BigDecimal}. * * @return {@code BigDecimal} value * @see BigDecimal */ public BigDecimal getBigDecimal() { BigDecimal decimal; if (isBigDecimal()) { decimal = Bytes.toBigDecimal(rawBytes, OFFSET, rawBytes.length - OFFSET); } else if (isFloat()) { decimal = BigDecimal.valueOf(getFloat()); } else if (isDouble()) { decimal = BigDecimal.valueOf(getDouble()); } else if (isShort()) { decimal = BigDecimal.valueOf(getShort()); } else if (isInt()) { decimal = BigDecimal.valueOf(getInt()); } else if (isLong()) { decimal = BigDecimal.valueOf(getLong()); } else if (isString()) { decimal = new BigDecimal(getString()); } else { throw new ClassCastException( "Cannot covert " + this.getType().getSimpleName() + " to " + BigDecimal.class.getSimpleName()); } return decimal; } /**
@Test public void testGetShort() throws Exception { PropertyValue p = PropertyValue.create(SHORT_VAL_e); assertEquals(SHORT_VAL_e, p.getShort()); }
@Test public void testSetShort() throws Exception { PropertyValue p = new PropertyValue(); p.setShort(SHORT_VAL_e); assertEquals(SHORT_VAL_e, p.getShort()); }
/** * 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; } /**
assertEquals(epgmElement.getPropertyValue(GradoopTestUtils.KEY_d).getList(), PROPERTY_MAP.get(GradoopTestUtils.KEY_d)); assertEquals(epgmElement.getPropertyValue(GradoopTestUtils.KEY_e).getShort(), PROPERTY_MAP.get(GradoopTestUtils.KEY_e)); assertEquals(epgmElement.getPropertyValue(GradoopTestUtils.KEY_f).getObject(),
assertEquals(p.getShort(), maxShort, 0); p = max(create(minBigDecimal), create(maxShort)); assertTrue(p.isShort()); assertEquals(p.getShort(), maxShort, 0); assertEquals(p.getShort(), maxShort, 0); p = max(create(minDouble), create(maxShort)); assertTrue(p.isShort()); assertEquals(p.getShort(), maxShort, 0); assertEquals(p.getShort(), maxShort, 0); p = max(create(minFloat), create(maxShort)); assertTrue(p.isShort()); assertEquals(p.getShort(), maxShort, 0); assertEquals(p.getShort(), maxShort, 0); p = max(create(minLong), create(maxShort)); assertTrue(p.isShort()); assertEquals(p.getShort(), maxShort, 0); assertEquals(p.getShort(), maxShort, 0); p = max(create(minInt), create(maxShort)); assertTrue(p.isShort()); assertEquals(p.getShort(), maxShort, 0); assertEquals(p.getShort(), maxShort, 0); p = max(create(minShort), create(maxShort)); assertTrue(p.isShort()); assertEquals(p.getShort(), maxShort, 0);
assertEquals(p.getShort(), minShort, 0); p = min(create(maxBigDecimal), create(minShort)); assertTrue(p.isShort()); assertEquals(p.getShort(), minShort, 0); assertEquals(p.getShort(), minShort, 0); p = min(create(maxDouble), create(minShort)); assertTrue(p.isShort()); assertEquals(p.getShort(), minShort, 0); assertEquals(p.getShort(), minShort, 0); p = min(create(maxFloat), create(minShort)); assertTrue(p.isShort()); assertEquals(p.getShort(), minShort, 0); assertEquals(p.getShort(), minShort, 0); p = min(create(maxLong), create(minShort)); assertTrue(p.isShort()); assertEquals(p.getShort(), minShort, 0); assertEquals(p.getShort(), minShort, 0); p = min(create(maxInt), create(minShort)); assertTrue(p.isShort()); assertEquals(p.getShort(), minShort, 0); assertEquals(p.getShort(), minShort, 0); p = min(create(maxShort), create(minShort)); assertTrue(p.isShort()); assertEquals(p.getShort(), minShort, 0);
case KEY_e: assertTrue(v.getPropertyValue(propertyKey).isShort()); assertEquals(SHORT_VAL_e, v.getPropertyValue(propertyKey).getShort()); break; case KEY_f:
case KEY_e: assertTrue(v.getPropertyValue(propertyKey).isShort()); assertEquals(SHORT_VAL_e, v.getPropertyValue(propertyKey).getShort()); break; case KEY_f:
assertEquals(SHORT_VAL_e, p.getShort());