KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > bridge > IdentifierArrayProperty


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.java.bridge;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Arrays JavaDoc;
24 import java.util.List JavaDoc;
25
26 import org.openide.src.Element;
27 import org.openide.src.Identifier;
28
29 /**
30  * Support for multivalued properties holding identifier arrays and advanced change
31  * detection and property firing. The support is implemented as a flyweight, so it does
32  * not contain any state-specific fields, but is bound to a property and bean class.
33  * Concrete subclass will add methods for accessing state of the bean.
34  *
35  * @author sdedic
36  * @version
37  */

38 abstract class IdentifierArrayProperty extends FlyweightIndexedProperty {
39     /** Tag value (and performance enhancement) for properties with no identifiers
40      * in them.
41      */

42     static final Identifier[] EMPTY = new Identifier[0];
43
44     /** Constructs the flyweight and binds it to a property name.
45      */

46     public IdentifierArrayProperty(String JavaDoc propName) {
47         super(propName);
48     }
49
50     /** Returns the tag value for an empty array of identifiers.
51      */

52     protected final Object JavaDoc[] createValue(int size) {
53         return size == 0 ? EMPTY : new Identifier[size];
54     }
55     
56     protected final Object JavaDoc[] createEmpty() {
57         return EMPTY;
58     }
59
60     protected boolean compareValues(Object JavaDoc one, Object JavaDoc two) {
61         // assume both are identifiers.
62
Identifier id1 = (Identifier)one;
63         Identifier id2 = (Identifier)two;
64
65         return MemberElementImpl.compareSourceIdentifiers(id1, id2);
66     }
67     
68     protected boolean compareValuesForRemove(Object JavaDoc one, Object JavaDoc two) {
69         Identifier id1 = (Identifier)one;
70         Identifier id2 = (Identifier)two;
71         return id1.compareTo(id2, false);
72     }
73 }
74
75
Popular Tags