java.lang.Object
org.apache.hadoop.yarn.server.timelineservice.storage.common.LongConverter
All Implemented Interfaces:
Serializable, Comparator<Number>, NumericValueConverter, ValueConverter

public final class LongConverter extends Object implements NumericValueConverter, Serializable
Encodes a value by interpreting it as a Long and converting it to bytes and decodes a set of bytes as a Long.
See Also:
  • Constructor Details

    • LongConverter

      public LongConverter()
  • Method Details

    • encodeValue

      public byte[] encodeValue(Object value) throws IOException
      Description copied from interface: ValueConverter
      Encode an object as a byte array depending on the converter implementation.
      Specified by:
      encodeValue in interface ValueConverter
      Parameters:
      value - Value to be encoded.
      Returns:
      a byte array
      Throws:
      IOException - if any problem is encountered while encoding.
    • decodeValue

      public Object decodeValue(byte[] bytes) throws IOException
      Description copied from interface: ValueConverter
      Decode a byte array and convert it into an object depending on the converter implementation.
      Specified by:
      decodeValue in interface ValueConverter
      Parameters:
      bytes - Byte array to be decoded.
      Returns:
      an object
      Throws:
      IOException - if any problem is encountered while decoding.
    • compare

      public int compare(Number num1, Number num2)
      Compares two numbers as longs. If either number is null, it will be taken as 0.
      Specified by:
      compare in interface Comparator<Number>
      Parameters:
      num1 - the first Long to compare.
      num2 - the second Long to compare.
      Returns:
      -1 if num1 is less than num2, 0 if num1 is equal to num2 and 1 if num1 is greater than num2.
    • add

      public Number add(Number num1, Number num2, Number... numbers)
      Description copied from interface: NumericValueConverter
      Adds two or more numbers. If either of the numbers are null, it is taken as 0.
      Specified by:
      add in interface NumericValueConverter
      Parameters:
      num1 - the first number to add.
      num2 - the second number to add.
      numbers - Rest of the numbers to be added.
      Returns:
      result after adding up the numbers.
    • invertLong

      public static long invertLong(long key)
      Converts a timestamp into it's inverse timestamp to be used in (row) keys where we want to have the most recent timestamp in the top of the table (scans start at the most recent timestamp first).
      Parameters:
      key - value to be inverted so that the latest version will be first in a scan.
      Returns:
      inverted long