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.navigation;
17:
18: import org.outerj.daisy.repository.VariantKey;
19:
20: public class LookupAlternative implements Comparable {
21: private final String name;
22: private final long collectionId;
23: private final VariantKey navigationDoc;
24: private final NavigationVersionMode versionMode;
25:
26: /**
27: *
28: * @param name a name that identifies this lookup alternative
29: * @param collectionId the collection this lookup alternative is associated with
30: * @param navigationDoc the navigation doc for this lookup alternative
31: */
32: public LookupAlternative(String name, long collectionId,
33: VariantKey navigationDoc, NavigationVersionMode versionMode) {
34: if (name == null)
35: throw new IllegalArgumentException(
36: "name argument cannot be null");
37: if (navigationDoc == null)
38: throw new IllegalArgumentException(
39: "navigationDoc argument cannot be null");
40:
41: this .name = name;
42: this .collectionId = collectionId;
43: this .navigationDoc = navigationDoc;
44: this .versionMode = versionMode;
45: }
46:
47: public LookupAlternative(String name, long collectionId,
48: VariantKey navigationDoc) {
49: this (name, collectionId, navigationDoc,
50: NavigationVersionMode.LIVE);
51: }
52:
53: public String getName() {
54: return name;
55: }
56:
57: public long getCollectionId() {
58: return collectionId;
59: }
60:
61: public VariantKey getNavigationDoc() {
62: return navigationDoc;
63: }
64:
65: public NavigationVersionMode getVersionMode() {
66: return versionMode;
67: }
68:
69: public int compareTo(Object o) {
70: LookupAlternative other = (LookupAlternative) o;
71:
72: int nameCompare = name.compareTo(other.name);
73: if (nameCompare != 0)
74: return nameCompare;
75:
76: if (collectionId < other.collectionId)
77: return -1;
78: else if (collectionId > other.collectionId)
79: return 1;
80:
81: int navDocCompare = navigationDoc
82: .compareTo(other.navigationDoc);
83: if (navDocCompare != 0)
84: return navDocCompare;
85:
86: if (versionMode == other.versionMode)
87: return 0;
88: else
89: return versionMode == NavigationVersionMode.LIVE ? -1 : 1;
90: }
91: }
|