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 protected
NumberType(AbstractType.ComparisonType comparisonType)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description 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.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.boolean
isFloatingPoint()
Checks if this type support floating point numbers.abstract java.nio.ByteBuffer
mod(NumberType<?> leftType, java.nio.ByteBuffer left, NumberType<?> rightType, java.nio.ByteBuffer right)
Return the remainder.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.abstract java.nio.ByteBuffer
negate(java.nio.ByteBuffer input)
Negates the argument.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.protected java.math.BigDecimal
toBigDecimal(java.nio.ByteBuffer value)
Converts the specified value into aBigDecimal
.protected java.math.BigInteger
toBigInteger(java.nio.ByteBuffer value)
Converts the specified value into aBigInteger
if allowed.protected byte
toByte(java.nio.ByteBuffer value)
Converts the specified value into abyte
if allowed.protected double
toDouble(java.nio.ByteBuffer value)
Converts the specified value into adouble
if allowed.protected float
toFloat(java.nio.ByteBuffer value)
Converts the specified value into afloat
if allowed.protected int
toInt(java.nio.ByteBuffer value)
Converts the specified value into anint
if allowed.protected long
toLong(java.nio.ByteBuffer value)
Converts the specified value into along
if allowed.protected short
toShort(java.nio.ByteBuffer value)
Converts the specified value into ashort
if allowed.-
Methods inherited from class org.apache.cassandra.db.marshal.AbstractType
asCQL3Type, asCQLTypeStringList, checkComparable, compare, compare, compareCollectionMembers, compareCustom, compareForCQL, compose, compose, decompose, expandUserTypes, freeze, freezeNestedMulticellTypes, fromJSONObject, fromString, getComponents, getSerializer, getString, getString, getString, isCollection, isCompatibleWith, isCounter, isEmptyValueMeaningless, isFreezable, isFrozenCollection, isMultiCell, isReversed, isTuple, isUDT, isValueCompatibleWith, isValueCompatibleWithInternal, parseDefaultParameters, read, readArray, readBuffer, readBuffer, referencesDuration, referencesUserType, referencesUserType, skipValue, subTypes, testAssignment, testAssignment, toJSONString, toJSONString, toString, toString, 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:
true
if this type support floating point numbers,false
otherwise.
-
toBigInteger
protected java.math.BigInteger toBigInteger(java.nio.ByteBuffer value)
Converts the specified value into aBigInteger
if 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 abyte
if 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 ashort
if 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 anint
if 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 along
if 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 afloat
if 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 adouble
if 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
-
-