Package convex.core.data.prim
Class CVMLong
- All Implemented Interfaces:
IValidated,IWriteable,Comparable<ANumeric>
Class for CVM long values.
Longs are signed 64-bit integers, and are the primary fixed point integer type on the CVM.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final CVMLongstatic final CVMLongstatic final CVMLongstatic final CVMLongstatic final CVMLongFields inherited from class convex.core.data.ACell
cachedRef, EMPTY_ARRAY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabs()Gets the absolute value of this number.Adds another integer to this integerbig()Converts this integer to a Java BigInteger.longNumber of bytes in minimal representation of this Integer.intstatic CVMLongcreate(long value) Creates a CVMLong wrapping the given Java long value.static CVMLongCreates a CVMLong wrapping the given Java long value.dec()Decrements this IntegerDivides this integer with a given denominator.doubleintencode(byte[] bs, int pos) Writes this Cell's encoding to a byte array, including a tag byte which will be written first.intencodeRaw(byte[] bs, int pos) Writes this Cell's encoding to a byte array, excluding the tag byte.Gets the numeric value as a Long integer, or null if not a valid LongbooleanChecks for equality with another Cell.booleanintEstimate the encoded data size for this Cell.static CVMLongforByte(byte b) Gets the CVMLong representing an unsigned byte valuestatic final CVMLongforSignum(long value) Gets a CVMLong representing the signum of the given valuebytegetTag()Gets the tag byte for this cell.getType()Gets the most specific known runtime Type for this Cell.inc()Increments this IntegerbooleanReturns true if this Cell is in a canonical representation for message writing.booleanisZero()Check if this numeric value is equal to zerolongReturns the modulus of this integer with a given integer baseMultiplies a second numeric value with this valuenegate()Negates this numeric valueClass<?>Gets the numeric type that should be used as for calculationsstatic CVMLongParse an Object as a CVM Long, on a best efforts basisstatic CVMLongParse a String as a CVM Long.booleanprint(BlobBuilder bb, long limit) Prints this Object to a readable String Representation.Divides this integer with a given denominator.static CVMLongReturns the remainder of dividing this integer with a given divisorsignum()Gets the signum of this numerical value.Subtracts another integer from this integertoBlob()Converts this Integer value to Blob formConverts this Cell to its canonical version.toCVMString(long limit) Returns the CVM String representation of this Cell.toDouble()Casts to a CVM Double value.toLong()Casts to a CVM Long value.toString()Returns the Java String representation of this Cell.voidValidates the local structure and invariants of this cell.Methods inherited from class convex.core.data.prim.APrimitive
calcMemorySize, getRefCount, isCVMValue, isEmbeddedMethods inherited from class convex.core.data.ACell
announce, announce, attachMemorySize, attachRef, cachedEncoding, cachedHash, createAnnounced, createEncoding, createPersisted, createPersisted, createRef, equals, getCanonical, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getRef, getRef, hashCode, isCompletelyEncoded, mark, mark, updateRefs, validateMethods inherited from class convex.core.data.AObject
attachEncoding, print, print
-
Field Details
-
ZERO
-
ONE
-
MINUS_ONE
-
MAX_VALUE
-
MIN_VALUE
-
MAX_ENCODING_LENGTH
public static final int MAX_ENCODING_LENGTH- See Also:
-
-
Constructor Details
-
CVMLong
public CVMLong(long value)
-
-
Method Details
-
create
Creates a CVMLong wrapping the given Java long value. Always succeeds.- Parameters:
value- Java long- Returns:
- CVMLong instance.
-
create
Creates a CVMLong wrapping the given Java long value. Always succeeds.- Parameters:
value- Java long- Returns:
- CVMLong instance.
-
forByte
Gets the CVMLong representing an unsigned byte value- Parameters:
b- Byte to convert to CVMLong (will be interpreted as unsigned)- Returns:
- CVMLong value
-
getType
Description copied from class:ACellGets the most specific known runtime Type for this Cell. -
longValue
public long longValue()- Specified by:
longValuein classAPrimitive- Returns:
- Java long value representing this primitive CVM value
-
toLong
Description copied from class:ANumericCasts to a CVM Long value. Takes last 64 bits. -
toDouble
Description copied from class:ANumericCasts to a CVM Double value. -
estimatedEncodingSize
public int estimatedEncodingSize()Description copied from interface:IWriteableEstimate the encoded data size for this Cell. Used for quickly sizing buffers. Implementations should try to return a size that is highly likely to contain the entire object when encoded, including the tag byte. Should not traverse soft Refs, i.e. must be usable on arbitrary partial data structures- Returns:
- The estimated size for the binary representation of this object.
-
validateCell
Description copied from class:ACellValidates the local structure and invariants of this cell. Called by validate() super implementation. Should validate directly contained data, but should not validate all other structure of this cell. In particular, should not traverse potentially missing child Refs.- Specified by:
validateCellin classACell- Throws:
InvalidDataException- If the Cell is invalid
-
encode
public int encode(byte[] bs, int pos) Description copied from class:ACellWrites this Cell's encoding to a byte array, including a tag byte which will be written first. Cell must be canonical, or else an error may occur.- Specified by:
encodein interfaceIWriteable- Specified by:
encodein classACell- Parameters:
bs- A byte array to which to write the encodingpos- The offset into the byte array- Returns:
- New position after writing
-
encodeRaw
public int encodeRaw(byte[] bs, int pos) Description copied from class:ACellWrites this Cell's encoding to a byte array, excluding the tag byte. -
read
- Throws:
BadFormatException
-
print
Description copied from class:AObjectPrints this Object to a readable String Representation. SECURITY: Must halt and return false in O(1) time when limit of printing is exceeded otherwise DoS attacks may be possible. -
numericType
Description copied from class:ANumericGets the numeric type that should be used as for calculations- Specified by:
numericTypein classANumeric- Returns:
- Double.class or Long.class, or null if not a numeric type
-
doubleValue
public double doubleValue()- Specified by:
doubleValuein classANumeric- Returns:
- Java double value representing this primitive CVM value
-
parse
Parse an Object as a CVM Long, on a best efforts basis- Parameters:
o- String to parse- Returns:
- CVM Long value or null if parse failed
-
parse
Parse a String as a CVM Long. Throws an exception if the string is not valid- Parameters:
s- String to parse- Returns:
- CVM Long value, or null if not convertible
-
getTag
public byte getTag()Description copied from class:ACellGets the tag byte for this cell. The tag byte is always equal to the first byte of the Cell's canonical Encoding, and is sufficient to distinguish how to read the rest of the encoding. -
signum
Description copied from class:ANumericGets the signum of this numerical value. Will be -1, 0 or 1 for Longs, -1.0, 0.0 , 1.0 or ##NaN for Doubles. -
toCVMString
Description copied from class:ACellReturns the CVM String representation of this Cell. Normally, this is as printed, but may be different for some types. MUST return null in O(1) time if the length of the CVM String would exceed limit. The String representation is intended to be a easy-to-read textual representation of the Cell's data content.- Overrides:
toCVMStringin classACell- Parameters:
limit- Limit of CVM String length in UTF-8 bytes- Returns:
- CVM String, or null if limit exceeded
-
toString
Description copied from class:ACellReturns the Java String representation of this Cell. The String representation is intended to be a easy-to-read textual representation of the Cell's data content. -
equals
Description copied from class:ACellChecks for equality with another Cell. In general, Cells are considered equal if they have the same canonical representation, i.e. an identical encoding with the same hash value. Subclasses SHOULD override this if they have a more efficient equals implementation. MUST NOT require reads from Store. -
equals
-
forSignum
Gets a CVMLong representing the signum of the given value- Parameters:
value- Value to test for signum- Returns:
- 1, 0 or -1 as a CVM Long
-
isCanonical
public boolean isCanonical()Description copied from class:ACellReturns true if this Cell is in a canonical representation for message writing. Non-canonical objects may be used on a temporary internal basis, they must always be converted to canonical representations for external use (e.g. Encoding).- Specified by:
isCanonicalin classAInteger- Returns:
- true if the object is in canonical format, false otherwise
-
abs
Description copied from class:ANumericGets the absolute value of this number. May be ##NaN for Doubles. -
inc
Description copied from class:AIntegerIncrements this Integer -
dec
Description copied from class:AIntegerDecrements this Integer -
compareTo
-
ensureLong
Description copied from class:ANumericGets the numeric value as a Long integer, or null if not a valid Long- Specified by:
ensureLongin classANumeric- Returns:
- CVMLong value, or null
-
byteLength
public long byteLength()Description copied from class:AIntegerNumber of bytes in minimal representation of this Integer. Returns 0 if and only if the integer is zero.- Specified by:
byteLengthin classAInteger- Returns:
- Number of bytes
-
add
Description copied from class:AIntegerAdds another integer to this integer -
add
-
sub
Description copied from class:AIntegerSubtracts another integer from this integer -
sub
-
big
Description copied from class:AIntegerConverts this integer to a Java BigInteger. WARNING: might be O(n) -
negate
Description copied from class:ANumericNegates this numeric value -
multiply
Description copied from class:ANumericMultiplies a second numeric value with this value -
isZero
public boolean isZero()Description copied from class:ANumericCheck if this numeric value is equal to zero -
mod
Description copied from class:AIntegerReturns the modulus of this integer with a given integer base -
mod
-
div
Description copied from class:AIntegerDivides this integer with a given denominator. Performs Euclidian division consistent with mod -
div
-
rem
Description copied from class:AIntegerReturns the remainder of dividing this integer with a given divisor -
rem
-
quot
Description copied from class:AIntegerDivides this integer with a given denominator. Performs division consistent with rem -
quot
-
toCanonical
Description copied from class:ACellConverts this Cell to its canonical version. Must return this Cell if already canonical, may be O(n) in size of value otherwise.- Specified by:
toCanonicalin classAInteger- Returns:
- Canonical version of Cell
-
toBlob
Description copied from class:AIntegerConverts this Integer value to Blob form
-