Coverage Summary for Class: LexicographicalOrdering (com.google.common.collect)
| Class | Class, % | Method, % | Line, % |
|---|---|---|---|
| LexicographicalOrdering | 0% (0/1) | 0% (0/5) | 0% (0/23) |
1 /* 2 * Copyright (C) 2007 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.Comparator; 22 import java.util.Iterator; 23 import org.checkerframework.checker.nullness.qual.Nullable; 24 25 /** An ordering which sorts iterables by comparing corresponding elements pairwise. */ 26 @GwtCompatible(serializable = true) 27 final class LexicographicalOrdering<T> extends Ordering<Iterable<T>> implements Serializable { 28 final Comparator<? super T> elementOrder; 29 30 LexicographicalOrdering(Comparator<? super T> elementOrder) { 31 this.elementOrder = elementOrder; 32 } 33 34 @Override 35 public int compare(Iterable<T> leftIterable, Iterable<T> rightIterable) { 36 Iterator<T> left = leftIterable.iterator(); 37 Iterator<T> right = rightIterable.iterator(); 38 while (left.hasNext()) { 39 if (!right.hasNext()) { 40 return LEFT_IS_GREATER; // because it's longer 41 } 42 int result = elementOrder.compare(left.next(), right.next()); 43 if (result != 0) { 44 return result; 45 } 46 } 47 if (right.hasNext()) { 48 return RIGHT_IS_GREATER; // because it's longer 49 } 50 return 0; 51 } 52 53 @Override 54 public boolean equals(@Nullable Object object) { 55 if (object == this) { 56 return true; 57 } 58 if (object instanceof LexicographicalOrdering) { 59 LexicographicalOrdering<?> that = (LexicographicalOrdering<?>) object; 60 return this.elementOrder.equals(that.elementOrder); 61 } 62 return false; 63 } 64 65 @Override 66 public int hashCode() { 67 return elementOrder.hashCode() ^ 2075626741; // meaningless 68 } 69 70 @Override 71 public String toString() { 72 return elementOrder + ".lexicographical()"; 73 } 74 75 private static final long serialVersionUID = 0; 76 }