001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.core.bo.user;
017:
018: import java.io.Serializable;
019:
020: /**
021: * This class is a wrapper class for UUID
022: *
023: *
024: */
025: public final class UuId implements UserId, Serializable {
026: private static final long serialVersionUID = -8581055150173349593L;
027:
028: public static final UuId NOT_FOUND = new UuId("not found");
029:
030: private String uuId;
031:
032: /**
033: * Constructor that takes in a string uuid
034: *
035: * @param uuId
036: */
037: public UuId(String uuId) {
038: setUuId(uuId);
039: }
040:
041: /**
042: * Empty constructor
043: *
044: */
045: public UuId() {
046: }
047:
048: /**
049: * simple getter for string uuid
050: *
051: * @return
052: */
053: public String getUuId() {
054: return uuId;
055: }
056:
057: /**
058: * simple setter for uuid
059: *
060: * @param uuId
061: */
062: public void setUuId(String uuId) {
063: this .uuId = (uuId == null ? null : uuId.trim());
064: }
065:
066: /**
067: * Returns true if this userId has an empty value. Empty userIds can't be used as keys in a Hash, among other things.
068: *
069: * @return true if this instance doesn't have a value
070: */
071: public boolean isEmpty() {
072: return (uuId == null || uuId.trim().length() == 0);
073: }
074:
075: /**
076: * Override of equals that allows us to compare uuids If you make this class non-final, you must rewrite equals to work for
077: * subclasses.
078: */
079: public boolean equals(Object obj) {
080: boolean isEqual = false;
081:
082: if (obj != null && (obj instanceof UuId)) {
083: UuId a = (UuId) obj;
084:
085: if (getUuId() == null) {
086: return false;
087: }
088:
089: return uuId.equals(a.uuId);
090: }
091:
092: return false;
093: }
094:
095: /**
096: * override of hashCode since we overrode equals
097: */
098: public int hashCode() {
099: return uuId == null ? 0 : uuId.hashCode();
100: }
101:
102: /**
103: * override of toString that will print uuid
104: */
105: public String toString() {
106: return uuId;
107: }
108: }
|