Source code: org/mitre/cvw/CVWObjNum.java
1 /*
2 * Copyright (c) 1996-2000. The MITRE Corporation (http://www.mitre.org/).
3 * All rights reserved.
4 * CVW comes with ABSOLUTELY NO WARRANTY. See license for details.
5 */
6
7 package org.mitre.cvw;
8
9 import java.io.Serializable;
10
11 /**************************************************************
12 **************** CVW Server Comm Object *********************
13 **************************************************************/
14 /**
15 * This class represents the object number of all objects on the CVW server.
16 * It is in the format of #xxxx. If the string used to create the CVWObjNum
17 * doesn't have a #, it inserts one.
18 * @version 1.0
19 * @author Deb Ercolini
20 */
21 public class CVWObjNum extends Object implements Serializable{
22 String strValue; //"#xxxx"
23 int numValue; //xxxx
24 String server = null; // e.g. if strValue is #123@cvw, server is cvw
25
26
27 /**
28 * Constructor
29 * @param str the string value of the object number
30 */
31 public CVWObjNum(String str) {
32 try {
33 if (!str.startsWith("#"))
34 strValue = "#"+str;
35 else
36 strValue = str;
37
38 String piece[] = CVWServer.split(strValue);
39 numValue = new Integer(piece[0].substring(1)).intValue();
40 server = (!piece[1].equals("")) ? piece[1] : null;
41 } catch (Exception e) {
42 System.err.println("Integer exception is " + e);
43 }
44 }
45
46 /**
47 * Constructor
48 * @param num the int value of the object number
49 */
50 public CVWObjNum(int num) {
51 numValue = num;
52 strValue = "#" + String.valueOf(num);
53 }
54
55 /**
56 * Returns a int representing the object number.
57 * @return the integer value of the object number
58 */
59 public int intValue() {
60 return numValue;
61 }
62
63 /**
64 * Returns a string representing the object number.
65 * @return the string value of the object number
66 */
67 public String strValue() {
68 return strValue;
69 }
70
71 /**
72 * Returns the server identity portion, if it exists.
73 * @return the ID of the server (null if object is local)
74 */
75 public String serverValue() {
76 return server;
77 }
78
79 /**
80 * Returns whether the two object numbers are the same using int comparison.
81 * If the object isnt even a CVWObjNum, then return <code>false</code>.
82 * @param obj the object number to be compared.
83 * @return whether the two object numbers are the same
84 */
85 public boolean equals(Object obj) {
86 if ((obj != null) && (obj instanceof CVWObjNum)) {
87 return strValue.equals(((CVWObjNum)obj).strValue());
88 }
89 return false;
90 }
91
92 /**
93 * Returns whether the this object number is the same as that of the CVWObject
94 * passed in, using int comparison.
95 * @param cvwObj the object to be compared.
96 * @return whether the two object numbers are the same
97 */
98 public boolean equals(CVWObject cvwObj) {
99 if (cvwObj != null)
100 return this.equals(cvwObj.objNum);
101 return false;
102 }
103
104 /**
105 * Returns whether the two object numbers are the same using int comparison.
106 * @param objNum the object number to compare
107 * @return whether the two object numbers are the same
108 */
109 public boolean equals(CVWObjNum objNum) {
110 if (objNum == null) return false;
111 return (objNum.strValue().equals(this.strValue));
112 }
113
114 /**
115 * Checks whether the two object numbers are the same using string comparison.
116 * @param str the string value of an object number
117 * @return whether the two object numbers are the same using string comparison
118 */
119 public boolean equals(String str) {
120 return strValue.equals(str);
121 }
122
123 /**
124 * Checks whether the two object numbers are the same using int comparison.
125 * @param num the int value of an object number
126 * @return whether the two object numbers are the same using int comparison
127 */
128 public boolean equals(int num) {
129 return (numValue == num);
130 }
131
132 /**
133 * Checks whether the two object numbers are the same using Integer comparison.
134 * Don't use this one!!!!
135 * @param num the Integer value of an object number
136 * @return whether the two object numbers are the same using Integer comparison
137 */
138 public boolean equals(Integer num) {
139 return (numValue == num.intValue());
140 }
141
142 /**
143 * Returns a hashcode for this object number.
144 * @return a hashcode for this object number
145 */
146 public int hashCode() {
147 return numValue;
148 }
149
150 /**
151 * Returns a string representation of this component and its values.
152 * @return a string representation of this component.
153 */
154 public String toString() {
155 return(getClass().getName() + "[" +
156 "strValue=" + strValue +
157 ",intValue=" + numValue + "]");
158 }
159
160 }
161