/* JFox, the OpenSource J2EE Application Server
 *
 * Distributable under GNU LGPL license by gun.org
 * more details please visit http://www.huihoo.org/jfox
 */

package org.jfox.framework.util;

import java.io.Serializable;

/**
 * @author <a href="mailto:young_yy@hotmail.com">Young Yang</a>
 */

public class ObjectUUID implements Serializable {

    private VMID vmid = VMID.getInstance();
    private UUID uuid = UUID.randomUUID();

    private ObjectUUID() {

    }

    public static ObjectUUID randomUUID() {
        return new ObjectUUID();
    }

    public VMID getVMID() {
        return vmid;
    }

    public UUID getUUID() {
        return uuid;
    }

    public String toString() {
        return vmid.toString() + "-" + uuid.toString();
    }

    public boolean equals(Object o) {
        if(this == o) return true;
        if(!(o instanceof ObjectUUID)) return false;

        final ObjectUUID objectUUID = (ObjectUUID) o;

        if(uuid != null ? !uuid.equals(objectUUID.uuid) : objectUUID.uuid != null) return false;
        if(vmid != null ? !vmid.equals(objectUUID.vmid) : objectUUID.vmid != null) return false;

        return true;
    }

    public int hashCode() {
        int result;
        result = (vmid != null ? vmid.hashCode() : 0);
        result = 29 * result + (uuid != null ? uuid.hashCode() : 0);
        return result;
    }

    public static void main(String[] args) {
        System.out.println(new ObjectUUID().toString());
        System.out.println(new ObjectUUID().toString());
        System.out.println(new ObjectUUID().toString());
        System.out.println(new ObjectUUID().toString());
        System.out.println(new ObjectUUID().toString());
    }
}
