Package org.sensorhub.api.common
Interface BigId
- All Superinterfaces:
Comparable<BigId>
- All Known Implementing Classes:
BigIdBytes
,BigIdLong
,BigIdZero
Class used to store arbitrary long IDs (i.e. as many bytes as necessary can be encoded, much like BigInteger), along with a scope.
The local ID part is typically used as the database local ID while the combination of scope and ID is used as a public ID (for example by the federated database). The scope must be unique for Id provider in order to be able to form a globally unique ID across providers (e.g. different databases).
- Since:
- Apr 14, 2022
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final com.google.common.io.BaseEncoding
static final Comparator<byte[]>
static final String
static final BigId
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
Compare two BigIds using their byte representations.static int
compareLongs
(BigId a, BigId b) Compare two BigIds using their long representations.default int
boolean
static boolean
static BigId
fromBytes
(int scope, byte[] id) Creates a BigId from a scope and an ID part coded as a byte arraystatic BigId
fromBytes
(int scope, byte[] buf, int offset, int len) Creates a BigId with the given scope and reading the ID part from a portion of a byte arraystatic BigId
fromLong
(int scope, long id) Creates a BigId from a scope and an ID part coded as a longstatic Collection<BigId>
fromLongs
(int scope, long... ids) Creates multiple BigIds from a scope and their ID parts coded as longsstatic BigId
Parse a BigId from a base32 encoded stringbyte[]
default long
int
getScope()
int
hashCode()
default int
size()
static String
toString32
(BigId id)
-
Field Details
-
NONE
-
NO_LONG_REPRESENTATION
- See Also:
-
BYTES_COMPARATOR
-
BASE32_ENCODING
static final com.google.common.io.BaseEncoding BASE32_ENCODING
-
-
Method Details
-
getScope
int getScope()- Returns:
- The scope within which the ID is valid
-
getIdAsBytes
byte[] getIdAsBytes()- Returns:
- The value of the ID part as a byte array
-
getIdAsLong
default long getIdAsLong()- Returns:
- The value of the ID part as a long
- Throws:
IllegalArgumentException
- if this type of BigId cannot be represented by a single long value
-
size
default int size()- Returns:
- Size of the ID part in bytes
-
compareTo
- Specified by:
compareTo
in interfaceComparable<BigId>
-
equals
-
hashCode
int hashCode() -
fromBytes
Creates a BigId from a scope and an ID part coded as a byte array- Parameters:
scope
- Integer ID scope (e.g. database number)id
- Local ID part- Returns:
- The new immutable BigId instance
-
fromBytes
Creates a BigId with the given scope and reading the ID part from a portion of a byte array- Parameters:
scope
- Integer ID scope (e.g. database number)buf
- Byte array containing the local ID partoffset
- Offset where to start reading the ID in the byte arraylen
- Number of bytes to read from the byte array- Returns:
- The new immutable BigId instance
-
fromLong
Creates a BigId from a scope and an ID part coded as a long- Parameters:
scope
- Integer ID scope (e.g. database number)id
- Local ID part- Returns:
- The new immutable BigId instance
-
fromLongs
Creates multiple BigIds from a scope and their ID parts coded as longs- Parameters:
scope
- Integer ID scope (e.g. database number)ids
- One or more local IDs- Returns:
- A collection of immutable BigId instances
-
equals
-
compare
Compare two BigIds using their byte representations. This function works with all BigId types since they are all required to provide a byte[] representation.- Parameters:
a
- First id to compare (must not be null)b
- Second id to compare (must not be null)- Returns:
- A negative, zero, or positive integer as the first argument is less than, equal to, or greater than the second.
- Throws:
NullPointerException
- if one of the argument is null
-
compareLongs
Compare two BigIds using their long representations. This will only work for BigId types with an ID part that can be represented as a long.- Parameters:
a
- First id to compare (must not be null)b
- Second id to compare (must not be null)- Returns:
- A negative, zero, or positive integer as the first argument is less than, equal to, or greater than the second.
- Throws:
NullPointerException
- if one of the argument is null
-
fromString32
Parse a BigId from a base32 encoded string- Parameters:
s
-- Returns:
- A BigId instance
- Throws:
IllegalArgumentException
- if the provided string is not a valid base32 string as per IETF RFC 4648 section 7
-
toString32
-