public class ResourceIdHelper
extends java.lang.Object
handle.resourceId(WrappedResource)
.
The main areas of functionality implemented by this class include allocations of new resource identifiers, string formatting and parsing.
A resource identifier takes two forms, numeric and textual. The numeric form is
represented by Long
data type.
Internally, P2J can avoid the string representation of the resource ID and use it as a long
value. For this reason, the getNext()
API will never generate negative resource IDs,
as these are not valid legacy resource IDs (as calling idFromString(java.lang.String)
with a negative
resource ID will fail).
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_FORMAT
The default format string for a resource identifier (WARNING: not compatible with Progress).
|
private static java.math.BigInteger |
MAX_LONG
Max long constant
|
private static java.security.SecureRandom |
rnd
We are using Secure random number generator so the generated values
are uniformly distributed in the whole 64-bit range.
|
static java.lang.Long |
UNKNOWN
Constant denoting the unknown resource id
|
static java.lang.String |
UNKNOWN_STRING
Constant denoting the unknown resource id string
|
static java.lang.Long |
ZERO
Constant denoting the zero resource id
|
Constructor and Description |
---|
ResourceIdHelper() |
Modifier and Type | Method and Description |
---|---|
static java.lang.Long |
getNext()
Generates a valid resource identifier.
|
static java.lang.Long |
idFromString(java.lang.String resourceId)
Parses a resource id from its textual form into its numeric form.
|
static java.lang.String |
idToString(java.lang.Long resourceId)
Formats the numeric resource identifier with the default format string,
DEFAULT_FORMAT . |
static java.lang.String |
idToString(java.lang.String format,
java.lang.Long resourceId)
Formats the numeric resource identifier with the supplied format string.
|
static boolean |
isUnknown(java.lang.Long resourceId)
Returns
true if the supplied identifier represents
an unknown resource identifier, false otherwise. |
static boolean |
isZero(java.lang.Long resourceId)
Returns
true if the supplied identifier represents
a zero resource identifier, false otherwise. |
public static final java.lang.Long UNKNOWN
public static final java.lang.String UNKNOWN_STRING
public static final java.lang.Long ZERO
public static final java.lang.String DEFAULT_FORMAT
private static java.security.SecureRandom rnd
private static final java.math.BigInteger MAX_LONG
public static java.lang.Long getNext()
The returned value is a randomly generated positive 64bit number with no guarantee of uniqueness. It is the responsibility of the caller to check uniqueness of the returned value in the caller's context if required.
public static boolean isZero(java.lang.Long resourceId)
true
if the supplied identifier represents
a zero resource identifier, false
otherwise.resourceId
- Resource identifier.public static boolean isUnknown(java.lang.Long resourceId)
true
if the supplied identifier represents
an unknown resource identifier, false
otherwise.resourceId
- Resource identifier.public static java.lang.Long idFromString(java.lang.String resourceId) throws ErrorConditionException
NumberType.parseDouble(java.lang.String, boolean)
.
The method returns UNKNOWN
if the input is null
or equal to "?" or
the method returns ZERO
if the input contains a trimmed empty string or
the method returns ZERO
if the parsed input is zero or less than zero or
the method throws ErrorConditionException
if the input cannot be parsed to
an integer.
resourceId
- A string value representing a resource identifier.ErrorConditionException
- If the input cannot be parsed into an integer, see method description
for more details.public static java.lang.String idToString(java.lang.Long resourceId)
DEFAULT_FORMAT
.
See idToString(String, Long)
for more details.resourceId
- Resource identifier.public static java.lang.String idToString(java.lang.String format, java.lang.Long resourceId)
format
- Format string.resourceId
- Resource identifier.java.lang.IllegalArgumentException
- If the resource ID is negative.