001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package com.sun.jsfcl.std.reference;
042:
043: import java.util.ArrayList;
044: import java.util.Collections;
045: import java.util.List;
046: import java.util.regex.Matcher;
047: import java.util.regex.Pattern;
048:
049: /**
050: * @author eric
051: *
052: * TODO To change the template for this generated type comment go to
053: * Window - Preferences - Java - Code Generation - Code and Comments
054: */
055: public class ReferenceDataItem implements Comparable {
056:
057: protected ReferenceDataItem aliasFor;
058: protected boolean isUnsetMarker;
059: protected boolean isRemovable;
060: protected String name;
061: protected Object value;
062: protected String javaInitializationString;
063:
064: public static ArrayList sorted(List items) {
065: ArrayList result;
066:
067: result = new ArrayList(items.size());
068: result.addAll(items);
069: Collections.sort(result);
070: return result;
071: }
072:
073: protected ReferenceDataItem(String name, Object value,
074: String javaInitializationString, boolean isUnsetMarker,
075: boolean isRemovable, ReferenceDataItem aliasFor) {
076:
077: super ();
078: this .name = name;
079: this .value = value;
080: this .javaInitializationString = javaInitializationString;
081: this .isUnsetMarker = isUnsetMarker;
082: this .isRemovable = isRemovable;
083: this .aliasFor = aliasFor;
084: }
085:
086: public int compareTo(Object object) {
087: ReferenceDataItem otherItem;
088:
089: otherItem = (ReferenceDataItem) object;
090: return getName().compareToIgnoreCase(otherItem.getName());
091: }
092:
093: public boolean equals(Object object) {
094:
095: if (object instanceof ReferenceDataItem) {
096: return equals((ReferenceDataItem) object);
097: }
098: return false;
099: }
100:
101: public boolean equals(ReferenceDataItem other) {
102:
103: if (value != null && other.value != null) {
104: if (value.equals(other.value)) {
105: return true;
106: }
107: }
108: return false;
109: }
110:
111: public ReferenceDataItem getAliasFor() {
112:
113: return aliasFor;
114: }
115:
116: public String getDisplayString() {
117:
118: if (value instanceof String) {
119: return (String) value;
120: }
121: return name;
122: }
123:
124: public String getJavaInitializationString() {
125:
126: return javaInitializationString;
127: }
128:
129: public String getName() {
130:
131: return name;
132: }
133:
134: public Object getValue() {
135:
136: return value;
137: }
138:
139: public int hashCode() {
140:
141: if (value == null) {
142: return 0;
143: }
144: return value.hashCode();
145: }
146:
147: public boolean isRemovable() {
148:
149: return isRemovable;
150: }
151:
152: public boolean isUnsetMarker() {
153:
154: return isUnsetMarker;
155: }
156:
157: public boolean matchesPattern(Pattern pattern) {
158:
159: Matcher matcher = pattern.matcher(getName());
160: if (matcher.matches()) {
161: return true;
162: }
163: if (getValue() instanceof String) {
164: matcher = pattern.matcher((String) getValue());
165: if (matcher.matches()) {
166: return true;
167: }
168: }
169: return false;
170: }
171:
172: public void setIsRemovable(boolean isRemovable) {
173:
174: this .isRemovable = isRemovable;
175: }
176:
177: public void setIsUnsetMarker(boolean isUnsetValue) {
178:
179: this .isUnsetMarker = isUnsetValue;
180: }
181:
182: public void setJavaInitializationString(String string) {
183:
184: javaInitializationString = string;
185: }
186:
187: }
|