/** * Get or create byte value for the given byte. * * @param i the byte * @return the value */ public static ValueByte get(byte i) { return (ValueByte) Value.cache(new ValueByte(i)); }
/** * Get or create a date value for the given date. * * @param dateValue the date value * @param nanos the nanoseconds * @return the value */ public static ValueTimestamp fromDateValueAndNanos(long dateValue, long nanos) { return (ValueTimestamp) Value.cache(new ValueTimestamp(dateValue, nanos)); }
/** * Get or create a long value for the given long. * * @param i the long * @return the value */ public static ValueLong get(long i) { if (i >= 0 && i < STATIC_SIZE) { return STATIC_CACHE[(int) i]; } return (ValueLong) Value.cache(new ValueLong(i)); }
/** * Get or create a date value for the given date. * * @param dateValue the date value * @return the value */ public static ValueDate fromDateValue(long dateValue) { return (ValueDate) Value.cache(new ValueDate(dateValue)); }
/** * Get or create a UUID for the given high and low order values. * * @param high the most significant bits * @param low the least significant bits * @return the UUID */ public static ValueUuid get(long high, long low) { return (ValueUuid) Value.cache(new ValueUuid(high, low)); }
/** * Get or create a time value. * * @param nanos the nanoseconds * @return the value */ public static ValueTime fromNanos(long nanos) { return (ValueTime) Value.cache(new ValueTime(nanos)); }
/** * Get or create a short value for the given short. * * @param i the short * @return the value */ public static ValueShort get(short i) { return (ValueShort) Value.cache(new ValueShort(i)); }
/** * Get or create big decimal value for the given big decimal. * * @param dec the bit decimal * @return the value */ public static ValueDecimal get(BigDecimal dec) { if (BigDecimal.ZERO.equals(dec)) { return ZERO; } else if (BigDecimal.ONE.equals(dec)) { return ONE; } return (ValueDecimal) Value.cache(new ValueDecimal(dec)); }
/** * Get or create a bytes value for the given byte array. * Do not clone the date. * * @param b the byte array * @return the value */ public static ValueBytes getNoCopy(byte[] b) { if (b.length == 0) { return EMPTY; } ValueBytes obj = new ValueBytes(b); if (b.length > SysProperties.OBJECT_CACHE_MAX_PER_ELEMENT_SIZE) { return obj; } return (ValueBytes) Value.cache(obj); }
/** * Get or create float value for the given float. * * @param d the float * @return the value */ public static ValueFloat get(float d) { if (d == 1.0F) { return ONE; } else if (d == 0.0F) { // unfortunately, -0.0 == 0.0, but we don't want to return // 0.0 in this case if (Float.floatToIntBits(d) == ZERO_BITS) { return ZERO; } } return (ValueFloat) Value.cache(new ValueFloat(d)); }
/** * Get or create double value for the given double. * * @param d the double * @return the value */ public static ValueDouble get(double d) { if (d == 1.0) { return ONE; } else if (d == 0.0) { // unfortunately, -0.0 == 0.0, but we don't want to return // 0.0 in this case if (Double.doubleToLongBits(d) == ZERO_BITS) { return ZERO; } } else if (Double.isNaN(d)) { return NAN; } return (ValueDouble) Value.cache(new ValueDouble(d)); }
/** * Get or create a string value for the given string. * * @param s the string * @param treatEmptyStringsAsNull whether or not to treat empty strings as * NULL * @return the value */ public static Value get(String s, boolean treatEmptyStringsAsNull) { if (s.isEmpty()) { return treatEmptyStringsAsNull ? ValueNull.INSTANCE : EMPTY; } ValueString obj = new ValueString(StringUtils.cache(s)); if (s.length() > SysProperties.OBJECT_CACHE_MAX_PER_ELEMENT_SIZE) { return obj; } return Value.cache(obj); // this saves memory, but is really slow // return new ValueString(s.intern()); }
/** * Get or create a case insensitive string value for the given string. * The value will have the same case as the passed string. * * @param s the string * @return the value */ public static ValueStringIgnoreCase get(String s) { if (s.length() == 0) { return EMPTY; } ValueStringIgnoreCase obj = new ValueStringIgnoreCase(StringUtils.cache(s)); if (s.length() > SysProperties.OBJECT_CACHE_MAX_PER_ELEMENT_SIZE) { return obj; } ValueStringIgnoreCase cache = (ValueStringIgnoreCase) Value.cache(obj); // the cached object could have the wrong case // (it would still be 'equal', but we don't like to store it) if (cache.value.equals(s)) { return cache; } return obj; }
/** * Get or create a string value for the given string. * * @param s the string * @return the value */ public static ValueString get(String s) { if (s.length() == 0) { return EMPTY; } ValueString obj = new ValueString(StringUtils.cache(s)); if (s.length() > SysProperties.OBJECT_CACHE_MAX_PER_ELEMENT_SIZE) { return obj; } return (ValueString) Value.cache(obj); // this saves memory, but is really slow // return new ValueString(s.intern()); }
/** * Get or create a fixed length string value for the given string. * Spaces at the end of the string will be removed. * * @param s the string * @return the value */ public static ValueStringFixed get(String s) { s = trimRight(s); if (s.length() == 0) { return EMPTY; } ValueStringFixed obj = new ValueStringFixed(StringUtils.cache(s)); if (s.length() > SysProperties.OBJECT_CACHE_MAX_PER_ELEMENT_SIZE) { return obj; } return (ValueStringFixed) Value.cache(obj); }
/** * Get or create a UUID for the given text representation. * * @param s the text representation of the UUID * @return the UUID */ public static ValueUuid get(String s) { long low = 0, high = 0; for (int i = 0, j = 0, length = s.length(); i < length; i++) { char c = s.charAt(i); if (c >= '0' && c <= '9') { low = (low << 4) | (c - '0'); } else if (c >= 'a' && c <= 'f') { low = (low << 4) | (c - 'a' + 0xa); } else if (c == '-') { continue; } else if (c >= 'A' && c <= 'F') { low = (low << 4) | (c - 'A' + 0xa); } else if (c <= ' ') { continue; } else { throw DbException.get(ErrorCode.DATA_CONVERSION_ERROR_1, s); } if (j++ == 15) { high = low; low = 0; } } return (ValueUuid) Value.cache(new ValueUuid(high, low)); }
/** * Get or create a java object value for the given byte array. * Do not clone the data. * * @param javaObject the object * @param b the byte array * @return the value */ public static ValueJavaObject getNoCopy(Object javaObject, byte[] b) { if (b != null && b.length == 0) { return EMPTY; } ValueJavaObject obj; if (SysProperties.SERIALIZE_JAVA_OBJECT) { if (b == null) { b = Utils.serialize(javaObject); } obj = new ValueJavaObject(b); } else { obj = new NotSerialized(javaObject, b); } if (b == null || b.length > SysProperties.OBJECT_CACHE_MAX_PER_ELEMENT_SIZE) { return obj; } return (ValueJavaObject) Value.cache(obj); }
/** * Get or create a UUID for the given 16 bytes. * * @param binary the byte array (must be at least 16 bytes long) * @return the UUID */ public static ValueUuid get(byte[] binary) { if (binary.length < 16) { return get(StringUtils.convertBytesToHex(binary)); } long high = Utils.readLong(binary, 0); long low = Utils.readLong(binary, 8); return (ValueUuid) Value.cache(new ValueUuid(high, low)); }