/** * 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 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 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 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()); }