01: /*
02: * <copyright>
03: *
04: * Copyright 1997-2004 BBNT Solutions, LLC
05: * under sponsorship of the Defense Advanced Research Projects
06: * Agency (DARPA).
07: *
08: * You can redistribute this software and/or modify it under the
09: * terms of the Cougaar Open Source License as published on the
10: * Cougaar Open Source Website (www.cougaar.org).
11: *
12: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
15: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
16: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
18: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23: *
24: * </copyright>
25: */
26:
27: package org.cougaar.core.util;
28:
29: import java.io.Serializable;
30:
31: /**
32: * An object with a {@link UID} created by the {@link
33: * org.cougaar.core.service.UIDService}.
34: * <p>
35: * The UID is often set by a {@link org.cougaar.core.domain.Domain}
36: * {@link org.cougaar.core.domain.Factory}, and/or as a final field
37: * set in the object's constructor.
38: * <p>
39: * Objects that implement UniqueObject often use the UID for the
40: * "equals(Object)" and "hashCode()" methods, e.g.<pre>
41: * public class X implements UniqueObject .. {..
42: * public boolean equals(Object o) {
43: * return
44: * (o == this ||
45: * ((o instanceof X) &&
46: * getUID().equals(((X) o).getUID()));
47: * }
48: * public int hashCode() {
49: * return getUID().hashCode();
50: * }
51: * }
52: * </pre>
53: */
54: public interface UniqueObject extends Serializable {
55: /**
56: * @return the UID of this UniqueObject.
57: */
58: UID getUID();
59:
60: /**
61: * Set the UID of this UniqueObject, which may throw a
62: * RuntimeException if the UID is already set.
63: */
64: void setUID(UID uid);
65: }
|