use of java.math.BigDecimal in project jodd by oblac.
the class BeanUtilTest method testSetPropertyMath.
@Test
public void testSetPropertyMath() {
FooBean2 fb = new FooBean2();
String propName = "fooBigDecimal";
assertEquals(BigDecimal.class, BeanUtil.pojo.getPropertyType(fb, propName));
BeanUtil.pojo.setProperty(fb, propName, new BigDecimal("1.2"));
assertEquals(1.2, fb.getFooBigDecimal().doubleValue(), 0.0005);
}
use of java.math.BigDecimal in project openhab1-addons by openhab.
the class MBrickletSoundIntensityImpl method setThreshold.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
*
* @generated
*/
@Override
public void setThreshold(BigDecimal newThreshold) {
BigDecimal oldThreshold = threshold;
threshold = newThreshold;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, ModelPackage.MBRICKLET_SOUND_INTENSITY__THRESHOLD, oldThreshold, threshold));
}
use of java.math.BigDecimal in project openhab1-addons by openhab.
the class ZWaveCommandClass method encodeValue.
/**
* Encodes a decimal value as a byte array.
*
* @param value the decimal value to encode
* @param index the value index
* @return the value buffer
* @throws ArithmeticException when the supplied value is out of range.
* @since 1.4.0
*/
protected byte[] encodeValue(BigDecimal value) throws ArithmeticException {
// Remove any trailing zero's so we send the least amount of bytes possible
BigDecimal normalizedValue = value.stripTrailingZeros();
// this is guarded by the Integer min / max values already.
if (normalizedValue.scale() < 0) {
normalizedValue = normalizedValue.setScale(0);
}
if (normalizedValue.unscaledValue().compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) > 0) {
throw new ArithmeticException();
} else if (normalizedValue.unscaledValue().compareTo(BigInteger.valueOf(Integer.MIN_VALUE)) < 0) {
throw new ArithmeticException();
}
// default size = 4
int size = 4;
// it might fit in a byte or short
if (normalizedValue.unscaledValue().intValue() >= Byte.MIN_VALUE && normalizedValue.unscaledValue().intValue() <= Byte.MAX_VALUE) {
size = 1;
} else if (normalizedValue.unscaledValue().intValue() >= Short.MIN_VALUE && normalizedValue.unscaledValue().intValue() <= Short.MAX_VALUE) {
size = 2;
}
int precision = normalizedValue.scale();
byte[] result = new byte[size + 1];
// precision + scale (unused) + size
result[0] = (byte) ((precision << PRECISION_SHIFT) | size);
// ie. 22.5 = 225
int unscaledValue = normalizedValue.unscaledValue().intValue();
for (int i = 0; i < size; i++) {
result[size - i] = (byte) ((unscaledValue >> (i * 8)) & 0xFF);
}
return result;
}
use of java.math.BigDecimal in project orientdb by orientechnologies.
the class OBinaryComparatorV0 method isEqual.
/**
* Compares if 2 field values are the same.
*
* @param iField1
* First value to compare
* @param iField2
* Second value to compare
* @return true if they match, otherwise false
*/
@Override
public boolean isEqual(final OBinaryField iField1, final OBinaryField iField2) {
final BytesContainer fieldValue1 = iField1.bytes;
final int offset1 = fieldValue1.offset;
final BytesContainer fieldValue2 = iField2.bytes;
final int offset2 = fieldValue2.offset;
try {
switch(iField1.type) {
case INTEGER:
{
final int value1 = OVarIntSerializer.readAsInteger(fieldValue1);
switch(iField2.type) {
case INTEGER:
{
final int value2 = OVarIntSerializer.readAsInteger(fieldValue2);
return value1 == value2;
}
case LONG:
case DATETIME:
{
final long value2 = OVarIntSerializer.readAsLong(fieldValue2);
return value1 == value2;
}
case DATE:
{
final long value2 = (OVarIntSerializer.readAsLong(fieldValue2) * ORecordSerializerBinaryV0.MILLISEC_PER_DAY);
return value1 == value2;
}
case SHORT:
{
final short value2 = OVarIntSerializer.readAsShort(fieldValue2);
return value1 == value2;
}
case BYTE:
{
final byte value2 = ORecordSerializerBinaryV0.readByte(fieldValue2);
return value1 == value2;
}
case FLOAT:
{
final float value2 = Float.intBitsToFloat(ORecordSerializerBinaryV0.readInteger(fieldValue2));
return value1 == value2;
}
case DOUBLE:
{
final double value2 = Double.longBitsToDouble(ORecordSerializerBinaryV0.readLong(fieldValue2));
return value1 == value2;
}
case STRING:
{
return Integer.parseInt(ORecordSerializerBinaryV0.readString(fieldValue2)) == value1;
}
case DECIMAL:
{
final BigDecimal value2 = ODecimalSerializer.INSTANCE.deserialize(fieldValue2.bytes, fieldValue2.offset);
return value1 == value2.intValue();
}
}
break;
}
case LONG:
{
final long value1 = OVarIntSerializer.readAsLong(fieldValue1);
switch(iField2.type) {
case INTEGER:
{
final int value2 = OVarIntSerializer.readAsInteger(fieldValue2);
return value1 == value2;
}
case LONG:
case DATETIME:
{
final long value2 = OVarIntSerializer.readAsLong(fieldValue2);
return value1 == value2;
}
case DATE:
{
final long value2 = (OVarIntSerializer.readAsLong(fieldValue2) * ORecordSerializerBinaryV0.MILLISEC_PER_DAY);
return value1 == value2;
}
case SHORT:
{
final short value2 = OVarIntSerializer.readAsShort(fieldValue2);
return value1 == value2;
}
case BYTE:
{
final byte value2 = ORecordSerializerBinaryV0.readByte(fieldValue2);
return value1 == value2;
}
case FLOAT:
{
final float value2 = Float.intBitsToFloat(ORecordSerializerBinaryV0.readInteger(fieldValue2));
return value1 == value2;
}
case DOUBLE:
{
final double value2 = Double.longBitsToDouble(ORecordSerializerBinaryV0.readLong(fieldValue2));
return value1 == value2;
}
case STRING:
{
return Long.parseLong(ORecordSerializerBinaryV0.readString(fieldValue2)) == value1;
}
case DECIMAL:
{
final BigDecimal value2 = ODecimalSerializer.INSTANCE.deserialize(fieldValue2.bytes, fieldValue2.offset);
return value1 == value2.longValue();
}
}
break;
}
case SHORT:
{
final short value1 = OVarIntSerializer.readAsShort(fieldValue1);
switch(iField2.type) {
case INTEGER:
{
final int value2 = OVarIntSerializer.readAsInteger(fieldValue2);
return value1 == value2;
}
case LONG:
case DATETIME:
{
final long value2 = OVarIntSerializer.readAsLong(fieldValue2);
return value1 == value2;
}
case DATE:
{
final long value2 = (OVarIntSerializer.readAsLong(fieldValue2) * ORecordSerializerBinaryV0.MILLISEC_PER_DAY);
return value1 == value2;
}
case SHORT:
{
final short value2 = OVarIntSerializer.readAsShort(fieldValue2);
return value1 == value2;
}
case BYTE:
{
final byte value2 = ORecordSerializerBinaryV0.readByte(fieldValue2);
return value1 == value2;
}
case FLOAT:
{
final float value2 = Float.intBitsToFloat(ORecordSerializerBinaryV0.readInteger(fieldValue2));
return value1 == value2;
}
case DOUBLE:
{
final double value2 = Double.longBitsToDouble(ORecordSerializerBinaryV0.readLong(fieldValue2));
return value1 == value2;
}
case STRING:
{
return Short.parseShort(ORecordSerializerBinaryV0.readString(fieldValue2)) == value1;
}
case DECIMAL:
{
final BigDecimal value2 = ODecimalSerializer.INSTANCE.deserialize(fieldValue2.bytes, fieldValue2.offset);
return value1 == value2.shortValue();
}
}
break;
}
case STRING:
{
switch(iField2.type) {
case INTEGER:
{
final int value2 = OVarIntSerializer.readAsInteger(fieldValue2);
return Integer.parseInt(ORecordSerializerBinaryV0.readString(fieldValue1)) == value2;
}
case LONG:
case DATETIME:
{
final long value2 = OVarIntSerializer.readAsLong(fieldValue2);
return Long.parseLong(ORecordSerializerBinaryV0.readString(fieldValue1)) == value2;
}
case DATE:
{
final long value2 = OVarIntSerializer.readAsLong(fieldValue2) * ORecordSerializerBinaryV0.MILLISEC_PER_DAY;
return Long.parseLong(ORecordSerializerBinaryV0.readString(fieldValue1)) == value2;
}
case SHORT:
{
final short value2 = OVarIntSerializer.readAsShort(fieldValue2);
return Short.parseShort(ORecordSerializerBinaryV0.readString(fieldValue1)) == value2;
}
case BYTE:
{
final byte value2 = ORecordSerializerBinaryV0.readByte(fieldValue2);
return Byte.parseByte(ORecordSerializerBinaryV0.readString(fieldValue1)) == value2;
}
case FLOAT:
{
final float value2 = Float.intBitsToFloat(ORecordSerializerBinaryV0.readInteger(fieldValue2));
return Float.parseFloat(ORecordSerializerBinaryV0.readString(fieldValue1)) == value2;
}
case DOUBLE:
{
final double value2 = Double.longBitsToDouble(ORecordSerializerBinaryV0.readLong(fieldValue2));
return Double.parseDouble(ORecordSerializerBinaryV0.readString(fieldValue1)) == value2;
}
case STRING:
{
final int len1 = OVarIntSerializer.readAsInteger(fieldValue1);
final int len2 = OVarIntSerializer.readAsInteger(fieldValue2);
if (len1 != len2)
return false;
final OCollate collate = (iField1.collate != null && !ODefaultCollate.NAME.equals(iField1.collate.getName())) ? iField1.collate : (iField2.collate != null && !ODefaultCollate.NAME.equals(iField2.collate.getName()) ? iField2.collate : null);
if (collate != null) {
final String str1 = (String) collate.transform(ORecordSerializerBinaryV0.stringFromBytes(fieldValue1.bytes, fieldValue1.offset, len1));
final String str2 = (String) collate.transform(ORecordSerializerBinaryV0.stringFromBytes(fieldValue2.bytes, fieldValue2.offset, len2));
return str1.equals(str2);
} else {
for (int i = 0; i < len1; ++i) {
if (fieldValue1.bytes[fieldValue1.offset + i] != fieldValue2.bytes[fieldValue2.offset + i])
return false;
}
}
return true;
}
case DECIMAL:
{
final BigDecimal value2 = ODecimalSerializer.INSTANCE.deserialize(fieldValue2.bytes, fieldValue2.offset);
return new BigDecimal(ORecordSerializerBinaryV0.readString(fieldValue1)).equals(value2);
}
case BOOLEAN:
{
final boolean value2 = ORecordSerializerBinaryV0.readByte(fieldValue2) == 1;
return Boolean.parseBoolean(ORecordSerializerBinaryV0.readString(fieldValue1)) == value2;
}
}
break;
}
case DOUBLE:
{
final long value1AsLong = ORecordSerializerBinaryV0.readLong(fieldValue1);
switch(iField2.type) {
case INTEGER:
{
final double value1 = Double.longBitsToDouble(value1AsLong);
final int value2 = OVarIntSerializer.readAsInteger(fieldValue2);
return value1 == value2;
}
case LONG:
case DATETIME:
{
final double value1 = Double.longBitsToDouble(value1AsLong);
final long value2 = OVarIntSerializer.readAsLong(fieldValue2);
return value1 == value2;
}
case SHORT:
{
final double value1 = Double.longBitsToDouble(value1AsLong);
final short value2 = OVarIntSerializer.readAsShort(fieldValue2);
return value1 == value2;
}
case BYTE:
{
final double value1 = Double.longBitsToDouble(value1AsLong);
final byte value2 = ORecordSerializerBinaryV0.readByte(fieldValue2);
return value1 == value2;
}
case FLOAT:
{
final double value1 = Double.longBitsToDouble(value1AsLong);
final float value2 = Float.intBitsToFloat(ORecordSerializerBinaryV0.readInteger(fieldValue2));
return value1 == value2;
}
case DOUBLE:
{
final double value2AsLong = ORecordSerializerBinaryV0.readLong(fieldValue2);
return value1AsLong == value2AsLong;
}
case STRING:
{
final double value1 = Double.longBitsToDouble(value1AsLong);
return Double.parseDouble(ORecordSerializerBinaryV0.readString(fieldValue2)) == value1;
}
case DECIMAL:
{
final double value1 = Double.longBitsToDouble(value1AsLong);
final BigDecimal value2 = ODecimalSerializer.INSTANCE.deserialize(fieldValue2.bytes, fieldValue2.offset);
return value1 == value2.doubleValue();
}
}
break;
}
case FLOAT:
{
final int value1AsInt = ORecordSerializerBinaryV0.readInteger(fieldValue1);
switch(iField2.type) {
case INTEGER:
{
final float value1 = Float.intBitsToFloat(value1AsInt);
final int value2 = OVarIntSerializer.readAsInteger(fieldValue2);
return value1 == value2;
}
case LONG:
case DATETIME:
{
final float value1 = Float.intBitsToFloat(value1AsInt);
final long value2 = OVarIntSerializer.readAsLong(fieldValue2);
return value1 == value2;
}
case SHORT:
{
final float value1 = Float.intBitsToFloat(value1AsInt);
final short value2 = OVarIntSerializer.readAsShort(fieldValue2);
return value1 == value2;
}
case BYTE:
{
final float value1 = Float.intBitsToFloat(value1AsInt);
final byte value2 = ORecordSerializerBinaryV0.readByte(fieldValue2);
return value1 == value2;
}
case FLOAT:
{
final float value2AsInt = ORecordSerializerBinaryV0.readInteger(fieldValue2);
return value1AsInt == value2AsInt;
}
case DOUBLE:
{
final float value1 = Float.intBitsToFloat(value1AsInt);
final double value2 = Double.longBitsToDouble(ORecordSerializerBinaryV0.readLong(fieldValue2));
return value1 == value2;
}
case STRING:
{
final float value1 = Float.intBitsToFloat(value1AsInt);
return Float.parseFloat(ORecordSerializerBinaryV0.readString(fieldValue2)) == value1;
}
case DECIMAL:
{
final float value1 = Float.intBitsToFloat(value1AsInt);
final BigDecimal value2 = ODecimalSerializer.INSTANCE.deserialize(fieldValue2.bytes, fieldValue2.offset);
return value1 == value2.floatValue();
}
}
break;
}
case BYTE:
{
final byte value1 = ORecordSerializerBinaryV0.readByte(fieldValue1);
switch(iField2.type) {
case INTEGER:
{
final int value2 = OVarIntSerializer.readAsInteger(fieldValue2);
return value1 == value2;
}
case LONG:
case DATETIME:
{
final long value2 = OVarIntSerializer.readAsLong(fieldValue2);
return value1 == value2;
}
case SHORT:
{
final short value2 = OVarIntSerializer.readAsShort(fieldValue2);
return value1 == value2;
}
case BYTE:
{
final byte value2 = ORecordSerializerBinaryV0.readByte(fieldValue2);
return value1 == value2;
}
case FLOAT:
{
final float value2 = Float.intBitsToFloat(ORecordSerializerBinaryV0.readInteger(fieldValue2));
return value1 == value2;
}
case DOUBLE:
{
final double value2 = Double.longBitsToDouble(ORecordSerializerBinaryV0.readLong(fieldValue2));
return value1 == value2;
}
case STRING:
{
final byte value2 = Byte.parseByte((ORecordSerializerBinaryV0.readString(fieldValue2)));
return value1 == value2;
}
case DECIMAL:
{
final BigDecimal value2 = ODecimalSerializer.INSTANCE.deserialize(fieldValue2.bytes, fieldValue2.offset);
return value1 == value2.byteValue();
}
}
break;
}
case BOOLEAN:
{
final boolean value1 = ORecordSerializerBinaryV0.readByte(fieldValue1) == 1;
switch(iField2.type) {
case BOOLEAN:
{
final boolean value2 = ORecordSerializerBinaryV0.readByte(fieldValue2) == 1;
return value1 == value2;
}
case STRING:
{
final String str = ORecordSerializerBinaryV0.readString(fieldValue2);
return Boolean.parseBoolean(str) == value1;
}
}
break;
}
case DATE:
{
final long value1 = OVarIntSerializer.readAsLong(fieldValue1) * ORecordSerializerBinaryV0.MILLISEC_PER_DAY;
switch(iField2.type) {
case INTEGER:
{
final int value2 = OVarIntSerializer.readAsInteger(fieldValue2);
return value1 == value2;
}
case LONG:
case DATETIME:
{
final long value2 = OVarIntSerializer.readAsLong(fieldValue2);
return value1 == value2;
}
case DATE:
{
final long value2 = OVarIntSerializer.readAsLong(fieldValue2) * ORecordSerializerBinaryV0.MILLISEC_PER_DAY;
return value1 == value2;
}
case SHORT:
{
final short value2 = OVarIntSerializer.readAsShort(fieldValue2);
return value1 == value2;
}
case FLOAT:
{
final float value2 = Float.intBitsToFloat(ORecordSerializerBinaryV0.readInteger(fieldValue2));
return value1 == value2;
}
case DOUBLE:
{
final double value2 = Double.longBitsToDouble(ORecordSerializerBinaryV0.readLong(fieldValue2));
return value1 == value2;
}
case STRING:
{
final String value2AsString = ORecordSerializerBinaryV0.readString(fieldValue2);
if (OIOUtils.isLong(value2AsString)) {
final long value2 = Long.parseLong(value2AsString);
return value1 == value2;
}
final ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
try {
final SimpleDateFormat dateFormat = db != null ? db.getStorage().getConfiguration().getDateFormatInstance() : new SimpleDateFormat(OStorageConfiguration.DEFAULT_DATETIME_FORMAT);
final Date value2AsDate = dateFormat.parse(value2AsString);
final long value2 = value2AsDate.getTime();
return value1 == value2;
} catch (ParseException e) {
try {
final SimpleDateFormat dateFormat = db != null ? db.getStorage().getConfiguration().getDateFormatInstance() : new SimpleDateFormat(OStorageConfiguration.DEFAULT_DATE_FORMAT);
final Date value2AsDate = dateFormat.parse(value2AsString);
final long value2 = value2AsDate.getTime();
return value1 == value2;
} catch (ParseException e1) {
return new Date(value1).toString().equals(value2AsString);
}
}
}
case DECIMAL:
{
final BigDecimal value2 = ODecimalSerializer.INSTANCE.deserialize(fieldValue2.bytes, fieldValue2.offset);
return value1 == value2.longValue();
}
}
break;
}
case DATETIME:
{
final long value1 = OVarIntSerializer.readAsLong(fieldValue1);
switch(iField2.type) {
case INTEGER:
{
final int value2 = OVarIntSerializer.readAsInteger(fieldValue2);
return value1 == value2;
}
case LONG:
case DATETIME:
{
final long value2 = OVarIntSerializer.readAsLong(fieldValue2);
return value1 == value2;
}
case DATE:
{
final long value2 = OVarIntSerializer.readAsLong(fieldValue2) * ORecordSerializerBinaryV0.MILLISEC_PER_DAY;
return value1 == value2;
}
case SHORT:
{
final short value2 = OVarIntSerializer.readAsShort(fieldValue2);
return value1 == value2;
}
case FLOAT:
{
final float value2 = Float.intBitsToFloat(ORecordSerializerBinaryV0.readInteger(fieldValue2));
return value1 == value2;
}
case DOUBLE:
{
final double value2 = Double.longBitsToDouble(ORecordSerializerBinaryV0.readLong(fieldValue2));
return value1 == value2;
}
case STRING:
{
final String value2AsString = ORecordSerializerBinaryV0.readString(fieldValue2);
if (OIOUtils.isLong(value2AsString)) {
final long value2 = Long.parseLong(value2AsString);
return value1 == value2;
}
final ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
try {
final SimpleDateFormat dateFormat = db != null ? db.getStorage().getConfiguration().getDateTimeFormatInstance() : new SimpleDateFormat(OStorageConfiguration.DEFAULT_DATETIME_FORMAT);
final Date value2AsDate = dateFormat.parse(value2AsString);
final long value2 = value2AsDate.getTime();
return value1 == value2;
} catch (ParseException e) {
try {
final SimpleDateFormat dateFormat = db != null ? db.getStorage().getConfiguration().getDateFormatInstance() : new SimpleDateFormat(OStorageConfiguration.DEFAULT_DATE_FORMAT);
final Date value2AsDate = dateFormat.parse(value2AsString);
final long value2 = value2AsDate.getTime();
return value1 == value2;
} catch (ParseException e1) {
return new Date(value1).toString().equals(value2AsString);
}
}
}
case DECIMAL:
{
final BigDecimal value2 = ODecimalSerializer.INSTANCE.deserialize(fieldValue2.bytes, fieldValue2.offset);
return value1 == value2.longValue();
}
}
break;
}
case BINARY:
{
switch(iField2.type) {
case BINARY:
{
final int length1 = OVarIntSerializer.readAsInteger(fieldValue1);
final int length2 = OVarIntSerializer.readAsInteger(fieldValue2);
if (length1 != length2)
return false;
for (int i = 0; i < length1; ++i) {
if (fieldValue1.bytes[fieldValue1.offset + i] != fieldValue2.bytes[fieldValue2.offset + i])
return false;
}
return true;
}
}
break;
}
case LINK:
{
switch(iField2.type) {
case LINK:
{
final int clusterId1 = OVarIntSerializer.readAsInteger(fieldValue1);
final int clusterId2 = OVarIntSerializer.readAsInteger(fieldValue2);
if (clusterId1 != clusterId2)
return false;
final long clusterPos1 = OVarIntSerializer.readAsLong(fieldValue1);
final long clusterPos2 = OVarIntSerializer.readAsLong(fieldValue2);
if (clusterPos1 == clusterPos2)
return true;
}
case STRING:
{
return ORecordSerializerBinaryV0.readOptimizedLink(fieldValue1).toString().equals(ORecordSerializerBinaryV0.readString(fieldValue2));
}
}
break;
}
case DECIMAL:
{
BigDecimal value1 = ODecimalSerializer.INSTANCE.deserialize(fieldValue1.bytes, fieldValue1.offset);
switch(iField2.type) {
case INTEGER:
{
final int value2 = OVarIntSerializer.readAsInteger(fieldValue2);
return value1.equals(new BigDecimal(value2).setScale(value1.scale()));
}
case LONG:
case DATETIME:
{
final long value2 = OVarIntSerializer.readAsLong(fieldValue2);
return value1.equals(new BigDecimal(value2));
}
case SHORT:
{
final short value2 = OVarIntSerializer.readAsShort(fieldValue2);
return value1.equals(new BigDecimal(value2));
}
case FLOAT:
{
final float value2 = Float.intBitsToFloat(ORecordSerializerBinaryV0.readInteger(fieldValue2));
return value1.equals(new BigDecimal(value2));
}
case DOUBLE:
{
final double value2 = Double.longBitsToDouble(ORecordSerializerBinaryV0.readLong(fieldValue2));
return value1.equals(new BigDecimal(value2));
}
case STRING:
{
return value1.toString().equals(ORecordSerializerBinaryV0.readString(fieldValue2));
}
case DECIMAL:
{
BigDecimal value2 = ODecimalSerializer.INSTANCE.deserialize(fieldValue2.bytes, fieldValue2.offset);
int maxScale = Math.max(value1.scale(), value2.scale());
value1 = value1.setScale(maxScale, BigDecimal.ROUND_DOWN);
value2 = value2.setScale(maxScale, BigDecimal.ROUND_DOWN);
return value1.equals(value2);
}
}
break;
}
}
} finally {
fieldValue1.offset = offset1;
fieldValue2.offset = offset2;
}
return false;
}
use of java.math.BigDecimal in project orientdb by orientechnologies.
the class ORecordSerializerNetworkV0 method serializeValue.
@SuppressWarnings("unchecked")
public int serializeValue(final BytesContainer bytes, Object value, final OType type, final OType linkedType) {
int pointer = 0;
switch(type) {
case INTEGER:
case LONG:
case SHORT:
pointer = OVarIntSerializer.write(bytes, ((Number) value).longValue());
break;
case STRING:
pointer = writeString(bytes, value.toString());
break;
case DOUBLE:
long dg = Double.doubleToLongBits((Double) value);
pointer = bytes.alloc(OLongSerializer.LONG_SIZE);
OLongSerializer.INSTANCE.serializeLiteral(dg, bytes.bytes, pointer);
break;
case FLOAT:
int fg = Float.floatToIntBits((Float) value);
pointer = bytes.alloc(OIntegerSerializer.INT_SIZE);
OIntegerSerializer.INSTANCE.serializeLiteral(fg, bytes.bytes, pointer);
break;
case BYTE:
pointer = bytes.alloc(1);
bytes.bytes[pointer] = (Byte) value;
break;
case BOOLEAN:
pointer = bytes.alloc(1);
bytes.bytes[pointer] = ((Boolean) value) ? (byte) 1 : (byte) 0;
break;
case DATETIME:
if (value instanceof Long) {
pointer = OVarIntSerializer.write(bytes, (Long) value);
} else
pointer = OVarIntSerializer.write(bytes, ((Date) value).getTime());
break;
case DATE:
long dateValue;
if (value instanceof Long) {
dateValue = (Long) value;
} else
dateValue = ((Date) value).getTime();
dateValue = convertDayToTimezone(ODateHelper.getDatabaseTimeZone(), TimeZone.getTimeZone("GMT"), dateValue);
pointer = OVarIntSerializer.write(bytes, dateValue / MILLISEC_PER_DAY);
break;
case EMBEDDED:
pointer = bytes.offset;
if (value instanceof ODocumentSerializable) {
ODocument cur = ((ODocumentSerializable) value).toDocument();
cur.field(ODocumentSerializable.CLASS_NAME, value.getClass().getName());
serialize(cur, bytes, false);
} else {
serialize((ODocument) value, bytes, false);
}
break;
case EMBEDDEDSET:
case EMBEDDEDLIST:
if (value.getClass().isArray())
pointer = writeEmbeddedCollection(bytes, Arrays.asList(OMultiValue.array(value)), linkedType);
else
pointer = writeEmbeddedCollection(bytes, (Collection<?>) value, linkedType);
break;
case DECIMAL:
BigDecimal decimalValue = (BigDecimal) value;
pointer = bytes.alloc(ODecimalSerializer.INSTANCE.getObjectSize(decimalValue));
ODecimalSerializer.INSTANCE.serialize(decimalValue, bytes.bytes, pointer);
break;
case BINARY:
pointer = writeBinary(bytes, (byte[]) (value));
break;
case LINKSET:
case LINKLIST:
Collection<OIdentifiable> ridCollection = (Collection<OIdentifiable>) value;
pointer = writeLinkCollection(bytes, ridCollection);
break;
case LINK:
if (!(value instanceof OIdentifiable))
throw new OValidationException("Value '" + value + "' is not a OIdentifiable");
pointer = writeOptimizedLink(bytes, (OIdentifiable) value);
break;
case LINKMAP:
pointer = writeLinkMap(bytes, (Map<Object, OIdentifiable>) value);
break;
case EMBEDDEDMAP:
pointer = writeEmbeddedMap(bytes, (Map<Object, Object>) value);
break;
case LINKBAG:
pointer = ((ORidBag) value).toStream(bytes);
break;
case CUSTOM:
if (!(value instanceof OSerializableStream))
value = new OSerializableWrapper((Serializable) value);
pointer = writeString(bytes, value.getClass().getName());
writeBinary(bytes, ((OSerializableStream) value).toStream());
break;
case TRANSIENT:
break;
case ANY:
break;
}
return pointer;
}
Aggregations