KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > activities > ActivityRequirementBinding


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.internal.activities;
13
14 import org.eclipse.ui.activities.IActivityRequirementBinding;
15 import org.eclipse.ui.internal.util.Util;
16
17 public final class ActivityRequirementBinding implements
18         IActivityRequirementBinding {
19     private final static int HASH_FACTOR = 89;
20
21     private final static int HASH_INITIAL = ActivityRequirementBinding.class
22             .getName().hashCode();
23
24     private String JavaDoc requiredActivityId;
25
26     private transient int hashCode = HASH_INITIAL;
27
28     private String JavaDoc activityId;
29
30     private transient String JavaDoc string;
31
32     public ActivityRequirementBinding(String JavaDoc requiredActivityId,
33             String JavaDoc activityId) {
34         if (requiredActivityId == null || activityId == null) {
35             throw new NullPointerException JavaDoc();
36         }
37
38         this.requiredActivityId = requiredActivityId;
39         this.activityId = activityId;
40     }
41
42     public int compareTo(Object JavaDoc object) {
43         ActivityRequirementBinding castedObject = (ActivityRequirementBinding) object;
44         int compareTo = Util.compare(requiredActivityId,
45                 castedObject.requiredActivityId);
46
47         if (compareTo == 0) {
48             compareTo = Util.compare(activityId, castedObject.activityId);
49         }
50
51         return compareTo;
52     }
53
54     public boolean equals(Object JavaDoc object) {
55         if (!(object instanceof ActivityRequirementBinding)) {
56             return false;
57         }
58
59         final ActivityRequirementBinding castedObject = (ActivityRequirementBinding) object;
60         if (!Util.equals(requiredActivityId, castedObject.requiredActivityId)) {
61             return false;
62         }
63
64         return Util.equals(activityId, castedObject.activityId);
65     }
66
67     public String JavaDoc getRequiredActivityId() {
68         return requiredActivityId;
69     }
70
71     public String JavaDoc getActivityId() {
72         return activityId;
73     }
74
75     public int hashCode() {
76         if (hashCode == HASH_INITIAL) {
77             hashCode = hashCode * HASH_FACTOR
78                     + Util.hashCode(requiredActivityId);
79             hashCode = hashCode * HASH_FACTOR + Util.hashCode(activityId);
80             if (hashCode == HASH_INITIAL) {
81                 hashCode++;
82             }
83         }
84
85         return hashCode;
86     }
87
88     public String JavaDoc toString() {
89         if (string == null) {
90             final StringBuffer JavaDoc stringBuffer = new StringBuffer JavaDoc();
91             stringBuffer.append('[');
92             stringBuffer.append(requiredActivityId);
93             stringBuffer.append(',');
94             stringBuffer.append(activityId);
95             stringBuffer.append(']');
96             string = stringBuffer.toString();
97         }
98
99         return string;
100     }
101 }
102
Popular Tags