01: /*
02: * Copyright 2004 Outerthought bvba and Schaubroeck nv
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.outerj.daisy.emailnotifier;
17:
18: /**
19: * Identifies a subscription for document in a certain collection
20: * belonging to a certain branch/language.
21: */
22: public class CollectionSubscriptionKey implements Comparable {
23: private final long collectionId;
24: private final long branchId;
25: private final long languageId;
26:
27: public CollectionSubscriptionKey(long collectionId, long branchId,
28: long languageId) {
29: this .collectionId = collectionId;
30: this .branchId = branchId;
31: this .languageId = languageId;
32: }
33:
34: public long getCollectionId() {
35: return collectionId;
36: }
37:
38: public long getBranchId() {
39: return branchId;
40: }
41:
42: public long getLanguageId() {
43: return languageId;
44: }
45:
46: public int hashCode() {
47: // The calculation technique for this hashcode is taken from the HashCodeBuilder
48: // of Jakarta Commons Lang, which in itself is based on techniques from the
49: // "Effective Java" book by Joshua Bloch.
50: final int iConstant = 159;
51: int iTotal = 615;
52:
53: iTotal = appendHash(collectionId, iTotal, iConstant);
54: iTotal = appendHash(branchId, iTotal, iConstant);
55: iTotal = appendHash(languageId, iTotal, iConstant);
56:
57: return iTotal;
58: }
59:
60: private int appendHash(long value, int iTotal, int iConstant) {
61: return iTotal * iConstant + ((int) (value ^ (value >> 32)));
62: }
63:
64: public boolean equals(Object obj) {
65: if (obj == this ) {
66: return true;
67: } else if (obj instanceof CollectionSubscriptionKey) {
68: CollectionSubscriptionKey otherKey = (CollectionSubscriptionKey) obj;
69: return (this .collectionId == otherKey.collectionId
70: && this .branchId == otherKey.branchId && this .languageId == otherKey.languageId);
71: }
72:
73: return false;
74: }
75:
76: public int compareTo(Object o) {
77: CollectionSubscriptionKey otherKey = (CollectionSubscriptionKey) o;
78: if (collectionId == otherKey.collectionId) {
79: if (branchId == otherKey.branchId) {
80: if (languageId == otherKey.languageId) {
81: return 0;
82: } else if (languageId < otherKey.languageId) {
83: return -1;
84: } else {
85: return 1;
86: }
87: } else if (branchId < otherKey.branchId) {
88: return -1;
89: } else {
90: return 1;
91: }
92: } else if (collectionId < otherKey.collectionId) {
93: return -1;
94: } else {
95: return 1;
96: }
97: }
98: }
|