/** * 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(); }
/** * 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); } }
public ByteBuffer fromString(String source) throws MarshalException { ByteBuffer parsed = UUIDType.parse(source); if (parsed == null) throw new MarshalException(String.format("Unknown timeuuid representation: %s", source)); if (parsed.remaining() == 16 && UUIDType.version(parsed) != 1) throw new MarshalException("TimeUUID supports only version 1 UUIDs"); return parsed; }
@Override public Term fromJSONObject(Object parsed) throws MarshalException { try { return new Constants.Value(fromString((String) parsed)); } catch (ClassCastException exc) { throw new MarshalException(String.format( "Expected a string representation of a uuid, but got a %s: %s", parsed.getClass().getSimpleName(), parsed)); } }
@Override public ByteBuffer fromString(String source) throws MarshalException { // Return an empty ByteBuffer for an empty string. ByteBuffer parsed = parse(source); if (parsed != null) return parsed; throw new MarshalException(String.format("Unable to make UUID from '%s'", source)); }
public ByteBuffer fromString(String source) throws MarshalException { ByteBuffer parsed = UUIDType.parse(source); if (parsed == null) throw new MarshalException(String.format("Unknown timeuuid representation: %s", source)); if (parsed.remaining() == 16 && UUIDType.version(parsed) != 1) throw new MarshalException("TimeUUID supports only version 1 UUIDs"); return parsed; }
@Override public Term fromJSONObject(Object parsed) throws MarshalException { try { return new Constants.Value(fromString((String) parsed)); } catch (ClassCastException exc) { throw new MarshalException(String.format( "Expected a string representation of a uuid, but got a %s: %s", parsed.getClass().getSimpleName(), parsed)); } }
@Override public ByteBuffer fromString(String source) throws MarshalException { // Return an empty ByteBuffer for an empty string. ByteBuffer parsed = parse(source); if (parsed != null) return parsed; throw new MarshalException(String.format("Unable to make UUID from '%s'", source)); }
return UUIDType.instance.decompose(UUID.fromString(value.toString()));
public ByteBuffer fromString(String source) throws MarshalException { ByteBuffer parsed = UUIDType.parse(source); if (parsed == null) throw new MarshalException(String.format("Unknown timeuuid representation: %s", source)); if (parsed.remaining() == 16 && UUIDType.version(parsed) != 1) throw new MarshalException("TimeUUID supports only version 1 UUIDs"); return parsed; }
public UUID getUUID(String column) { return UUIDType.instance.compose(data.get(column)); }
@Override public Term fromJSONObject(Object parsed) throws MarshalException { try { return new Constants.Value(fromString((String) parsed)); } catch (ClassCastException exc) { throw new MarshalException(String.format( "Expected a string representation of a uuid, but got a %s: %s", parsed.getClass().getSimpleName(), parsed)); } }
@Override public ByteBuffer fromString(String source) throws MarshalException { // Return an empty ByteBuffer for an empty string. ByteBuffer parsed = parse(source); if (parsed != null) return parsed; throw new MarshalException(String.format("Unable to make UUID from '%s'", source)); }
private static byte[] compose(Object value, Class clazz) { return UUIDType.instance.decompose((UUID) value).array(); }
public ByteBuffer fromString(String source) throws MarshalException { ByteBuffer parsed = UUIDType.parse(source); if (parsed == null) throw new MarshalException(String.format("Unknown timeuuid representation: %s", source)); if (parsed.remaining() == 16 && UUIDType.version(parsed) != 1) throw new MarshalException("TimeUUID supports only version 1 UUIDs"); return parsed; }
private static Object decompose(Object value, Class clazz) { ByteBuffer buf = ByteBuffer.wrap((byte[]) value, 0, ((byte[]) value).length); return UUIDType.instance.compose(buf); } }
@Override public Term fromJSONObject(Object parsed) throws MarshalException { try { return new Constants.Value(fromString((String) parsed)); } catch (ClassCastException exc) { throw new MarshalException(String.format( "Expected a string representation of a uuid, but got a %s: %s", parsed.getClass().getSimpleName(), parsed)); } }
@Override public ByteBuffer fromString(String source) throws MarshalException { // Return an empty ByteBuffer for an empty string. ByteBuffer parsed = parse(source); if (parsed != null) return parsed; throw new MarshalException(String.format("Unable to make UUID from '%s'", source)); }
/** * Returns the {@link String} representation of the specified {@link UUID}. The returned value has the same * collation as {@link UUIDType}. * * @param uuid the {@link UUID} to be serialized * @return the {@link String} representation of the specified {@link UUID} */ static String serialize(UUID uuid) { StringBuilder sb = new StringBuilder(); // Get UUID type version ByteBuffer bb = UUIDType.instance.decompose(uuid); int version = (bb.get(bb.position() + 6) >> 4) & 0x0f; // Add version at the beginning sb.append(ByteBufferUtils.toHex((byte) version)); // If it's a time based UUID, add the UNIX timestamp if (version == 1) { long timestamp = uuid.timestamp(); String timestampHex = ByteBufferUtils.toHex(Longs.toByteArray(timestamp)); sb.append(timestampHex); } // Add the UUID itself sb.append(ByteBufferUtils.toHex(bb)); return sb.toString(); }
public UUID getUUID(String column) { return UUIDType.instance.compose(data.get(column)); }