01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.catalina.tribes;
18:
19: import org.apache.catalina.tribes.util.Arrays;
20: import java.io.Serializable;
21:
22: /**
23: * <p>Title: Represents a globabally unique Id</p>
24: *
25: * <p>Company: </p>
26: *
27: * @author Filip Hanik
28: * @version 1.0
29: */
30: public final class UniqueId implements Serializable {
31: protected byte[] id;
32:
33: public UniqueId() {
34: }
35:
36: public UniqueId(byte[] id) {
37: this .id = id;
38: }
39:
40: public UniqueId(byte[] id, int offset, int length) {
41: this .id = new byte[length];
42: System.arraycopy(id, offset, this .id, 0, length);
43: }
44:
45: public int hashCode() {
46: if (id == null)
47: return 0;
48: return Arrays.hashCode(id);
49: }
50:
51: public boolean equals(Object other) {
52: boolean result = (other instanceof UniqueId);
53: if (result) {
54: UniqueId uid = (UniqueId) other;
55: if (this .id == null && uid.id == null)
56: result = true;
57: else if (this .id == null && uid.id != null)
58: result = false;
59: else if (this .id != null && uid.id == null)
60: result = false;
61: else
62: result = Arrays.equals(this .id, uid.id);
63: }//end if
64: return result;
65: }
66:
67: public byte[] getBytes() {
68: return id;
69: }
70:
71: public String toString() {
72: StringBuffer buf = new StringBuffer("UniqueId");
73: buf.append(org.apache.catalina.tribes.util.Arrays.toString(id));
74: return buf.toString();
75: }
76:
77: }
|