org.bson.types
Class ObjectId

java.lang.Object
  extended by org.bson.types.ObjectId
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<ObjectId>

public class ObjectId
extends java.lang.Object
implements java.lang.Comparable<ObjectId>, java.io.Serializable

A globally unique identifier for objects.

Consists of 12 bytes, divided as follows:

 
0123456 7891011
timemachine pidinc

See Also:
Serialized Form
MongoDB Doc Links

Constructor Summary
ObjectId()
          Create a new object id.
ObjectId(byte[] b)
           
ObjectId(java.util.Date time)
           
ObjectId(java.util.Date time, int inc)
           
ObjectId(java.util.Date time, int machine, int inc)
           
ObjectId(int time, int machine, int inc)
           
ObjectId(java.lang.String s)
          Creates a new instance from a string.
ObjectId(java.lang.String s, boolean babble)
           
 
Method Summary
static int _flip(int x)
           
 int _inc()
           
 int _machine()
           
 int _time()
           
static java.lang.String babbleToMongod(java.lang.String b)
           
 int compareTo(ObjectId id)
           
 boolean equals(java.lang.Object o)
           
static ObjectId get()
          Gets a new object id.
 int getInc()
           
 int getMachine()
           
 long getTime()
           
 int hashCode()
           
 boolean isNew()
           
static boolean isValid(java.lang.String s)
          Checks if a string could be an ObjectId.
static ObjectId massageToObjectId(java.lang.Object o)
          Turn an object into an ObjectId, if possible.
 void notNew()
           
 byte[] toByteArray()
           
 java.lang.String toString()
           
 java.lang.String toStringBabble()
           
 java.lang.String toStringMongod()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ObjectId

public ObjectId(java.util.Date time)

ObjectId

public ObjectId(java.util.Date time,
                int inc)

ObjectId

public ObjectId(java.util.Date time,
                int machine,
                int inc)

ObjectId

public ObjectId(java.lang.String s)
Creates a new instance from a string.

Parameters:
s - the string to convert
Throws:
java.lang.IllegalArgumentException - if the string is not a valid id

ObjectId

public ObjectId(java.lang.String s,
                boolean babble)

ObjectId

public ObjectId(byte[] b)

ObjectId

public ObjectId(int time,
                int machine,
                int inc)

ObjectId

public ObjectId()
Create a new object id.

Method Detail

get

public static ObjectId get()
Gets a new object id.

Returns:
the new id

isValid

public static boolean isValid(java.lang.String s)
Checks if a string could be an ObjectId.

Returns:
whether the string could be an object id

massageToObjectId

public static ObjectId massageToObjectId(java.lang.Object o)
Turn an object into an ObjectId, if possible. Strings will be converted into ObjectIds, if possible, and ObjectIds will be cast and returned. Passing in null returns null.

Parameters:
o - the object to convert
Returns:
an ObjectId if it can be massaged, null otherwise

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

toStringBabble

public java.lang.String toStringBabble()

toStringMongod

public java.lang.String toStringMongod()

toByteArray

public byte[] toByteArray()

babbleToMongod

public static java.lang.String babbleToMongod(java.lang.String b)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

compareTo

public int compareTo(ObjectId id)
Specified by:
compareTo in interface java.lang.Comparable<ObjectId>

getMachine

public int getMachine()

getTime

public long getTime()

getInc

public int getInc()

_time

public int _time()

_machine

public int _machine()

_inc

public int _inc()

isNew

public boolean isNew()

notNew

public void notNew()

_flip

public static int _flip(int x)