Class AInteger

All Implemented Interfaces:
IValidated, IWriteable, Comparable<ANumeric>
Direct Known Subclasses:
CVMBigInteger, CVMLong

public abstract class AInteger extends ANumeric
Abstract base class for CVM Integer values
  • Constructor Details

    • AInteger

      public AInteger()
  • Method Details

    • isCanonical

      public abstract boolean isCanonical()
      Description copied from class: ACell
      Returns 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).
      Overrides:
      isCanonical in class APrimitive
      Returns:
      true if the object is in canonical format, false otherwise
    • toCanonical

      public abstract AInteger toCanonical()
      Description copied from class: ACell
      Converts this Cell to its canonical version. Must return this Cell if already canonical, may be O(n) in size of value otherwise.
      Overrides:
      toCanonical in class APrimitive
      Returns:
      Canonical version of Cell
    • inc

      public abstract AInteger inc()
      Increments this Integer
      Returns:
      Incremented value
    • dec

      public abstract AInteger dec()
      Decrements this Integer
      Returns:
      Decremented 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
    • parse

      public static AInteger parse(String s)
      Parse an integer value as a canonical value
      Parameters:
      s - String to parse
      Returns:
      AInteger instance, or null if not convertible
    • parse

      public static AInteger parse(Object o)
      Parse a value as a canonical integer
      Parameters:
      o - Object to parse
      Returns:
      AInteger instance, or null if not convertible
    • byteLength

      public abstract long byteLength()
      Number of bytes in minimal representation of this Integer. Returns 0 if and only if the integer is zero.
      Returns:
      Number of bytes
    • add

      public ANumeric add(ANumeric b)
      Description copied from class: ANumeric
      Adds a second numeric value to this value
      Specified by:
      add in class ANumeric
      Parameters:
      b - Second number to add
      Returns:
      Result of addition
    • add

      public abstract AInteger add(AInteger a)
      Adds another integer to this integer
      Parameters:
      a - Integer value to add
      Returns:
      New integer
    • sub

      public ANumeric sub(ANumeric b)
      Description copied from class: ANumeric
      Subtracts a second numeric value to this value
      Specified by:
      sub in class ANumeric
      Parameters:
      b - Number to subtract
      Returns:
      Result of subtraction
    • sub

      public abstract AInteger sub(AInteger a)
      Subtracts another integer from this integer
      Parameters:
      a - Integer value to subtract
      Returns:
      New integer
    • big

      public abstract BigInteger big()
      Converts this integer to a Java BigInteger. WARNING: might be O(n)
      Returns:
      Java BigInteger
    • toInteger

      public AInteger toInteger()
      Description copied from class: ANumeric
      Converts this numeric value to the nearest integer
      Specified by:
      toInteger in class ANumeric
      Returns:
      Integer value
    • create

      public static AInteger create(BigInteger bi)
      Create a canonical CVM integer representation of the given Java BigInteger
      Parameters:
      bi - BigInteger value
      Returns:
      AInteger instance
    • create

      public static AInteger create(long value)
      Create a canonical CVM integer representation of the given Java Long
      Parameters:
      value - Long value
      Returns:
      AInteger instance
    • create

      public static AInteger create(Number value)
      Create a canonical CVM integer representation of the given Java Number
      Parameters:
      value - Long value
      Returns:
      AInteger instance
    • mod

      public abstract AInteger mod(AInteger base)
      Returns the modulus of this integer with a given integer base
      Parameters:
      base - Base of modulus operation
      Returns:
      Modulus result
    • div

      public abstract AInteger div(AInteger base)
      Divides this integer with a given denominator. Performs Euclidian division consistent with mod
      Parameters:
      base - Base of division
      Returns:
      Division result
    • quot

      public abstract AInteger quot(AInteger divisor)
      Divides this integer with a given denominator. Performs division consistent with rem
      Parameters:
      divisor - Base of division
      Returns:
      Division result
    • rem

      public abstract AInteger rem(AInteger divisor)
      Returns the remainder of dividing this integer with a given divisor
      Parameters:
      divisor - Base of division operation
      Returns:
      Modulus result