1 11 12 package org.eclipse.ui.views.markers.internal; 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 20 public class MarkerType { 21 private MarkerTypesModel model; 22 23 private String id; 24 25 private String label; 26 27 private String [] supertypeIds; 28 29 32 public MarkerType(MarkerTypesModel model, String id, String label, 33 String [] supertypeIds) { 34 this.model = model; 35 this.id = id; 36 this.label = label; 37 this.supertypeIds = supertypeIds; 38 } 39 40 43 public MarkerType[] getAllSupertypes() { 44 ArrayList result = new ArrayList (); 45 getAllSupertypes(result); 46 return (MarkerType[]) result.toArray(new MarkerType[result.size()]); 47 } 48 49 52 private void getAllSupertypes(ArrayList 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 66 public String getId() { 67 return id; 68 } 69 70 73 public String getLabel() { 74 return label; 75 } 76 77 82 public MarkerType[] getSubtypes() { 83 MarkerType[] types = model.getTypes(); 84 ArrayList result = new ArrayList (); 85 for (int i = 0; i < types.length; ++i) { 86 MarkerType type = types[i]; 87 String [] 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 subTypes = new ArrayList (); 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 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 119 public String [] getSupertypeIds() { 120 return supertypeIds; 121 } 122 123 126 public MarkerType[] getSupertypes() { 127 ArrayList result = new ArrayList (); 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 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 other) { 157 if (!(other instanceof MarkerType)) { 158 return false; 159 } 160 return ((MarkerType) other).getId().equals(this.id); 161 } 162 } 163 | Popular Tags |