KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > pojos > BookmarkComparator


1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. The ASF licenses this file to You
4 * under the Apache License, Version 2.0 (the "License"); you may not
5 * 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. For additional information regarding
15 * copyright in this work, please see the NOTICE file in the top level
16 * directory of this distribution.
17 */

18 package org.apache.roller.pojos;
19
20 import java.io.Serializable JavaDoc;
21 import java.util.Comparator JavaDoc;
22
23 public class BookmarkComparator implements Comparator JavaDoc, Serializable JavaDoc
24 {
25     static final long serialVersionUID = 4009699640952161148L;
26     
27     public int compare(Object JavaDoc val1, Object JavaDoc val2)
28     throws ClassCastException JavaDoc
29     {
30         BookmarkData bd1 = (BookmarkData)val1;
31         BookmarkData bd2 = (BookmarkData)val2;
32         int priority1 = bd1.getPriority().intValue();
33         int priority2 = bd2.getPriority().intValue();
34
35         if (priority1 > priority2)
36         {
37             return 1;
38         }
39         else if (priority1 < priority2)
40         {
41             return -1;
42         }
43
44         // if priorities are the same, return
45
// results of String.compareTo()
46
return bd1.getName().compareTo(bd2.getName());
47
48     }
49
50 }
51
Popular Tags