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.ICategoryActivityBinding;
013: import org.eclipse.ui.internal.util.Util;
014:
015: public final class CategoryActivityBinding implements
016: ICategoryActivityBinding {
017: private final static int HASH_FACTOR = 89;
018:
019: private final static int HASH_INITIAL = CategoryActivityBinding.class
020: .getName().hashCode();
021:
022: private String activityId;
023:
024: private String categoryId;
025:
026: private transient int hashCode = HASH_INITIAL;
027:
028: private transient String string;
029:
030: public CategoryActivityBinding(String activityId, String categoryId) {
031: if (activityId == null || categoryId == null) {
032: throw new NullPointerException();
033: }
034:
035: this .activityId = activityId;
036: this .categoryId = categoryId;
037: }
038:
039: public int compareTo(Object object) {
040: CategoryActivityBinding castedObject = (CategoryActivityBinding) object;
041: int compareTo = Util.compare(activityId,
042: castedObject.activityId);
043:
044: if (compareTo == 0) {
045: compareTo = Util.compare(categoryId,
046: castedObject.categoryId);
047: }
048:
049: return compareTo;
050: }
051:
052: public boolean equals(Object object) {
053: if (!(object instanceof CategoryActivityBinding)) {
054: return false;
055: }
056:
057: final CategoryActivityBinding castedObject = (CategoryActivityBinding) object;
058: if (!Util.equals(activityId, castedObject.activityId)) {
059: return false;
060: }
061:
062: return Util.equals(categoryId, castedObject.categoryId);
063: }
064:
065: public String getActivityId() {
066: return activityId;
067: }
068:
069: public String getCategoryId() {
070: return categoryId;
071: }
072:
073: public int hashCode() {
074: if (hashCode == HASH_INITIAL) {
075: hashCode = hashCode * HASH_FACTOR
076: + Util.hashCode(activityId);
077: hashCode = hashCode * HASH_FACTOR
078: + Util.hashCode(categoryId);
079: if (hashCode == HASH_INITIAL) {
080: hashCode++;
081: }
082: }
083:
084: return hashCode;
085: }
086:
087: public String toString() {
088: if (string == null) {
089: final StringBuffer stringBuffer = new StringBuffer();
090: stringBuffer.append('[');
091: stringBuffer.append(activityId);
092: stringBuffer.append(',');
093: stringBuffer.append(categoryId);
094: stringBuffer.append(']');
095: string = stringBuffer.toString();
096: }
097:
098: return string;
099: }
100: }
|