Example usage for org.apache.cassandra.utils UUIDGen unixTimestamp

List of usage examples for org.apache.cassandra.utils UUIDGen unixTimestamp

Introduction

In this page you can find the example usage for org.apache.cassandra.utils UUIDGen unixTimestamp.

Prototype

public static long unixTimestamp(UUID uuid) 

Source Link

Usage

From source file:com.stratio.cassandra.lucene.util.DateParser.java

License:Apache License

/**
 * Returns the {@link Date} represented by the specified {@link Object}, or {@code null} if the specified  {@link
 * Object} is {@code null}.// w  ww .  j a va  2s. c  om
 *
 * @param value the {@link Object} to be parsed
 * @param <K> the type of the value to be parsed
 * @return the parsed {@link Date}
 */
public final <K> Date parse(K value) {

    if (value == null) {
        return null;
    }

    try {
        if (value instanceof Date) {
            Date date = (Date) value;
            if (date.getTime() == Long.MAX_VALUE || date.getTime() == Long.MIN_VALUE) {
                return date;
            } else {
                String string = formatter.get().format(date);
                return formatter.get().parse(string);
            }
        } else if (value instanceof UUID) {
            long timestamp = UUIDGen.unixTimestamp((UUID) value);
            Date date = new Date(timestamp);
            return formatter.get().parse(formatter.get().format(date));
        } else if (Number.class.isAssignableFrom(value.getClass())) {
            Long number = ((Number) value).longValue();
            return formatter.get().parse(number.toString());
        } else {
            return formatter.get().parse(value.toString());
        }
    } catch (Exception e) {
        throw new IndexException(e, "Error parsing {} with value '{}' using date pattern {}",
                value.getClass().getSimpleName(), value, pattern);
    }
}