Package org.apache.cassandra.db.marshal
Class NumberType<T extends java.lang.Number>
- java.lang.Object
-
- org.apache.cassandra.db.marshal.AbstractType<T>
-
- org.apache.cassandra.db.marshal.NumberType<T>
-
- All Implemented Interfaces:
java.util.Comparator<java.nio.ByteBuffer>,AssignmentTestable
- Direct Known Subclasses:
ByteType,CounterColumnType,DecimalType,DoubleType,FloatType,Int32Type,IntegerType,LongType,ShortType
public abstract class NumberType<T extends java.lang.Number> extends AbstractType<T>
Base type for the numeric types.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.cassandra.db.marshal.AbstractType
AbstractType.ComparisonType
-
Nested classes/interfaces inherited from interface org.apache.cassandra.cql3.AssignmentTestable
AssignmentTestable.TestResult
-
-
Field Summary
-
Fields inherited from class org.apache.cassandra.db.marshal.AbstractType
comparatorSet, comparisonType, isByteOrderComparable, reverseComparator
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedNumberType(AbstractType.ComparisonType comparisonType)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract java.nio.ByteBufferadd(NumberType<?> leftType, java.nio.ByteBuffer left, NumberType<?> rightType, java.nio.ByteBuffer right)Adds the left argument to the right one.abstract java.nio.ByteBufferdivide(NumberType<?> leftType, java.nio.ByteBuffer left, NumberType<?> rightType, java.nio.ByteBuffer right)Divides the left argument by the right one.booleanisFloatingPoint()Checks if this type support floating point numbers.abstract java.nio.ByteBuffermod(NumberType<?> leftType, java.nio.ByteBuffer left, NumberType<?> rightType, java.nio.ByteBuffer right)Return the remainder.abstract java.nio.ByteBuffermultiply(NumberType<?> leftType, java.nio.ByteBuffer left, NumberType<?> rightType, java.nio.ByteBuffer right)Multiplies the left argument with the right one.abstract java.nio.ByteBuffernegate(java.nio.ByteBuffer input)Negates the argument.abstract java.nio.ByteBuffersubstract(NumberType<?> leftType, java.nio.ByteBuffer left, NumberType<?> rightType, java.nio.ByteBuffer right)Substracts the left argument from the right one.protected java.math.BigDecimaltoBigDecimal(java.nio.ByteBuffer value)Converts the specified value into aBigDecimal.protected java.math.BigIntegertoBigInteger(java.nio.ByteBuffer value)Converts the specified value into aBigIntegerif allowed.protected bytetoByte(java.nio.ByteBuffer value)Converts the specified value into abyteif allowed.protected doubletoDouble(java.nio.ByteBuffer value)Converts the specified value into adoubleif allowed.protected floattoFloat(java.nio.ByteBuffer value)Converts the specified value into afloatif allowed.protected inttoInt(java.nio.ByteBuffer value)Converts the specified value into anintif allowed.protected longtoLong(java.nio.ByteBuffer value)Converts the specified value into alongif allowed.protected shorttoShort(java.nio.ByteBuffer value)Converts the specified value into ashortif allowed.-
Methods inherited from class org.apache.cassandra.db.marshal.AbstractType
asCQL3Type, asCQLTypeStringList, checkComparable, compare, compare, compareCollectionMembers, compareCustom, compareForCQL, compose, compose, decompose, decomposeUntyped, expandUserTypes, freeze, freezeNestedMulticellTypes, fromJSONObject, fromString, getComponents, getSerializer, getString, getString, getString, isCollection, isCompatibleWith, isCounter, isEmptyValueMeaningless, isFreezable, isFrozenCollection, isMultiCell, isReversed, isSerializationCompatibleWith, isTuple, isUDT, isValueCompatibleWith, isValueCompatibleWithInternal, parseDefaultParameters, read, readArray, readBuffer, readBuffer, referencesDuration, referencesUserType, referencesUserType, skipValue, subTypes, testAssignment, testAssignment, toCQLString, toJSONString, toJSONString, toString, toString, udfType, unwrap, validate, validate, validateCellValue, validateCollectionMember, valueLengthIfFixed, withUpdatedUserType, writeValue, writeValue, writtenLength, writtenLength
-
-
-
-
Constructor Detail
-
NumberType
protected NumberType(AbstractType.ComparisonType comparisonType)
-
-
Method Detail
-
isFloatingPoint
public boolean isFloatingPoint()
Checks if this type support floating point numbers.- Returns:
trueif this type support floating point numbers,falseotherwise.
-
toBigInteger
protected java.math.BigInteger toBigInteger(java.nio.ByteBuffer value)
Converts the specified value into aBigIntegerif allowed.- Parameters:
value- the value to convert- Returns:
- the converted value
- Throws:
java.lang.UnsupportedOperationException- if the value cannot be converted without losing precision
-
toBigDecimal
protected java.math.BigDecimal toBigDecimal(java.nio.ByteBuffer value)
Converts the specified value into aBigDecimal.- Parameters:
value- the value to convert- Returns:
- the converted value
-
toByte
protected byte toByte(java.nio.ByteBuffer value)
Converts the specified value into abyteif allowed.- Parameters:
value- the value to convert- Returns:
- the converted value
- Throws:
java.lang.UnsupportedOperationException- if the value cannot be converted without losing precision
-
toShort
protected short toShort(java.nio.ByteBuffer value)
Converts the specified value into ashortif allowed.- Parameters:
value- the value to convert- Returns:
- the converted value
- Throws:
java.lang.UnsupportedOperationException- if the value cannot be converted without losing precision
-
toInt
protected int toInt(java.nio.ByteBuffer value)
Converts the specified value into anintif allowed.- Parameters:
value- the value to convert- Returns:
- the converted value
- Throws:
java.lang.UnsupportedOperationException- if the value cannot be converted without losing precision
-
toLong
protected long toLong(java.nio.ByteBuffer value)
Converts the specified value into alongif allowed.- Parameters:
value- the value to convert- Returns:
- the converted value
- Throws:
java.lang.UnsupportedOperationException- if the value cannot be converted without losing precision
-
toFloat
protected float toFloat(java.nio.ByteBuffer value)
Converts the specified value into afloatif allowed.- Parameters:
value- the value to convert- Returns:
- the converted value
- Throws:
java.lang.UnsupportedOperationException- if the value cannot be converted without losing precision
-
toDouble
protected double toDouble(java.nio.ByteBuffer value)
Converts the specified value into adoubleif allowed.- Parameters:
value- the value to convert- Returns:
- the converted value
- Throws:
java.lang.UnsupportedOperationException- if the value cannot be converted without losing precision
-
add
public abstract java.nio.ByteBuffer add(NumberType<?> leftType, java.nio.ByteBuffer left, NumberType<?> rightType, java.nio.ByteBuffer right)
Adds the left argument to the right one.- Parameters:
leftType- the type associated to the left argumentleft- the left argumentrightType- the type associated to the right argumentright- the right argument- Returns:
- the addition result
-
substract
public abstract java.nio.ByteBuffer substract(NumberType<?> leftType, java.nio.ByteBuffer left, NumberType<?> rightType, java.nio.ByteBuffer right)
Substracts the left argument from the right one.- Parameters:
leftType- the type associated to the left argumentleft- the left argumentrightType- the type associated to the right argumentright- the right argument- Returns:
- the substraction result
-
multiply
public abstract java.nio.ByteBuffer multiply(NumberType<?> leftType, java.nio.ByteBuffer left, NumberType<?> rightType, java.nio.ByteBuffer right)
Multiplies the left argument with the right one.- Parameters:
leftType- the type associated to the left argumentleft- the left argumentrightType- the type associated to the right argumentright- the right argument- Returns:
- the multiplication result
-
divide
public abstract java.nio.ByteBuffer divide(NumberType<?> leftType, java.nio.ByteBuffer left, NumberType<?> rightType, java.nio.ByteBuffer right)
Divides the left argument by the right one.- Parameters:
leftType- the type associated to the left argumentleft- the left argumentrightType- the type associated to the right argumentright- the right argument- Returns:
- the division result
-
mod
public abstract java.nio.ByteBuffer mod(NumberType<?> leftType, java.nio.ByteBuffer left, NumberType<?> rightType, java.nio.ByteBuffer right)
Return the remainder.- Parameters:
leftType- the type associated to the left argumentleft- the left argumentrightType- the type associated to the right argumentright- the right argument- Returns:
- the remainder
-
negate
public abstract java.nio.ByteBuffer negate(java.nio.ByteBuffer input)
Negates the argument.- Parameters:
input- the argument to negate- Returns:
- the negated argument
-
-