KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > views > markers > internal > MarkerType


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.ui.views.markers.internal;
13
14 import java.util.ArrayList JavaDoc;
15 import java.util.List JavaDoc;
16
17 /**
18  * Represents a marker type.
19  */

20 public class MarkerType {
21     private MarkerTypesModel model;
22
23     private String JavaDoc id;
24
25     private String JavaDoc label;
26
27     private String JavaDoc[] supertypeIds;
28
29     /**
30      * Creates a new marker type.
31      */

32     public MarkerType(MarkerTypesModel model, String JavaDoc id, String JavaDoc label,
33             String JavaDoc[] supertypeIds) {
34         this.model = model;
35         this.id = id;
36         this.label = label;
37         this.supertypeIds = supertypeIds;
38     }
39
40     /**
41      * Returns all this type's supertypes.
42      */

43     public MarkerType[] getAllSupertypes() {
44         ArrayList JavaDoc result = new ArrayList JavaDoc();
45         getAllSupertypes(result);
46         return (MarkerType[]) result.toArray(new MarkerType[result.size()]);
47     }
48
49     /**
50      * Appends all this type's supertypes to the given list.
51      */

52     private void getAllSupertypes(ArrayList JavaDoc result) {
53         MarkerType[] supers = getSupertypes();
54         for (int i = 0; i < supers.length; ++i) {
55             MarkerType sup = supers[i];
56             if (!result.contains(sup)) {
57                 result.add(sup);
58                 sup.getAllSupertypes(result);
59             }
60         }
61     }
62
63     /**
64      * Returns the marker type id.
65      */

66     public String JavaDoc getId() {
67         return id;
68     }
69
70     /**
71      * Returns the human-readable label for this marker type.
72      */

73     public String JavaDoc getLabel() {
74         return label;
75     }
76
77     /**
78      * Returns the types which have this type as a direct supertype.
79      *
80      * @return the direct subtypes of this type
81      */

82     public MarkerType[] getSubtypes() {
83         MarkerType[] types = model.getTypes();
84         ArrayList JavaDoc result = new ArrayList JavaDoc();
85         for (int i = 0; i < types.length; ++i) {
86             MarkerType type = types[i];
87             String JavaDoc[] supers = type.getSupertypeIds();
88             for (int j = 0; j < supers.length; ++j) {
89                 if (supers[j].equals(id)) {
90                     result.add(type);
91                 }
92             }
93         }
94         return (MarkerType[]) result.toArray(new MarkerType[result.size()]);
95     }
96
97     public MarkerType[] getAllSubTypes() {
98         List JavaDoc subTypes = new ArrayList JavaDoc();
99         addSubTypes(subTypes, this);
100         MarkerType[] subs = new MarkerType[subTypes.size()];
101         subTypes.toArray(subs);
102         return subs;
103     }
104
105     private void addSubTypes(List JavaDoc list, MarkerType superType) {
106         MarkerType[] subTypes = superType.getSubtypes();
107         for (int i = 0; i < subTypes.length; i++) {
108             MarkerType subType = subTypes[i];
109             if (!list.contains(subType)) {
110                 list.add(subType);
111             }
112             addSubTypes(list, subType);
113         }
114     }
115
116     /**
117      * Returns the marker type ids for this type's supertypes.
118      */

119     public String JavaDoc[] getSupertypeIds() {
120         return supertypeIds;
121     }
122
123     /**
124      * Returns this type's direct supertypes.
125      */

126     public MarkerType[] getSupertypes() {
127         ArrayList JavaDoc result = new ArrayList JavaDoc();
128         for (int i = 0; i < supertypeIds.length; ++i) {
129             MarkerType sup = model.getType(supertypeIds[i]);
130             if (sup != null) {
131                 result.add(sup);
132             }
133         }
134         return (MarkerType[]) result.toArray(new MarkerType[result.size()]);
135     }
136
137     /**
138      * Returns whether this marker type is considered to be a subtype of
139      * the given marker type.
140      *
141      * @return boolean <code>true</code>if this type is the same as (or a subtype of) the given type
142      */

143     public boolean isSubtypeOf(MarkerType superType) {
144         if (id.equals(superType.getId())) {
145             return true;
146         }
147         for (int i = 0; i < supertypeIds.length; ++i) {
148             MarkerType sup = model.getType(supertypeIds[i]);
149             if (sup != null && sup.isSubtypeOf(superType)) {
150                 return true;
151             }
152         }
153         return false;
154     }
155
156     public boolean equals(Object JavaDoc other) {
157         if (!(other instanceof MarkerType)) {
158             return false;
159         }
160         return ((MarkerType) other).getId().equals(this.id);
161     }
162 }
163
Popular Tags