1 | package dmg.cells.nucleus; |
2 | |
3 | import java.io.Serializable; |
4 | |
5 | /** |
6 | * |
7 | * Is the core of the CellDomain addressing scheme. The |
8 | * <code>CellAddressCore</code> specifies the name of the cell and the name of |
9 | * the domain the cell exists in.<br> |
10 | * <strong>This Class is designed to be immutable. The whole package relies on |
11 | * that fact. </strong> |
12 | * |
13 | * @author Patrick Fuhrmann |
14 | * @version 0.1,02/15/1998 |
15 | * |
16 | * |
17 | */ |
18 | |
19 | /* |
20 | * @Immutable |
21 | */ |
22 | public class CellAddressCore implements Cloneable, Serializable { |
23 | |
24 | static final long serialVersionUID = 4072907109959708379L; |
25 | |
26 | private final String _domain; |
27 | private final String _cell; |
28 | |
29 | /** |
30 | * while CellAddressCore always used in CellPath, where it stored inside |
31 | * List, store pre-calculated hashcode; |
32 | */ |
33 | private final int _hashcode; |
34 | |
35 | /** |
36 | * Creates a CellAddressCore by scanning the argument string. The syntax can |
37 | * be only one of the following :<br> |
38 | * <cellName> or <cellName>@<domainName>. If the <domainName> is omitted, |
39 | * the keyword 'local' is used instead. |
40 | * |
41 | * @param addr |
42 | * the cell address specification which is interpreted as |
43 | * described above. The specified <code>addr</code> is not |
44 | * checked for existence. |
45 | * @return the immutable CellAddressCore. |
46 | * |
47 | */ |
48 | public CellAddressCore(String addr) { |
49 | int ind = addr.indexOf('@'); |
50 | if (ind < 0) { |
51 | _cell = addr; |
52 | _domain = "local"; |
53 | } else { |
54 | _cell = addr.substring(0, ind); |
55 | if (ind == (addr.length() - 1)) |
56 | _domain = "local"; |
57 | else |
58 | _domain = addr.substring(ind + 1); |
59 | } |
60 | |
61 | _hashcode = (_domain + _cell).hashCode(); |
62 | } |
63 | |
64 | public CellAddressCore(String addr, String domain) { |
65 | _cell = addr; |
66 | _domain = domain; |
67 | _hashcode = (_domain + _cell).hashCode(); |
68 | } |
69 | |
70 | /* |
71 | CellAddressCore getClone(){ |
72 | try { |
73 | return (CellAddressCore)this.clone() ; |
74 | }catch( CloneNotSupportedException cnse ){ |
75 | return null ; |
76 | } |
77 | } |
78 | */ |
79 | public String getCellName() { |
80 | return _cell; |
81 | } |
82 | |
83 | public String getCellDomainName() { |
84 | return _domain; |
85 | } |
86 | |
87 | @Override |
88 | public String toString() { |
89 | return (_cell != null ? _cell : "UnknownCell") + "@" |
90 | + (_domain != null ? _domain : "UnknownDomain"); |
91 | } |
92 | |
93 | @Override |
94 | public boolean equals(Object obj) { |
95 | |
96 | if (obj == this) return true; |
97 | if (!(obj instanceof CellAddressCore)) return false; |
98 | |
99 | CellAddressCore other = (CellAddressCore) obj; |
100 | return other._domain.equals(_domain) && other._cell.equals(_cell); |
101 | } |
102 | |
103 | @Override |
104 | public int hashCode() { |
105 | return _hashcode; |
106 | } |
107 | |
108 | } |