File Source: ConfigTarget.java
/*
P/P * Method: com.dmdirc.config.ConfigTarget__static_init
*/
1 /*
2 * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 package com.dmdirc.config;
24
25 import java.io.Serializable;
26
27 /**
28 * Represents the target of a particular config source.
29 * <p>
30 * Note: this class has a natural ordering that is inconsistent with equals.
31 *
32 * @author chris
33 */
34 public class ConfigTarget implements Comparable, Serializable {
35
36 /** The possible target types. */
/*
P/P * Method: void com.dmdirc.config.ConfigTarget$TYPE(String, int)
*/
37 public static enum TYPE {
38 /** Client-wide default settings. */
/*
P/P * Method: com.dmdirc.config.ConfigTarget$TYPE__static_init
*
* Postconditions:
* $VALUES == &new ConfigTarget$TYPE[](ConfigTarget$TYPE__static_init#9)
* CHANNEL == &new ConfigTarget$TYPE(ConfigTarget$TYPE__static_init#8)
* $VALUES[7] == &new ConfigTarget$TYPE(ConfigTarget$TYPE__static_init#8)
* GLOBAL == &new ConfigTarget$TYPE(ConfigTarget$TYPE__static_init#2)
* $VALUES[1] == &new ConfigTarget$TYPE(ConfigTarget$TYPE__static_init#2)
* GLOBALDEFAULT == &new ConfigTarget$TYPE(ConfigTarget$TYPE__static_init#1)
* $VALUES[0] == &new ConfigTarget$TYPE(ConfigTarget$TYPE__static_init#1)
* IRCD == &new ConfigTarget$TYPE(ConfigTarget$TYPE__static_init#5)
* $VALUES[4] == &new ConfigTarget$TYPE(ConfigTarget$TYPE__static_init#5)
* NETWORK == &new ConfigTarget$TYPE(ConfigTarget$TYPE__static_init#6)
* ...
*/
39 GLOBALDEFAULT,
40 /** Client-wide settings. */
41 GLOBAL,
42 /** Settings for a theme. */
43 THEME,
44 /** Settings for a profile. */
45 PROFILE,
46 /** Settings for an IRCd. */
47 IRCD,
48 /** Settings for a network. */
49 NETWORK,
50 /** Settings for a server. */
51 SERVER,
52 /** Settings for a channel. */
53 CHANNEL,
54 }
55
56 /**
57 * A version number for this class. It should be changed whenever the class
58 * structure is changed (or anything else that would prevent serialized
59 * objects being unserialized with the new class).
60 */
61 private static final long serialVersionUID = 2;
62
63 /** The type of this target. */
64 protected TYPE type = ConfigTarget.TYPE.GLOBAL;
65
66 /** The data of this target. */
67 protected String data;
68
69 /** The user-defined ordering for this target. */
70 protected int order = 50000;
71
72 /** Creates a new instance of ConfigTarget. */
/*
P/P * Method: void com.dmdirc.config.ConfigTarget()
*
* Postconditions:
* this.order == 50_000
* this.type == &com.dmdirc.config.ConfigTarget$TYPE__static_init.new ConfigTarget$TYPE(ConfigTarget$TYPE__static_init#2)
*/
73 public ConfigTarget() {
74 //Do nothing.
75 }
76
77 /**
78 * Sets the ordering value for this target. Lower means higher preference.
79 *
80 * @param order The new order to use
81 */
82 public void setOrder(final int order) {
/*
P/P * Method: void setOrder(int)
*
* Postconditions:
* this.order == order
* init'ed(this.order)
*/
83 this.order = order;
84 }
85
86 /**
87 * Retrieves the ordering value for this target. Lower means higher preference.
88 *
89 * @return This target's order
90 */
91 public int getOrder() {
/*
P/P * Method: int getOrder()
*
* Preconditions:
* init'ed(this.order)
*
* Postconditions:
* return_value == this.order
* init'ed(return_value)
*/
92 return order;
93 }
94
95 /** Sets this target to be a global config source. */
96 public void setGlobal() {
/*
P/P * Method: void setGlobal()
*
* Postconditions:
* this.data == &""
* this.type == &com.dmdirc.config.ConfigTarget$TYPE__static_init.new ConfigTarget$TYPE(ConfigTarget$TYPE__static_init#2)
*/
97 type = TYPE.GLOBAL;
98 data = "";
99 }
100
101 /** Sets this target to be a global default source. */
102 public void setGlobalDefault() {
/*
P/P * Method: void setGlobalDefault()
*
* Postconditions:
* this.data == &""
* this.type == &com.dmdirc.config.ConfigTarget$TYPE__static_init.new ConfigTarget$TYPE(ConfigTarget$TYPE__static_init#1)
*/
103 type = TYPE.GLOBALDEFAULT;
104 data = "";
105 }
106
107 /** Sets this target to be a theme source. */
108 public void setTheme() {
/*
P/P * Method: void setTheme()
*
* Postconditions:
* this.data == &""
* this.type == &com.dmdirc.config.ConfigTarget$TYPE__static_init.new ConfigTarget$TYPE(ConfigTarget$TYPE__static_init#3)
*/
109 type = TYPE.THEME;
110 data = "";
111 }
112
113 /** Sets this target to be a profile source. */
114 public void setProfile() {
/*
P/P * Method: void setProfile()
*
* Postconditions:
* this.data == &""
* this.type == &com.dmdirc.config.ConfigTarget$TYPE__static_init.new ConfigTarget$TYPE(ConfigTarget$TYPE__static_init#4)
*/
115 type = TYPE.PROFILE;
116 data = "";
117 }
118
119 /**
120 * Sets this target to target an ircd.
121 *
122 * @param ircd The ircd to target
123 */
124 public void setIrcd(final String ircd) {
/*
P/P * Method: void setIrcd(String)
*
* Postconditions:
* this.data == ircd
* init'ed(this.data)
* this.type == &com.dmdirc.config.ConfigTarget$TYPE__static_init.new ConfigTarget$TYPE(ConfigTarget$TYPE__static_init#5)
*/
125 type = TYPE.IRCD;
126 data = ircd;
127 }
128
129 /**
130 * Sets this target to target a network.
131 *
132 * @param network The network to target
133 */
134 public void setNetwork(final String network) {
/*
P/P * Method: void setNetwork(String)
*
* Postconditions:
* this.data == network
* init'ed(this.data)
* this.type == &com.dmdirc.config.ConfigTarget$TYPE__static_init.new ConfigTarget$TYPE(ConfigTarget$TYPE__static_init#6)
*/
135 type = TYPE.NETWORK;
136 data = network;
137 }
138
139 /**
140 * Sets this target to target a server.
141 *
142 * @param server The server to target
143 */
144 public void setServer(final String server) {
/*
P/P * Method: void setServer(String)
*
* Postconditions:
* this.data == server
* init'ed(this.data)
* this.type == &com.dmdirc.config.ConfigTarget$TYPE__static_init.new ConfigTarget$TYPE(ConfigTarget$TYPE__static_init#7)
*/
145 type = TYPE.SERVER;
146 data = server;
147 }
148
149 /**
150 * Sets this target to target a channel.
151 *
152 * @param channel The channel to target, in the form of channel@network
153 */
154 public void setChannel(final String channel) {
/*
P/P * Method: void setChannel(String)
*
* Postconditions:
* this.data == channel
* init'ed(this.data)
* this.type == &com.dmdirc.config.ConfigTarget$TYPE__static_init.new ConfigTarget$TYPE(ConfigTarget$TYPE__static_init#8)
*/
155 type = TYPE.CHANNEL;
156 data = channel;
157 }
158
159 /**
160 * Retrieves the type of this target.
161 *
162 * @return This target's type
163 */
164 public TYPE getType() {
/*
P/P * Method: ConfigTarget$TYPE getType()
*
* Preconditions:
* init'ed(this.type)
*
* Postconditions:
* return_value == this.type
* init'ed(return_value)
*/
165 return type;
166 }
167
168 /**
169 * Returns a string representation of the type of this target.
170 *
171 * @return A string describing this target's type
172 */
173 public String getTypeName() {
/*
P/P * Method: String getTypeName()
*
* Preconditions:
* this.type != null
* (soft) init'ed(com.dmdirc.config.ConfigTarget$1__static_init.new int[](ConfigTarget$1__static_init#1)[...])
*
* Presumptions:
* com.dmdirc.config.ConfigTarget_TYPE:ordinal(...)@174 in {0..7}
*
* Postconditions:
* return_value in Addr_Set{&"globaldefault",&"theme",&"profile",&"ircd",&"network",&"server",&"channel",&"global"}
*
* Test Vectors:
* com.dmdirc.config.ConfigTarget$1__static_init.new int[](ConfigTarget$1__static_init#1)[...]: {1}, {2}, {3}, {4}, {5}, {6}, {7}, {-231..0, 8..232-1}
*/
174 switch(type) {
175 case GLOBALDEFAULT:
176 return "globaldefault";
177 case THEME:
178 return "theme";
179 case PROFILE:
180 return "profile";
181 case IRCD:
182 return "ircd";
183 case NETWORK:
184 return "network";
185 case SERVER:
186 return "server";
187 case CHANNEL:
188 return "channel";
189 default:
190 return "global";
191 }
192 }
193
194 /**
195 * Retrieves the data associated with this target.
196 *
197 * @return This target's data
198 */
199 public String getData() {
/*
P/P * Method: String getData()
*
* Preconditions:
* init'ed(this.data)
*
* Postconditions:
* return_value == this.data
* init'ed(return_value)
*/
200 return data;
201 }
202
203 /** {@inheritDoc} */
204 @Override
205 public int hashCode() {
/*
P/P * Method: int hashCode()
*
* Preconditions:
* this.data != null
* this.type != null
*
* Presumptions:
* com.dmdirc.config.ConfigTarget_TYPE:ordinal(...)@206 + java.lang.String:hashCode(...)@206 in {-231..232-1}
*
* Postconditions:
* init'ed(return_value)
*/
206 return type.ordinal() + data.hashCode();
207 }
208
209 /** {@inheritDoc} */
210 @Override
211 public boolean equals(final Object obj) {
/*
P/P * Method: bool equals(Object)
*
* Preconditions:
* (soft) init'ed(obj.data)
* (soft) init'ed(obj.type)
* (soft) this.data != null
* (soft) init'ed(this.type)
*
* Postconditions:
* init'ed(return_value)
*
* Test Vectors:
* this.type == obj.type: {0}, {1}
* java.lang.String:equals(...)@212: {0}, {1}
*/
212 if (obj instanceof ConfigTarget
213 && type == ((ConfigTarget) obj).getType()
214 && data.equals(((ConfigTarget) obj).getData())) {
215 return true;
216 }
217 return false;
218 }
219
220 /**
221 * Compares this target to another to determine which is more specific.
222 *
223 * @param target The target to compare to
224 * @return a negative integer if this config is less specific, 0 if they're
225 * equal, or a positive integer if this is more specific
226 */
227 public int compareTo(final Object target) {
/*
P/P * Method: int compareTo(Object)
*
* Preconditions:
* target != null
* init'ed(target.type)
* this.type != null
* (soft) init'ed(target.order)
* (soft) target.order - this.order in {-231..232-1}
* (soft) init'ed(this.order)
*
* Postconditions:
* init'ed(return_value)
*
* Test Vectors:
* com.dmdirc.config.ConfigTarget_TYPE:equals(...)@228: {0}, {1}
*/
228 if (type.equals(((ConfigTarget) target).getType())) {
229 return ((ConfigTarget) target).getOrder() - order;
230 } else {
231 return type.compareTo(((ConfigTarget) target).getType());
232 }
233 }
234
235 /**
236 * Returns a string representation of this object.
237 *
238 * @return A string representation of this object
239 */
240 @Override
241 public String toString() {
/*
P/P * Method: String toString()
*
* Preconditions:
* this.type != null
* (soft) init'ed(com.dmdirc.config.ConfigTarget$1__static_init.new int[](ConfigTarget$1__static_init#1)[...])
* (soft) init'ed(this.data)
*
* Presumptions:
* com.dmdirc.config.ConfigTarget_TYPE:ordinal(...)@242 in {0..7}
*
* Postconditions:
* init'ed(java.lang.StringBuilder:toString(...)._tainted)
* return_value in Addr_Set{&"Global defaults",&"Theme",&"Profile",&java.lang.StringBuilder:toString(...),&java.lang.StringBuilder:toString(...),&java.lang.StringBuilder:toString(...),&java.lang.StringBuilder:toString(...),&"Global config"}
*
* Test Vectors:
* com.dmdirc.config.ConfigTarget$1__static_init.new int[](ConfigTarget$1__static_init#1)[...]: {1}, {2}, {3}, {4}, {5}, {6}, {7}, {-231..0, 8..232-1}
*/
242 switch (type) {
243 case GLOBALDEFAULT:
244 return "Global defaults";
245 case THEME:
246 return "Theme";
247 case PROFILE:
248 return "Profile";
249 case IRCD:
250 return "Ircd specific: " + data;
251 case NETWORK:
252 return "Network specific: " + data;
253 case SERVER:
254 return "Server specific: " + data;
255 case CHANNEL:
256 return "Channel specific: " + data;
257 default:
258 return "Global config";
259 }
260 }
261
262 }
SofCheck Inspector Build Version : 2.17854
| ConfigTarget.java |
2009-Jun-25 01:54:24 |
| ConfigTarget.class |
2009-Sep-02 17:04:11 |
| ConfigTarget$1.class |
2009-Sep-02 17:04:11 |
| ConfigTarget$TYPE.class |
2009-Sep-02 17:04:11 |