Package org.rocksdb

Class AbstractSlice<T>

All Implemented Interfaces:
AutoCloseable
Direct Known Subclasses:
DirectSlice, Slice

public abstract class AbstractSlice<T> extends RocksMutableObject
Slices are used by RocksDB to provide efficient access to keys and values.

This class is package private, implementers should extend either of the public abstract classes:

See Also:
  • Constructor Details

    • AbstractSlice

      protected AbstractSlice()
    • AbstractSlice

      protected AbstractSlice(long nativeHandle)
  • Method Details

    • data

      public T data()
      Returns the data of the slice.
      Returns:
      The slice data. Note, the type of access is determined by the subclass
      See Also:
    • data0

      protected abstract T data0(long handle)
      Access to the data is provided by the subtype as it needs to handle the generic typing.
      Parameters:
      handle - The address of the underlying native object.
      Returns:
      Java typed access to the data.
    • removePrefix

      public abstract void removePrefix(int n)
      Drops the specified n number of bytes from the start of the backing slice
      Parameters:
      n - The number of bytes to drop
    • clear

      public abstract void clear()
      Clears the backing slice
    • size

      public int size()
      Return the length (in bytes) of the data.
      Returns:
      The length in bytes.
    • empty

      public boolean empty()
      Return true if the length of the data is zero.
      Returns:
      true if there is no data, false otherwise.
    • toString

      public String toString(boolean hex)
      Creates a string representation of the data
      Parameters:
      hex - When true, the representation will be encoded in hexadecimal.
      Returns:
      The string representation of the data.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • compare

      public int compare(AbstractSlice<?> other)
      Three-way key comparison
      Parameters:
      other - A slice to compare against
      Returns:
      Should return either: 1) < 0 if this < other 2) == 0 if this == other 3) > 0 if this > other
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object other)
      If other is a slice object, then we defer to compare to check equality, otherwise we return false.
      Overrides:
      equals in class Object
      Parameters:
      other - Object to test for equality
      Returns:
      true when this.compare(other) == 0, false otherwise.
    • startsWith

      public boolean startsWith(AbstractSlice<?> prefix)
      Determines whether this slice starts with another slice
      Parameters:
      prefix - Another slice which may of may not be a prefix of this slice.
      Returns:
      true when this slice starts with the prefix slice
    • createNewSliceFromString

      protected static long createNewSliceFromString(String str)
    • disposeInternal

      protected final void disposeInternal(long handle)
      Deletes underlying C++ slice pointer. Note that this function should be called only after all RocksDB instances referencing the slice are closed. Otherwise, an undefined behavior will occur.
      Specified by:
      disposeInternal in class RocksMutableObject