Package org.rocksdb
Class AbstractSlice<T>
- java.lang.Object
-
- org.rocksdb.AbstractNativeReference
-
- org.rocksdb.RocksMutableObject
-
- org.rocksdb.AbstractSlice<T>
-
- All Implemented Interfaces:
java.lang.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:
Slice,Regards the lifecycle of Java Slices in RocksDB: At present when you configure a Comparator from Java, it creates an instance of a C++ BaseComparatorJniCallback subclass and passes that to RocksDB as the comparator. That subclass of BaseComparatorJniCallback creates the Java,subclass Objects. When you dispose the Java @see org.rocksdb.AbstractComparator subclass, it disposes the C++ BaseComparatorJniCallback subclass, which in turn destroys the Java @see org.rocksdb.AbstractSlice subclass Objects.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractSlice()protectedAbstractSlice(long nativeHandle)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voidclear()Clears the backing sliceintcompare(AbstractSlice<?> other)Three-way key comparisonprotected static longcreateNewSliceFromString(java.lang.String str)Tdata()Returns the data of the slice.protected abstract Tdata0(long handle)Access to the data is provided by the subtype as it needs to handle the generic typing.protected voiddisposeInternal(long handle)Deletes underlying C++ slice pointer.booleanempty()Return true if the length of the data is zero.booleanequals(java.lang.Object other)If other is a slice object, then we defer tocompareto check equality, otherwise we return false.inthashCode()abstract voidremovePrefix(int n)Drops the specifiednnumber of bytes from the start of the backing sliceintsize()Return the length (in bytes) of the data.booleanstartsWith(AbstractSlice<?> prefix)Determines whether this slice starts with another slicejava.lang.StringtoString()java.lang.StringtoString(boolean hex)Creates a string representation of the data-
Methods inherited from class org.rocksdb.RocksMutableObject
close, disposeInternal, getNativeHandle, isOwningHandle, resetNativeHandle, setNativeHandle
-
Methods inherited from class org.rocksdb.AbstractNativeReference
dispose, finalize
-
-
-
-
Method Detail
-
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(long)
-
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 specifiednnumber 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 java.lang.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 java.lang.String toString()
- Overrides:
toStringin classjava.lang.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:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object other)
If other is a slice object, then we defer tocompareto check equality, otherwise we return false.- Overrides:
equalsin classjava.lang.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
prefixslice
-
createNewSliceFromString
protected static long createNewSliceFromString(java.lang.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:
disposeInternalin classRocksMutableObject
-
-