Home | History | Annotate | Download | only in collect
      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 
     21 import java.io.Serializable;
     22 import java.util.List;
     23 
     24 import javax.annotation.Nullable;
     25 
     26 /**
     27  * An ordering that treats all references as equals, even nulls.
     28  *
     29  * @author Emily Soldal
     30  */
     31 @GwtCompatible(serializable = true)
     32 final class AllEqualOrdering extends Ordering<Object> implements Serializable {
     33   static final AllEqualOrdering INSTANCE = new AllEqualOrdering();
     34 
     35   @Override
     36   public int compare(@Nullable Object left, @Nullable Object right) {
     37     return 0;
     38   }
     39 
     40   @Override
     41   public <E> List<E> sortedCopy(Iterable<E> iterable) {
     42     return Lists.newArrayList(iterable);
     43   }
     44 
     45   @Override
     46   public <E> ImmutableList<E> immutableSortedCopy(Iterable<E> iterable) {
     47     return ImmutableList.copyOf(iterable);
     48   }
     49 
     50   @SuppressWarnings("unchecked")
     51   @Override
     52   public <S> Ordering<S> reverse() {
     53     return (Ordering<S>) this;
     54   }
     55 
     56   private Object readResolve() {
     57     return INSTANCE;
     58   }
     59 
     60   @Override
     61   public String toString() {
     62     return "Ordering.allEqual()";
     63   }
     64 
     65   private static final long serialVersionUID = 0;
     66 }
     67