1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.commons.functor.core.comparator;
18
19 import java.io.Serializable;
20 import java.util.Comparator;
21
22 /**
23 * See Commons-Collections for a public version
24 * of this class.
25 *
26 * @version $Revision: 1166339 $ $Date: 2011-09-07 21:43:47 +0200 (Wed, 07 Sep 2011) $
27 * @author Rodney Waldhoff
28 */
29 @SuppressWarnings({ "unchecked", "rawtypes" })
30 final class ComparableComparator implements Comparator, Serializable {
31
32 /** Singleton. */
33 public static final ComparableComparator INSTANCE = new ComparableComparator();
34
35 /**
36 * serialVersionUID declaration.
37 */
38 private static final long serialVersionUID = -5849476573719561212L;
39
40 /**
41 * Create a new ComparableComparator.
42 */
43 public ComparableComparator() {
44 }
45
46 /**
47 * {@inheritDoc}
48 */
49 public int compare(Object o1, Object o2) {
50 return ((Comparable) o1).compareTo(o2);
51 }
52
53 /**
54 * {@inheritDoc}
55 */
56 public boolean equals(Object obj) {
57 return (obj instanceof ComparableComparator);
58 }
59
60 /**
61 * {@inheritDoc}
62 */
63 public int hashCode() {
64 return toString().hashCode();
65 }
66
67 /**
68 * {@inheritDoc}
69 */
70 public String toString() {
71 return "ComparableComparator";
72 }
73
74 /**
75 * Get a ComparableComparator instance.
76 * @return ComparableComparator
77 */
78 public static ComparableComparator instance() {
79 return INSTANCE;
80 }
81
82 }