1 11 package org.eclipse.ui.internal.ide.registry; 12 13 import org.eclipse.core.resources.IMarker; 14 import org.eclipse.core.runtime.CoreException; 15 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; 16 17 23 public class MarkerQuery { 24 28 private String type; 29 30 35 private String [] attributes; 36 37 40 private int hashCode; 41 42 53 public MarkerQuery(String markerType, String [] markerAttributes) { 54 if (markerAttributes == null) { 55 throw new IllegalArgumentException (); 56 } 57 58 type = markerType; 59 attributes = markerAttributes; 60 computeHashCode(); 61 } 62 63 74 public MarkerQueryResult performQuery(IMarker marker) { 75 try { 77 if (type != null && !type.equals(marker.getType())) { 78 return null; 79 } 80 } catch (CoreException e) { 81 IDEWorkbenchPlugin 82 .log("Error accessing marker type", e.getStatus()); return null; 84 } 85 86 String [] values = new String [attributes.length]; 88 for (int i = 0; i < attributes.length; i++) { 89 try { 90 Object value = marker.getAttribute(attributes[i]); 91 if (value == null) { 92 return null; 93 } 94 values[i] = value.toString(); 95 } catch (CoreException e) { 96 IDEWorkbenchPlugin.log( 97 "Error accessing marker attribute", e.getStatus()); return null; 99 } 100 } 101 102 return new MarkerQueryResult(values); 104 } 105 106 109 public boolean equals(Object o) { 110 if (!(o instanceof MarkerQuery)) { 111 return false; 112 } 113 114 if (o == this) { 115 return true; 116 } 117 118 MarkerQuery mq = (MarkerQuery) o; 119 if (!(type == null ? mq.type == null : type.equals(mq.type))) { 120 return false; 121 } 122 123 if (attributes.length != mq.attributes.length) { 124 return false; 125 } 126 127 for (int i = 0; i < attributes.length; i++) { 128 if (!(attributes[i].equals(mq.attributes[i]))) { 129 return false; 130 } 131 } 132 133 return true; 134 } 135 136 139 public int hashCode() { 140 return hashCode; 141 } 142 143 146 public void computeHashCode() { 147 hashCode = 19; 148 149 if (type != null) { 150 hashCode = hashCode * 37 + type.hashCode(); 151 } 152 153 for (int i = 0; i < attributes.length; i++) { 154 hashCode = hashCode * 37 + attributes[i].hashCode(); 155 } 156 } 157 158 164 public String getType() { 165 return type; 166 } 167 168 174 public String [] getAttributes() { 175 return attributes; 176 } 177 } 178 179 | Popular Tags |