File Source: StatCountCountComparator.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 StatCountCountComparator implements Comparator, Serializable {
    28  
    29      private static final long serialVersionUID = 4811314286365625712L;
    30      
             /* 
    P/P       *  Method: org.apache.roller.weblogger.pojos.StatCountCountComparator__static_init
              * 
              *  Postconditions:
              *    instance == &new StatCountCountComparator(StatCountCountComparator__static_init#1)
              *    new StatCountCountComparator(StatCountCountComparator__static_init#1) num objects == 1
              */
    31      private static StatCountCountComparator instance = new StatCountCountComparator();
    32  
    33      /**
    34       * 
    35       */
             /* 
    P/P       *  Method: void org.apache.roller.weblogger.pojos.StatCountCountComparator()
              */
    36      private StatCountCountComparator() {
    37  
    38      }
    39  
    40      /** 
    41       * Compares two <em>StatCount</em> instances according to their count values.
    42       * 
    43       * @throws ClassCastException if arguments are not instances of <em>StatCount</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.subjectId != null
                  *    (soft) obj1.typeKey != null
                  *    (soft) init'ed(obj2.subjectId)
                  *    (soft) init'ed(obj2.typeKey)
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  * 
                  *  Test Vectors:
                  *    java.lang.String:compareTo(...)@53: {-231..-1, 1..232-1}, {0}
                  */
    47          StatCount sc1 = (StatCount) obj1;
    48          StatCount sc2 = (StatCount) obj2;
    49          int compVal = sc1.getCount() < sc2.getCount() ? -1 :
    50                  (sc1.getCount() == sc2.getCount() ? 0 : 1);
    51          
    52          if (compVal == 0) {
    53              compVal = sc1.getSubjectId().compareTo(sc2.getSubjectId());
    54              if (compVal == 0) {
    55                  compVal = sc1.getTypeKey().compareTo(sc2.getTypeKey());   
    56              }
    57          }
    58          return compVal;
    59      }
    60  
    61      public static StatCountCountComparator getInstance() {
                 /* 
    P/P           *  Method: StatCountCountComparator getInstance()
                  * 
                  *  Preconditions:
                  *    init'ed(instance)
                  * 
                  *  Postconditions:
                  *    return_value == instance
                  *    init'ed(return_value)
                  */
    62          return instance;
    63      }
    64  }








SofCheck Inspector Build Version : 2.18479
StatCountCountComparator.java 2009-Jan-02 14:24:48
StatCountCountComparator.class 2009-Sep-04 03:12:32