KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > navigation > LookupAlternative


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc {
21     private final String JavaDoc 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 JavaDoc name, long collectionId, VariantKey navigationDoc, NavigationVersionMode versionMode) {
33         if (name == null)
34             throw new IllegalArgumentException JavaDoc("name argument cannot be null");
35         if (navigationDoc == null)
36             throw new IllegalArgumentException JavaDoc("navigationDoc argument cannot be null");
37
38         this.name = name;
39         this.collectionId = collectionId;
40         this.navigationDoc = navigationDoc;
41         this.versionMode = versionMode;
42     }
43
44     public LookupAlternative(String JavaDoc name, long collectionId, VariantKey navigationDoc) {
45         this(name, collectionId, navigationDoc, NavigationVersionMode.LIVE);
46     }
47
48     public String JavaDoc getName() {
49         return name;
50     }
51
52     public long getCollectionId() {
53         return collectionId;
54     }
55
56     public VariantKey getNavigationDoc() {
57         return navigationDoc;
58     }
59
60     public NavigationVersionMode getVersionMode() {
61         return versionMode;
62     }
63
64     public int compareTo(Object JavaDoc o) {
65         LookupAlternative other = (LookupAlternative)o;
66
67         int nameCompare = name.compareTo(other.name);
68         if (nameCompare != 0)
69             return nameCompare;
70
71         if (collectionId < other.collectionId)
72             return -1;
73         else if (collectionId > other.collectionId)
74             return 1;
75
76         int navDocCompare = navigationDoc.compareTo(other.navigationDoc);
77         if (navDocCompare != 0)
78             return navDocCompare;
79
80         if (versionMode == other.versionMode)
81             return 0;
82         else
83             return versionMode == NavigationVersionMode.LIVE ? -1 : 1;
84     }
85 }
86
Popular Tags