com.mongodb
Class ObjectId

java.lang.Object
  extended by com.mongodb.ObjectId
All Implemented Interfaces:
Comparable<ObjectId>

public class ObjectId
extends Object
implements Comparable<ObjectId>

A globally unique identifier for objects.

Consists of 12 bytes, divided as follows:

 
0123456 7891011
timemachine pidinc


MongoDB Doc Links

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

Constructor Detail

ObjectId

public ObjectId(Date time)

ObjectId

public ObjectId(Date time,
                int inc)

ObjectId

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

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

ObjectId

public ObjectId(String s,
                boolean babble)

ObjectId

public ObjectId(byte[] b)

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(String s)
Checks if a string could be an ObjectId.

Returns:
whether the string could be an object id

massageToObjectId

public static ObjectId massageToObjectId(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 Object

equals

public boolean equals(Object o)
Overrides:
equals in class Object

toStringBabble

public String toStringBabble()

toStringMongod

public String toStringMongod()

toByteArray

public byte[] toByteArray()

babbleToMongod

public static String babbleToMongod(String b)

toString

public String toString()
Overrides:
toString in class Object

compareTo

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

getMachine

public int getMachine()

getTime

public long getTime()

getInc

public int getInc()

main

public static void main(String[] args)