ORCentral

src/eu/coform/UniqueID.java

Go to the documentation of this file.
00001 package eu.coform;
00002 
00003 import java.util.UUID;
00004 
00008 public class UniqueID {
00009    
00010    private String id;
00011     
00015    public UniqueID() { }
00016 
00022    public UniqueID(String idstring) throws IllegalArgumentException {
00023       this.id = UUID.fromString(idstring).toString();
00024    }
00025    
00026    public String getId() {
00027       return id;
00028    }
00029 
00030    public void setId(String id) {
00031       this.id = id;
00032    }
00033    
00038    public String toBin16() {
00039       return id.replaceAll("-", "");
00040    }
00041    
00049    public static UniqueID fromBin16(String bin16) {
00050       bin16 = new StringBuffer(bin16)
00051       .insert(20, "-")
00052       .insert(16, "-")
00053       .insert(12, "-")
00054       .insert(8,  "-")
00055       .toString();
00056       return new UniqueID(UUID.fromString(bin16).toString());
00057    }
00058    
00062    public void setRandomUUID() {
00063       setId(randomUUID());
00064    }
00065    
00069    public static String randomUUID() {
00070       return java.util.UUID.randomUUID().toString();
00071    }
00072    
00076    public static UniqueID randomUniqueID() {
00077       UniqueID u = new UniqueID();
00078       u.setRandomUUID();
00079       return u;
00080    }
00081 
00085    public UniqueID newUniqueID() { 
00086       id = randomUUID();
00087       return this;
00088    }
00089    
00090 }
 All Classes Namespaces Files Functions Variables Enumerations