View Javadoc

1   /*
2    * DaCapo Benchmark Maven Plugin
3    * Copyright (C) 2010 Technische Universität Darmstadt
4    * info@scalabench.org
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.scalabench.plugins.dacapo.util;
19  
20  import java.util.Arrays;
21  import java.util.Comparator;
22  import java.util.List;
23  
24  /**
25   * A comparator which treats the following strings, commonly used as the names of input sizes, specially.
26   * 
27   * <ol>
28   *   <li><code>tiny</code></li>
29   *   <li><code>small</code></li>
30   *   <li><code>default</code></li>
31   *   <li><code>large</code></li>
32   *   <li><code>huge</code></li>
33   *   <li><code>gargantuan</code></li>
34   *   <li><code>colossal</code></li>
35   * </ol>
36   * 
37   * All other strings are sorted beyond them.
38   */
39  public final class SizeNameComparator implements Comparator<String> {
40      
41      private static final List<String> STANDARD_SIZES = Arrays.asList(
42              "colossal",
43              "gargantuan",
44              "huge",
45              "large",
46              "default",
47              "small",
48              "tiny");
49      
50      @Override
51      public int compare(String lhs, String rhs) {
52          final int standardResult = STANDARD_SIZES.indexOf(rhs) - STANDARD_SIZES.indexOf(lhs);
53          return standardResult == 0 ? lhs.compareTo(rhs) : standardResult;
54      }
55      
56      /**
57       * Any two instances of {@code SizeNameComparator} are equal, as this class is a state-less function object.
58       */
59      @Override
60      public boolean equals(Object other) {
61          return this.getClass() == other.getClass();
62      }
63      
64      @Override
65      public int hashCode() {
66          return 0;
67      }
68  }