oracle.nosql.driver.values.IntegerValue Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nosqldriver Show documentation
Show all versions of nosqldriver Show documentation
Java examples for Oracle NoSQL Database
/*-
* Copyright (c) 2011, 2020 Oracle and/or its affiliates. All rights reserved.
*
* Licensed under the Universal Permissive License v 1.0 as shown at
* https://oss.oracle.com/licenses/upl/
*/
package oracle.nosql.driver.values;
import java.math.BigDecimal;
import oracle.nosql.driver.util.SizeOf;
/**
* A {@link FieldValue} instance representing an integer value.
*/
public class IntegerValue extends FieldValue {
private final int value;
/**
* Creates a new instance.
*
* @param value the value to use
*/
public IntegerValue(int value) {
super();
this.value = value;
}
@Override
public Type getType() {
return Type.INTEGER;
}
/**
* Returns the integer value of this object
*
* @return the integer value
*/
public int getValue() {
return value;
}
@Override
public int compareTo(FieldValue other) {
return Integer.compare(value, (other.getInt()));
}
/**
* Returns a long value for this object.
*
* @return the long value
*/
@Override
public long getLong() {
return value;
}
/**
* Casts this integer to a double, possibly with loss of information about
* magnitude, precision or sign.
*
* @return a double value
*/
@Override
public double castAsDouble() {
return value;
}
/**
* Returns a BigDecimal value for this object.
*
* @return the BigDecimal value
*/
@Override
public BigDecimal getNumber() {
return new BigDecimal(value);
}
@Override
public String toJson(JsonOptions options) {
return String.valueOf(value);
}
@Override
public boolean equals(Object other) {
if (other instanceof IntegerValue) {
return value == ((IntegerValue)other).value;
}
return false;
}
@Override
public int hashCode() {
return ((Integer) value).hashCode();
}
/**
* @hidden
*/
@Override
public long sizeof() {
return SizeOf.OBJECT_OVERHEAD + 4;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy