Class TupleHelpers

java.lang.Object
com.apple.foundationdb.tuple.TupleHelpers

@API(UNSTABLE) public class TupleHelpers extends Object
Helper methods for working with Tuples.
  • Field Details

    • EMPTY

      @Nonnull public static final Tuple EMPTY
  • Method Details

    • set

      @Nonnull public static Tuple set(@Nonnull Tuple src, int index, Object value)
    • subTuple

      @Nonnull public static Tuple subTuple(@Nonnull Tuple src, int start, int end)
    • compare

      @API(UNSTABLE) public static int compare(@Nonnull Tuple t1, @Nonnull Tuple t2)
      Compare two tuples lexicographically, that is, the same way they would sort when used as keys. Note that this is currently WAY more efficient than calling Tuple.equals(java.lang.Object), and slightly more efficient than calling Tuple.compareTo(com.apple.foundationdb.tuple.Tuple).
      Parameters:
      t1 - the first Tuple to compare
      t2 - the second Tuple to compare
      Returns:
      0 if t1 and t2 are equal a value less than 0 if t1 would sort before t2 a value greater than 0 if t1 would sort after t2
    • equals

      public static boolean equals(@Nullable Tuple t1, @Nullable Tuple t2)
      Determine if two Tuples have the same contents. Unfortunately, the implementation of Tuple.equals() serializes both Tuples to byte arrays, so it is fairly expensive. This method avoids serializing either Tuple, and it also adds a short-circuit to return early if the two Tuples are pointer-equal.
      Parameters:
      t1 - the first Tuple to compare
      t2 - the second Tuple to compare
      Returns:
      true if the two Tuples would serialize to the same array and false otherwise
    • negate

      public static Number negate(@Nonnull Number number)
      Negate a number used as an element of a Tuple.
      Parameters:
      number - the number to be negated
      Returns:
      a negated number suitable for use in a new Tuple
    • packedSizeAsTupleItem

      public static int packedSizeAsTupleItem(Object item)
      Get the number of bytes that an object would occupy as an element of an encoded Tuple. Unlike Tuple.getPackedSize(), this does not include the extra space an incomplete Versionstamp would add to the end to record its position.
      Parameters:
      item - an item of a tuple
      Returns:
      the number of bytes in the encoded form of the item
    • isPrefix

      public static boolean isPrefix(@Nonnull Tuple t1, @Nonnull Tuple t2)
      Get whether one tuple is a prefix of another.
      Parameters:
      t1 - the potential prefix
      t2 - the whole tuple
      Returns:
      true if t1 is a prefix of t2
    • prefixLengthOfSize

      public static int prefixLengthOfSize(@Nonnull byte[] bytes, int size)
      Get the index of a prefix of an encoded tuple that decodes as a sub-tuple of the given size.
      Parameters:
      bytes - encoded tuple
      size - size of desired subtuple
      Returns:
      the index into bytes that ends the sub-tuple or -1 if bytes is too short or decoding fails