Example usage for org.apache.cassandra.db.marshal DoubleType instance

List of usage examples for org.apache.cassandra.db.marshal DoubleType instance

Introduction

In this page you can find the example usage for org.apache.cassandra.db.marshal DoubleType instance.

Prototype

DoubleType instance

To view the source code for org.apache.cassandra.db.marshal DoubleType instance.

Click Source Link

Usage

From source file:clojurewerkz.cassaforte.Codec.java

License:Apache License

private static AbstractType getCodecInternal(DataType type) {
    switch (type.getName()) {
    case ASCII://from  ww w  .  ja va2 s .  c  om
        return AsciiType.instance;
    case BIGINT:
        return LongType.instance;
    case BLOB:
        return BytesType.instance;
    case BOOLEAN:
        return BooleanType.instance;
    case COUNTER:
        return CounterColumnType.instance;
    case DECIMAL:
        return DecimalType.instance;
    case DOUBLE:
        return DoubleType.instance;
    case FLOAT:
        return FloatType.instance;
    case INET:
        return InetAddressType.instance;
    case INT:
        return Int32Type.instance;
    case TEXT:
        return UTF8Type.instance;
    case TIMESTAMP:
        return DateType.instance;
    case UUID:
        return UUIDType.instance;
    case VARCHAR:
        return UTF8Type.instance;
    case VARINT:
        return IntegerType.instance;
    case TIMEUUID:
        return TimeUUIDType.instance;
    case LIST:
        return ListType.getInstance(getCodec(type.getTypeArguments().get(0)));
    case SET:
        return SetType.getInstance(getCodec(type.getTypeArguments().get(0)));
    case MAP:
        return MapType.getInstance(getCodec(type.getTypeArguments().get(0)),
                getCodec(type.getTypeArguments().get(1)));
    default:
        throw new RuntimeException("Unknown type");
    }
}

From source file:com.datastax.driver.core.ArrayBackedRow.java

License:Apache License

public double getDouble(int i) {
    metadata.checkType(i, DataType.Name.DOUBLE);

    ByteBuffer value = data.get(i);
    if (value == null || value.remaining() == 0)
        return 0.0;

    return DoubleType.instance.compose(value);
}

From source file:com.datastax.driver.core.BoundStatement.java

License:Apache License

/**
 * Sets the {@code i}th value to the provided double.
 *
 * @param i the index of the variable to set.
 * @param v the value to set./*from w  ww  .java  2 s.co  m*/
 * @return this BoundStatement.
 *
 * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.preparedStatement().variables().size()}.
 * @throws InvalidTypeException if column {@code i} is not of type DOUBLE.
 */
public BoundStatement setDouble(int i, double v) {
    metadata().checkType(i, DataType.Name.DOUBLE);
    return setValue(i, DoubleType.instance.decompose(v));
}

From source file:com.datastax.driver.core.Codec.java

License:Apache License

private static AbstractType<?> getCodecInternal(DataType type) {
    switch (type.getName()) {
    case ASCII:/*w  ww.  ja va2 s  . c  o m*/
        return AsciiType.instance;
    case BIGINT:
        return LongType.instance;
    case BLOB:
        return BytesType.instance;
    case BOOLEAN:
        return BooleanType.instance;
    case COUNTER:
        return CounterColumnType.instance;
    case DECIMAL:
        return DecimalType.instance;
    case DOUBLE:
        return DoubleType.instance;
    case FLOAT:
        return FloatType.instance;
    case INET:
        return InetAddressType.instance;
    case INT:
        return Int32Type.instance;
    case TEXT:
        return UTF8Type.instance;
    case TIMESTAMP:
        return DateType.instance;
    case UUID:
        return UUIDType.instance;
    case VARCHAR:
        return UTF8Type.instance;
    case VARINT:
        return IntegerType.instance;
    case TIMEUUID:
        return TimeUUIDType.instance;
    case LIST:
        return ListType.getInstance(getCodec(type.getTypeArguments().get(0)));
    case SET:
        return SetType.getInstance(getCodec(type.getTypeArguments().get(0)));
    case MAP:
        return MapType.getInstance(getCodec(type.getTypeArguments().get(0)),
                getCodec(type.getTypeArguments().get(1)));
    // We don't interpret custom values in any way
    case CUSTOM:
        return BytesType.instance;
    default:
        throw new RuntimeException("Unknown type");
    }
}

From source file:com.datastax.driver.core.Row.java

License:Apache License

/**
 * Returns the {@code i}th value of this row as a double.
 *
 * @param i the index ({@code 0 <= i < size()}) of the column to retrieve.
 * @return the value of the {@code i}th column in this row as a double. If the
 * value is NULL, {@code 0.0} is returned.
 *
 * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}.
 * @throws InvalidTypeException if column {@code i} is not of type DOUBLE.
 *///from  w  w w .  j ava2 s . c  om
public double getDouble(int i) {
    metadata.checkType(i, DataType.Name.DOUBLE);

    ByteBuffer value = data.get(i);
    if (value == null || value.remaining() == 0)
        return 0.0;

    return DoubleType.instance.compose(value);
}

From source file:com.dse.pig.udfs.AbstractCassandraStorage.java

License:Apache License

/** convert object to ByteBuffer */
protected ByteBuffer objToBB(Object o) {
    if (o == null)
        return nullToBB();
    if (o instanceof java.lang.String)
        return ByteBuffer.wrap(new DataByteArray((String) o).get());
    if (o instanceof Integer)
        return Int32Type.instance.decompose((Integer) o);
    if (o instanceof Long)
        return LongType.instance.decompose((Long) o);
    if (o instanceof Float)
        return FloatType.instance.decompose((Float) o);
    if (o instanceof Double)
        return DoubleType.instance.decompose((Double) o);
    if (o instanceof java.util.UUID)
        //           return ByteBuffer.wrap(((UUID) o).toString().getBytes());
        return ByteBuffer.wrap(UUIDGen.decompose((java.util.UUID) o));
    if (o instanceof Tuple) {
        List<Object> objects = ((Tuple) o).getAll();
        //collections
        if (objects.size() > 0 && objects.get(0) instanceof String) {
            String collectionType = (String) objects.get(0);
            if ("set".equalsIgnoreCase(collectionType) || "list".equalsIgnoreCase(collectionType))
                return objToListOrSetBB(objects.subList(1, objects.size()));
            else if ("map".equalsIgnoreCase(collectionType))
                return objToMapBB(objects.subList(1, objects.size()));

        }//from   ww w .j a v  a  2s. com
        return objToCompositeBB(objects);
    }

    return ByteBuffer.wrap(((DataByteArray) o).get());
}

From source file:com.impetus.client.cassandra.common.CassandraUtilities.java

License:Apache License

/**
 * @param value//from ww  w . ja  v a  2 s.co  m
 * @param f
 * @return
 */
public static ByteBuffer toBytes(Object value, Class<?> clazz) {
    if (clazz.isAssignableFrom(String.class)) {
        return UTF8Type.instance.decompose((String) value);
    } else if (clazz.equals(int.class) || clazz.isAssignableFrom(Integer.class)) {
        return Int32Type.instance.decompose(Integer.parseInt(value.toString()));
    } else if (clazz.equals(long.class) || clazz.isAssignableFrom(Long.class)) {
        return LongType.instance.decompose(Long.parseLong(value.toString()));
    } else if (clazz.equals(boolean.class) || clazz.isAssignableFrom(Boolean.class)) {
        return BooleanType.instance.decompose(Boolean.valueOf(value.toString()));
    } else if (clazz.equals(double.class) || clazz.isAssignableFrom(Double.class)) {
        return DoubleType.instance.decompose(Double.valueOf(value.toString()));
    } else if (clazz.isAssignableFrom(java.util.UUID.class)) {
        return UUIDType.instance.decompose(UUID.fromString(value.toString()));
    } else if (clazz.equals(float.class) || clazz.isAssignableFrom(Float.class)) {
        return FloatType.instance.decompose(Float.valueOf(value.toString()));
    } else if (clazz.isAssignableFrom(Date.class)) {
        DateAccessor dateAccessor = new DateAccessor();
        return DateType.instance.decompose((Date) value);
    } else {
        if (value.getClass().isAssignableFrom(String.class)) {
            value = PropertyAccessorFactory.getPropertyAccessor(clazz).fromString(clazz, value.toString());
        }
        return BytesType.instance
                .decompose(ByteBuffer.wrap(PropertyAccessorFactory.getPropertyAccessor(clazz).toBytes(value)));
    }
}

From source file:com.stratio.cassandra.index.schema.ColumnMapperBigDecimal.java

License:Apache License

/**
 * Builds a new {@link ColumnMapperBigDecimal} using the specified max number of digits for the integer and decimal
 * parts./*  w w  w.j av  a  2  s . c o m*/
 *
 * @param integerDigits The max number of digits for the integer part. If {@code null}, the {@link
 *                      #DEFAULT_INTEGER_DIGITS} will be used.
 * @param decimalDigits The max number of digits for the decimal part. If {@code null}, the {@link
 *                      #DEFAULT_DECIMAL_DIGITS} will be used.
 */
@JsonCreator
public ColumnMapperBigDecimal(@JsonProperty("integer_digits") Integer integerDigits,
        @JsonProperty("decimal_digits") Integer decimalDigits) {
    super(new AbstractType<?>[] { AsciiType.instance, UTF8Type.instance, Int32Type.instance, LongType.instance,
            IntegerType.instance, FloatType.instance, DoubleType.instance, DecimalType.instance },
            new AbstractType[] {});

    // Setup integer part mapping
    if (integerDigits != null && integerDigits <= 0) {
        throw new IllegalArgumentException("Positive integer part digits required");
    }
    this.integerDigits = integerDigits == null ? DEFAULT_INTEGER_DIGITS : integerDigits;

    // Setup decimal part mapping
    if (decimalDigits != null && decimalDigits <= 0) {
        throw new IllegalArgumentException("Positive decimal part digits required");
    }
    this.decimalDigits = decimalDigits == null ? DEFAULT_DECIMAL_DIGITS : decimalDigits;

    int totalDigits = this.integerDigits + this.decimalDigits;
    BigDecimal divisor = BigDecimal.valueOf(10).pow(this.decimalDigits);
    BigDecimal dividend = BigDecimal.valueOf(10).pow(totalDigits).subtract(BigDecimal.valueOf(1));
    complement = dividend.divide(divisor);
}

From source file:com.stratio.cassandra.index.schema.ColumnMapperDate.java

License:Apache License

/**
 * Builds a new {@link ColumnMapperDate} using the specified pattern.
 *
 * @param pattern The {@link SimpleDateFormat} pattern to be used.
 *///w w  w  .  j a  v  a 2 s.  c  o m
@JsonCreator
public ColumnMapperDate(@JsonProperty("pattern") String pattern) {
    super(new AbstractType<?>[] { AsciiType.instance, UTF8Type.instance, Int32Type.instance, LongType.instance,
            IntegerType.instance, FloatType.instance, DoubleType.instance, DecimalType.instance,
            TimestampType.instance }, new AbstractType[] { LongType.instance, TimestampType.instance });
    this.pattern = pattern == null ? DEFAULT_PATTERN : pattern;
    concurrentDateFormat = new ThreadLocal<DateFormat>() {
        @Override
        protected DateFormat initialValue() {
            return new SimpleDateFormat(ColumnMapperDate.this.pattern);
        }
    };
}

From source file:com.stratio.cassandra.index.schema.ColumnMapperDouble.java

License:Apache License

/**
 * Builds a new {@link ColumnMapperDouble} using the specified boost.
 * @param boost The boost to be used.//from   w ww .j  av  a2  s. c o m
 */
@JsonCreator
public ColumnMapperDouble(@JsonProperty("boost") Float boost) {
    super(new AbstractType<?>[] { AsciiType.instance, UTF8Type.instance, Int32Type.instance, LongType.instance,
            IntegerType.instance, FloatType.instance, DoubleType.instance, DecimalType.instance },
            new AbstractType[] { DoubleType.instance });
    this.boost = boost == null ? DEFAULT_BOOST : boost;
}