001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.internal.activities;
011:
012: import org.eclipse.ui.activities.IActivityRequirementBinding;
013: import org.eclipse.ui.internal.util.Util;
014:
015: public final class ActivityRequirementBinding implements
016: IActivityRequirementBinding {
017: private final static int HASH_FACTOR = 89;
018:
019: private final static int HASH_INITIAL = ActivityRequirementBinding.class
020: .getName().hashCode();
021:
022: private String requiredActivityId;
023:
024: private transient int hashCode = HASH_INITIAL;
025:
026: private String activityId;
027:
028: private transient String string;
029:
030: public ActivityRequirementBinding(String requiredActivityId,
031: String activityId) {
032: if (requiredActivityId == null || activityId == null) {
033: throw new NullPointerException();
034: }
035:
036: this .requiredActivityId = requiredActivityId;
037: this .activityId = activityId;
038: }
039:
040: public int compareTo(Object object) {
041: ActivityRequirementBinding castedObject = (ActivityRequirementBinding) object;
042: int compareTo = Util.compare(requiredActivityId,
043: castedObject.requiredActivityId);
044:
045: if (compareTo == 0) {
046: compareTo = Util.compare(activityId,
047: castedObject.activityId);
048: }
049:
050: return compareTo;
051: }
052:
053: public boolean equals(Object object) {
054: if (!(object instanceof ActivityRequirementBinding)) {
055: return false;
056: }
057:
058: final ActivityRequirementBinding castedObject = (ActivityRequirementBinding) object;
059: if (!Util.equals(requiredActivityId,
060: castedObject.requiredActivityId)) {
061: return false;
062: }
063:
064: return Util.equals(activityId, castedObject.activityId);
065: }
066:
067: public String getRequiredActivityId() {
068: return requiredActivityId;
069: }
070:
071: public String getActivityId() {
072: return activityId;
073: }
074:
075: public int hashCode() {
076: if (hashCode == HASH_INITIAL) {
077: hashCode = hashCode * HASH_FACTOR
078: + Util.hashCode(requiredActivityId);
079: hashCode = hashCode * HASH_FACTOR
080: + Util.hashCode(activityId);
081: if (hashCode == HASH_INITIAL) {
082: hashCode++;
083: }
084: }
085:
086: return hashCode;
087: }
088:
089: public String toString() {
090: if (string == null) {
091: final StringBuffer stringBuffer = new StringBuffer();
092: stringBuffer.append('[');
093: stringBuffer.append(requiredActivityId);
094: stringBuffer.append(',');
095: stringBuffer.append(activityId);
096: stringBuffer.append(']');
097: string = stringBuffer.toString();
098: }
099:
100: return string;
101: }
102: }
|