@Test public void timeUUIDComparison() { TimeUUIDType ti = TimeUUIDType.instance; UUID zu = UUID.fromString(z); UUID vu = UUID.fromString(v); ByteBuffer zb = ti.decompose(zu); ByteBuffer vb = ti.decompose(vu); assertEquals(-1, ti.compare(zb, vb)); assertEquals(1, zu.compareTo(vu)); assertEquals(1, ti.compare(vb, zb)); assertEquals(-1, vu.compareTo(zu)); } }
/** * Compose. * * @param value * the value * @param clazz * the clazz * @return the byte[] */ private static byte[] compose(Object value, Class clazz) { return BooleanType.instance.decompose((Boolean) value).array(); }
/** * Compose. * * @param value * the value * @param clazz * the clazz * @return the byte[] */ private static byte[] compose(Object value, Class clazz) { return UUIDType.instance.decompose((UUID) value).array(); }
return UTF8Type.instance.decompose((String) value); return Int32Type.instance.decompose(Integer.parseInt(value.toString())); return LongType.instance.decompose(Long.parseLong(value.toString())); return BooleanType.instance.decompose(Boolean.valueOf(value.toString())); return DoubleType.instance.decompose(Double.valueOf(value.toString())); return UUIDType.instance.decompose(UUID.fromString(value.toString())); return FloatType.instance.decompose(Float.valueOf(value.toString())); return DateType.instance.decompose((Date) value); return BytesType.instance.decompose(ByteBuffer.wrap(PropertyAccessorFactory.getPropertyAccessor(clazz) .toBytes(value)));
private static CFMetaData compositeCFMD(String ksName, String cfName, AbstractType<?>... types) { return new CFMetaData(ksName, cfName, ColumnFamilyType.Standard, CompositeType.getInstance(Arrays.asList(types)), null).rebuild(); }
private static CFMetaData dynamicCompositeCFMD(String ksName, String cfName) { return new CFMetaData(ksName, cfName, ColumnFamilyType.Standard, DynamicCompositeType.getInstance(alias), null).rebuild(); }
/** * Compose. * * @param value * the value * @param clazz * the clazz * @return the byte[] */ private static byte[] compose(Object value, Class clazz) { return DecimalType.instance.decompose((BigDecimal) value).array(); }
/** * Compose. * * @param value * the value * @param clazz * the clazz * @return the byte[] */ private static byte[] compose(Object value, Class clazz) { return IntegerType.instance.decompose((BigInteger) value).array(); }
/** * Decompose. * * @param value * the value * @param clazz * the clazz * @return the object */ private static Object decompose(Object value, Class clazz) { ByteBuffer buf = ByteBuffer.wrap((byte[]) value, 0, ((byte[]) value).length); return DecimalType.instance.compose(buf); } }
/** * Decompose. * * @param value * the value * @param clazz * the clazz * @return the object */ private static Object decompose(Object value, Class clazz) { ByteBuffer buf = ByteBuffer.wrap((byte[]) value, 0, ((byte[]) value).length); return BooleanType.instance.compose(buf); } }
/** * Decompose. * * @param value * the value * @param clazz * the clazz * @return the object */ private static Object decompose(Object value, Class clazz) { ByteBuffer buf = ByteBuffer.wrap((byte[]) value, 0, ((byte[]) value).length); return UUIDType.instance.compose(buf); } }
/** * Decompose. * * @param value * the value * @param clazz * the clazz * @return the object */ private static Object decompose(Object value, Class clazz) { ByteBuffer buf = ByteBuffer.wrap((byte[]) value, 0, ((byte[]) value).length); return AsciiType.instance.compose(buf); } }
/** * Compose. * * @param value * the value * @param clazz * the clazz * @return the byte[] */ private static byte[] compose(Object value, Class clazz) { return AsciiType.instance.decompose((String) value).array(); }
/** * Compose. * * @param value * the value * @param clazz * the clazz * @return the byte[] */ private static byte[] compose(Object value, Class clazz) { return DateType.instance.decompose((Date) value).array(); }
/** * Compose. * * @param value * the value * @param clazz * the clazz * @return the byte[] */ private static byte[] compose(Object value, Class clazz) { return CounterColumnType.instance.decompose((Long) value).array(); }
/** * Decompose. * * @param value * the value * @param clazz * the clazz * @return the object */ private static Object decompose(Object value, Class clazz) { ByteBuffer buf = ByteBuffer.wrap((byte[]) value, 0, ((byte[]) value).length); return DateType.instance.compose(buf); } }
/** * Decompose. * * @param value * the value * @param clazz * the clazz * @return the object */ private static Object decompose(Object value, Class clazz) { ByteBuffer buf = ByteBuffer.wrap((byte[]) value, 0, ((byte[]) value).length); return CounterColumnType.instance.compose(buf); } }
/** * Decompose. * * @param value * the value * @param clazz * the clazz * @return the object */ private static Object decompose(Object value, Class clazz) { ByteBuffer buf = ByteBuffer.wrap((byte[]) value, 0, ((byte[]) value).length); return IntegerType.instance.compose(buf); } }
@Test public void test() throws Exception { Assert.assertEquals(str, s.fromByteBuffer(s.toByteBuffer(str))); if (str != null) { Assert .assertEquals(str, ByteBufferUtil.string(ByteBufferUtil.bytes(str))); } if (str != null) { UTF8Type.instance.validate(s.toByteBuffer(str)); } } }
@SuppressWarnings("rawtypes") public DynamicCompositeType getDefaultDynamicComparator() { //Well if ? makes you happy then :) Generics FTWhatever Map<Byte, AbstractType<?>> aliases = new HashMap<Byte, AbstractType<?>>(); aliases.put((byte) 'a', AsciiType.instance); aliases.put((byte) 'b', BytesType.instance); aliases.put((byte) 'i', IntegerType.instance); aliases.put((byte) 'x', LexicalUUIDType.instance); aliases.put((byte) 'l', LongType.instance); aliases.put((byte) 't', TimeUUIDType.instance); aliases.put((byte) 's', UTF8Type.instance); aliases.put((byte) 'u', UUIDType.instance); DynamicCompositeType comparator = DynamicCompositeType.getInstance(aliases); return comparator; }