Class CVMLong

All Implemented Interfaces:
INumeric, IValidated, IWriteable

public final class CVMLong extends APrimitive implements INumeric
Class for CVM long values. Longs are signed 64-bit integers, and are the primary fixed point integer type on the CVM.
  • Field Details

    • ZERO

      public static final CVMLong ZERO
    • ONE

      public static final CVMLong ONE
    • MINUS_ONE

      public static final CVMLong MINUS_ONE
    • MAX_VALUE

      public static final CVMLong MAX_VALUE
    • MIN_VALUE

      public static final CVMLong MIN_VALUE
    • MAX_ENCODING_LENGTH

      public static final int MAX_ENCODING_LENGTH
      See Also:
      Constant Field Values
  • Constructor Details

    • CVMLong

      public CVMLong(long value)
  • Method Details

    • create

      public static CVMLong create(long value)
    • getType

      public AType getType()
      Description copied from class: ACell
      Gets the most specific known runtime Type for this Cell.
      Overrides:
      getType in class ACell
      Returns:
      The Type of this Call
    • longValue

      public long longValue()
      Specified by:
      longValue in class APrimitive
      Returns:
      long value representing primitive
    • toLong

      public CVMLong toLong()
      Specified by:
      toLong in interface INumeric
    • toDouble

      public CVMDouble toDouble()
      Specified by:
      toDouble in interface INumeric
    • estimatedEncodingSize

      public int estimatedEncodingSize()
      Description copied from interface: IWriteable
      Estimate the encoded data size for this Cell. Used for quickly sizing buffers. Implementations should try to return a size that is likely to contain the entire object when represented in binary format, including the tag byte.
      Specified by:
      estimatedEncodingSize in interface IWriteable
      Returns:
      The estimated size for the binary representation of this object.
    • validateCell

      public void validateCell() throws InvalidDataException
      Description copied from class: ACell
      Validates 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:
      validateCell in class ACell
      Throws:
      InvalidDataException - If the Cell is invalid
    • encode

      public int encode(byte[] bs, int pos)
      Description copied from class: ACell
      Writes 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:
      encode in interface IWriteable
      Specified by:
      encode in class ACell
      Parameters:
      bs - A byte array to which to write the encoding
      pos - The offset into the byte array
      Returns:
      New position after writing
    • encodeRaw

      public int encodeRaw(byte[] bs, int pos)
      Description copied from class: ACell
      Writes this Cell's encoding to a byte array, excluding the tag byte.
      Specified by:
      encodeRaw in class ACell
      Parameters:
      bs - A byte array to which to write the encoding
      pos - The offset into the byte array
      Returns:
      New position after writing
    • print

      public boolean print(BlobBuilder bb, long limit)
      Description copied from class: AObject
      Prints this Object to a readable String Representation
      Specified by:
      print in class AObject
      Parameters:
      bb - StringBuilder to append to
      limit - Limit of printing in string bytes
      Returns:
      True if fully printed, false otherwise
    • numericType

      public Class<?> numericType()
      Description copied from interface: INumeric
      Gets the numeric type that should be used as for calculations
      Specified by:
      numericType in interface INumeric
      Returns:
      Double.class or Long.class, or null if not a numeric type
    • doubleValue

      public double doubleValue()
      Specified by:
      doubleValue in interface INumeric
      Specified by:
      doubleValue in class APrimitive
      Returns:
      double value representing primitive
    • parse

      public static CVMLong parse(String s)
      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
    • getTag

      public byte getTag()
      Description copied from class: ACell
      Gets the tag byte for this cell. The tag byte is always written as the first byte of the Cell's Encoding
      Specified by:
      getTag in class ACell
      Returns:
      Tag byte for this Cell
    • signum

      public CVMLong signum()
      Description copied from interface: INumeric
      Gets the signum of this numerical value. Will be -1, 0 or 1 for Longs, -1.0, 0.0 , 1.0 or ##NaN for Doubles.
      Specified by:
      signum in interface INumeric
      Returns:
      Signum of the numeric value
    • toStandardNumber

      public INumeric toStandardNumber()
      Specified by:
      toStandardNumber in interface INumeric
    • toCVMString

      public AString toCVMString(long limit)
      Description copied from class: ACell
      Returns 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:
      toCVMString in class ACell
      Parameters:
      limit - Limit of CVM String length in UTF-8 bytes
      Returns:
      CVM String, or null if limit exceeded by too much
    • toString

      public String toString()
      Description copied from class: ACell
      Returns 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.
      Overrides:
      toString in class ACell