View Javadoc
1   /*
2    * Copyright (C) 2012 The Guava Authors
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not 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.
15   */
16  
17  package com.google.common.collect;
18  
19  import com.google.common.annotations.GwtCompatible;
20  import java.io.Serializable;
21  import java.util.List;
22  import javax.annotation.Nullable;
23  
24  /**
25   * An ordering that treats all references as equals, even nulls.
26   *
27   * @author Emily Soldal
28   */
29  @GwtCompatible(serializable = true)
30  final class AllEqualOrdering extends Ordering<Object> implements Serializable {
31    static final AllEqualOrdering INSTANCE = new AllEqualOrdering();
32  
33    @Override
34    public int compare(@Nullable Object left, @Nullable Object right) {
35      return 0;
36    }
37  
38    @Override
39    public <E> List<E> sortedCopy(Iterable<E> iterable) {
40      return Lists.newArrayList(iterable);
41    }
42  
43    @Override
44    public <E> ImmutableList<E> immutableSortedCopy(Iterable<E> iterable) {
45      return ImmutableList.copyOf(iterable);
46    }
47  
48    @SuppressWarnings("unchecked")
49    @Override
50    public <S> Ordering<S> reverse() {
51      return (Ordering<S>) this;
52    }
53  
54    private Object readResolve() {
55      return INSTANCE;
56    }
57  
58    @Override
59    public String toString() {
60      return "Ordering.allEqual()";
61    }
62  
63    private static final long serialVersionUID = 0;
64  }