File Source: TagStatCountComparator.java
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
19 package org.apache.roller.weblogger.pojos;
20
21 import java.util.Comparator;
22 import java.io.Serializable;
23
24 /**
25 * @author Markus Fuchs
26 */
27 public class TagStatCountComparator implements Comparator, Serializable {
28
29 private static final long serialVersionUID = 1155112837815739929L;
30
31 private static TagStatCountComparator instance = new TagStatCountComparator();
32
33 /**
34 *
35 */
36 public TagStatCountComparator() {
37
38 }
39
40 /**
41 * Compares two <em>TagStat</em> instances according to their count values.
42 *
43 * @throws ClassCastException if arguments are not instances of <em>TagStat</em>
44 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
45 */
46 public int compare(Object obj1, Object obj2) throws ClassCastException {
/*
P/P * Method: int compare(Object, Object)
*
* Preconditions:
* obj1 != null
* init'ed(obj1.count)
* obj2 != null
* init'ed(obj2.count)
* (soft) obj1.name != null
* (soft) init'ed(obj2.name)
*
* Postconditions:
* init'ed(return_value)
*/
47 TagStat st1 = (TagStat) obj1;
48 TagStat st2 = (TagStat) obj2;
49 int compVal = st1.getCount() < st2.getCount() ? -1 :
50 (st1.getCount() == st2.getCount() ? 0 : 1);
51
52 if (compVal == 0) {
53 compVal = st1.getName().compareTo(st2.getName());
54 }
55 return compVal;
56 }
57
58 public static TagStatCountComparator getInstance() {
/*
P/P * Method: TagStatCountComparator getInstance()
*
* Preconditions:
* init'ed(instance)
*
* Postconditions:
* return_value == instance
* init'ed(return_value)
*/
59 return instance;
60 }
61 }
SofCheck Inspector Build Version : 2.18479
| TagStatCountComparator.java |
2009-Jan-02 14:25:38 |
| TagStatCountComparator.class |
2009-Sep-04 03:12:32 |