File Source: IRCTextAttribute.java
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.ui.messages;
24
25 import java.io.InvalidObjectException;
26 import java.text.AttributedCharacterIterator.Attribute;
27 import java.util.HashMap;
28 import java.util.Map;
29
30 /**
31 * Defines attribute keys that can be used to identify text attributes. These
32 * keys are used in AttributedCharacterIterator and AttributedString.
33 */
34 public final class IRCTextAttribute extends Attribute {
35
36 /**
37 * A version number for this class. It should be changed whenever the
38 * class structure is changed (or anything else that would prevent
39 * serialized objects being unserialized with the new class).
40 */
41 private static final long serialVersionUID = 1;
42
43 /** table of all instances in this class, used by readResolve. */
/*
P/P * Method: com.dmdirc.ui.messages.IRCTextAttribute__static_init
*
* Postconditions:
* CHANNEL == &new IRCTextAttribute(IRCTextAttribute__static_init#4)
* HYPERLINK == &new IRCTextAttribute(IRCTextAttribute__static_init#2)
* INSTANCE_MAP == &new HashMap(IRCTextAttribute__static_init#1)
* NICKNAME == &new IRCTextAttribute(IRCTextAttribute__static_init#3)
* SMILEY == &new IRCTextAttribute(IRCTextAttribute__static_init#5)
* init'ed(INSTANCE_MAP)
* new HashMap(IRCTextAttribute__static_init#1) num objects == 1
* new IRCTextAttribute(IRCTextAttribute__static_init#2) num objects == 1
* new IRCTextAttribute(IRCTextAttribute__static_init#3) num objects == 1
* new IRCTextAttribute(IRCTextAttribute__static_init#4) num objects == 1
* ...
*/
44 private static final Map<String, IRCTextAttribute> INSTANCE_MAP
45 = new HashMap<String, IRCTextAttribute>(1);
46
47 /**
48 * Constructs an Attribute with the given name.
49 *
50 * @param name name for the attribute
51 */
52 protected IRCTextAttribute(final String name) {
/*
P/P * Method: void com.dmdirc.ui.messages.IRCTextAttribute(String)
*/
53 super(name);
54 if (this.getClass() == IRCTextAttribute.class) {
55 INSTANCE_MAP.put(name, this);
56 }
57 }
58
59 /**
60 * Resolves instances being deserialized to the predefined constants.
61 *
62 * @return IRCTextAttribute instance
63 *
64 * @throws InvalidObjectException when the class being deserialized is not
65 * an instance of IRCTextAttribute
66 */
67 protected Object readResolve() throws InvalidObjectException {
/*
P/P * Method: Object readResolve()
*
* Presumptions:
* java.util.Map:get(...)@72 != null
*
* Postconditions:
* return_value != null
*/
68 if (this.getClass() != IRCTextAttribute.class) {
69 throw new InvalidObjectException("subclass didn't correctly implement readResolve");
70 }
71
72 final IRCTextAttribute instance = INSTANCE_MAP.get(getName());
73 if (instance == null) {
74 throw new InvalidObjectException("unknown attribute name");
75 } else {
76 return instance;
77 }
78 }
79
80 /** Hyperlink attribute. */
81 public static final IRCTextAttribute HYPERLINK = new IRCTextAttribute("hyperlink");
82
83 /** Nickname attribute. */
84 public static final IRCTextAttribute NICKNAME = new IRCTextAttribute("nickname");
85
86 /** Channel attribute. */
87 public static final IRCTextAttribute CHANNEL = new IRCTextAttribute("channel");
88
89 /** Smiley attribute. */
90 public static final IRCTextAttribute SMILEY = new IRCTextAttribute("smiley");
91 }
SofCheck Inspector Build Version : 2.17854
| IRCTextAttribute.java |
2009-Jun-25 01:54:24 |
| IRCTextAttribute.class |
2009-Sep-02 17:04:17 |