public class ObjectId extends Object implements Comparable<ObjectId>, Serializable
Consists of 12 bytes, divided as follows:
0 1 2 3 4 5 6 7 8 9 10 11 time machine pid inc
| Constructor and Description |
|---|
ObjectId()
Create a new object id.
|
ObjectId(byte[] b)
Constructs an ObjectId given its 12-byte binary representation.
|
ObjectId(Date time) |
ObjectId(Date time,
int inc) |
ObjectId(Date time,
int machine,
int inc)
Deprecated.
ObjectId's constructed this way do not conform to
the ObjectId specification.
Please use ObjectId(byte[]) or
createFromLegacyFormat(int, int, int) instead. |
ObjectId(int time,
int machine,
int inc)
Deprecated.
ObjectId's constructed this way do not conform to
the ObjectId specification.
Please use ObjectId(byte[]) or
createFromLegacyFormat(int, int, int) instead. |
ObjectId(String s)
Creates a new instance from a string.
|
ObjectId(String s,
boolean babble)
Deprecated.
'babble' format is deprecated. Please use
ObjectId(String) instead. |
| Modifier and Type | Method and Description |
|---|---|
static int |
_flip(int x)
Deprecated.
This method is NOT a part of public API and will be dropped in 3.x versions.
|
int |
_inc()
Deprecated.
Please use
toByteArray() instead. |
int |
_machine()
Deprecated.
Please use
toByteArray() instead. |
int |
_time()
Deprecated.
Please use
getTimestamp() ()} instead. |
static String |
babbleToMongod(String b)
Deprecated.
This method is NOT a part of public API and will be dropped in 3.x versions.
|
int |
compareTo(ObjectId id) |
static ObjectId |
createFromLegacyFormat(int time,
int machine,
int inc)
Creates an ObjectId using time, machine and inc values.
|
boolean |
equals(Object o) |
static ObjectId |
get()
Gets a new object id.
|
static int |
getCurrentCounter()
Gets the current value of the auto-incrementing counter.
|
static int |
getCurrentInc()
Deprecated.
Please use
getCurrentCounter() instead. |
Date |
getDate()
Gets the timestamp as a
Date instance. |
static int |
getGenMachineId()
Deprecated.
|
int |
getInc()
Deprecated.
Please use the
toByteArray() instead. |
int |
getMachine()
Deprecated.
Please use
#toByteArray() instead. |
long |
getTime()
Deprecated.
Please use
getDate() ()} instead. |
int |
getTimeSecond()
Deprecated.
Please use
getTimestamp() ()} instead. |
int |
getTimestamp()
Gets the timestamp (number of seconds since the Unix epoch).
|
int |
hashCode() |
boolean |
isNew()
Deprecated.
'new' flag breaks the immutability of the
ObjectId class
and will be dropped in 3.x versions of the driver |
static boolean |
isValid(String s)
Checks if a string could be an
ObjectId. |
static ObjectId |
massageToObjectId(Object o)
Deprecated.
This method is NOT a part of public API and will be dropped in 3.x versions.
|
void |
notNew()
Deprecated.
'new' flag breaks the immutability of the
ObjectId class
and will be dropped in 3.x versions of the driver |
byte[] |
toByteArray() |
String |
toHexString()
Converts this instance into a 24-byte hexadecimal string representation.
|
String |
toString() |
String |
toStringBabble()
Deprecated.
'babble' format is deprecated. Please use
toHexString() instead. |
String |
toStringMongod()
Deprecated.
Please use
toHexString() instead. |
public ObjectId(Date time)
public ObjectId(Date time, int inc)
@Deprecated public ObjectId(Date time, int machine, int inc)
ObjectId's constructed this way do not conform to
the ObjectId specification.
Please use ObjectId(byte[]) or
createFromLegacyFormat(int, int, int) instead.public ObjectId(String s)
s - the string to convertIllegalArgumentException - if the string is not a valid id@Deprecated public ObjectId(String s, boolean babble)
ObjectId(String) instead.ObjectId from a string.s - the string representation of ObjectId. Can contains only [0-9]|[a-f]|[A-F] characters.babble - if true - convert to 'babble' objectId formatpublic ObjectId(byte[] b)
b - a byte array of length 12@Deprecated public ObjectId(int time, int machine, int inc)
ObjectId's constructed this way do not conform to
the ObjectId specification.
Please use ObjectId(byte[]) or
createFromLegacyFormat(int, int, int) instead.time - time in secondsmachine - machine IDinc - incremental valuecreateFromLegacyFormat(int, int, int)public ObjectId()
public static ObjectId get()
public static ObjectId createFromLegacyFormat(int time, int machine, int inc)
NOTE: This will not break any application that use ObjectIds. The 12-byte representation will be round-trippable from old to new driver releases.
time - time in secondsmachine - machine IDinc - incremental valueObjectId(int, int, int)public static boolean isValid(String s)
ObjectId.@Deprecated public static ObjectId massageToObjectId(Object o)
ObjectId, if possible.
Strings will be converted into ObjectIds, if possible, and ObjectIds will
be cast and returned. Passing in null returns null.o - the object to convertObjectId if it can be massaged, null otherwise@Deprecated public String toStringBabble()
toHexString() instead.public String toHexString()
@Deprecated public String toStringMongod()
toHexString() instead.public byte[] toByteArray()
@Deprecated public static String babbleToMongod(String b)
public int compareTo(ObjectId id)
compareTo in interface Comparable<ObjectId>public int getTimestamp()
public Date getDate()
Date instance.@Deprecated public long getTime()
getDate() ()} instead.@Deprecated public int getTimeSecond()
getTimestamp() ()} instead.@Deprecated public int getInc()
toByteArray() instead.@Deprecated public int _time()
getTimestamp() ()} instead.@Deprecated public int getMachine()
#toByteArray() instead.createFromLegacyFormat(int, int, int)@Deprecated public int _machine()
toByteArray() instead.createFromLegacyFormat(int, int, int)@Deprecated public int _inc()
toByteArray() instead.createFromLegacyFormat(int, int, int)@Deprecated public boolean isNew()
ObjectId class
and will be dropped in 3.x versions of the driver@Deprecated public void notNew()
ObjectId class
and will be dropped in 3.x versions of the driver@Deprecated public static int getGenMachineId()
createFromLegacyFormat(int, int, int)public static int getCurrentCounter()
@Deprecated public static int getCurrentInc()
getCurrentCounter() instead.@Deprecated public static int _flip(int x)