01: /*******************************************************************************
02: * Copyright (c) 2004, 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.dialogs;
11:
12: import org.eclipse.core.runtime.Assert;
13:
14: /**
15: * A preference history entry.
16: *
17: * @since 3.1
18: */
19: final class PreferenceHistoryEntry {
20: private String id;
21: private String label;
22: private Object argument;
23:
24: /**
25: * Creates a new entry.
26: *
27: * @param id the preference page id
28: * @param label the label to display, usually the preference page label
29: * @param argument an argument to pass to the preference page, may be
30: * <code>null</code>
31: */
32: public PreferenceHistoryEntry(String id, String label,
33: Object argument) {
34: Assert.isLegal(id != null);
35: Assert.isLegal(label != null);
36: this .id = id;
37: this .label = label;
38: this .argument = argument;
39: }
40:
41: /**
42: * Returns the preference page id.
43: *
44: * @return the preference page id
45: */
46: public String getId() {
47: return id;
48: }
49:
50: /**
51: * Returns the preference page argument.
52: *
53: * @return the preference page argument
54: */
55: public Object getArgument() {
56: return argument;
57: }
58:
59: /**
60: * Returns the preference page label.
61: *
62: * @return the preference page label
63: */
64: public String getLabel() {
65: return label;
66: }
67:
68: /*
69: * @see java.lang.Object#toString()
70: */
71: public String toString() {
72: if (argument == null) {
73: return id;
74: }
75: return id + "(" + argument + ")"; //$NON-NLS-1$ //$NON-NLS-2$
76: }
77:
78: /*
79: * @see java.lang.Object#equals(java.lang.Object)
80: */
81: public boolean equals(Object obj) {
82: if (obj instanceof PreferenceHistoryEntry) {
83: PreferenceHistoryEntry other = (PreferenceHistoryEntry) obj;
84: return id.equals(other.id)
85: && (argument == null && other.argument == null || argument
86: .equals(other.argument));
87: }
88: return super .equals(obj);
89: }
90:
91: /*
92: * @see java.lang.Object#hashCode()
93: */
94: public int hashCode() {
95: int argHash = argument == null ? 0
96: : argument.hashCode() & 0x0000ffff;
97: return id.hashCode() << 16 | argHash;
98: }
99: }
|