01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.ide.registry;
11:
12: /**
13: * Instances of this class represent the result of a specific marker
14: * query. Specifically they contain an ordered collection of marker
15: * attribute values.
16: */
17:
18: public class MarkerQueryResult {
19: /**
20: * An ordered collection of marker attribute values.
21: */
22: private String[] values;
23:
24: /**
25: * Cached hash code value
26: */
27: private int hashCode;
28:
29: /**
30: * Creates a new marker query result with the given values.
31: * <p>
32: * The values may not be empty.
33: * </p>
34: *
35: * @param markerAttributeValues the target marker's attribute values
36: */
37: public MarkerQueryResult(String[] markerAttributeValues) {
38: if (markerAttributeValues == null) {
39: throw new IllegalArgumentException();
40: }
41: values = markerAttributeValues;
42: computeHashCode();
43: }
44:
45: /* (non-Javadoc)
46: * Method declared on Object.
47: */
48: public boolean equals(Object o) {
49: if (!(o instanceof MarkerQueryResult)) {
50: return false;
51: }
52:
53: if (o == this ) {
54: return true;
55: }
56:
57: MarkerQueryResult mqr = (MarkerQueryResult) o;
58: if (values.length != mqr.values.length) {
59: return false;
60: }
61:
62: for (int i = 0; i < values.length; i++) {
63: if (!(values[i].equals(mqr.values[i]))) {
64: return false;
65: }
66: }
67:
68: return true;
69: }
70:
71: /* (non-Javadoc)
72: * Method declared on Object.
73: */
74: public int hashCode() {
75: return hashCode;
76: }
77:
78: /**
79: * Computes the hash code for this instance.
80: */
81: public void computeHashCode() {
82: hashCode = 19;
83:
84: for (int i = 0; i < values.length; i++) {
85: hashCode = hashCode * 37 + values[i].hashCode();
86: }
87: }
88: }
|