Java Code Examples for com.google.common.primitives.Ints#compare()

The following examples show how to use com.google.common.primitives.Ints#compare() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseExceptionHandler.java    From ZjDroid with Apache License 2.0 6 votes vote down vote up
@Override
public int compareTo(@Nonnull ExceptionHandler o) {
    int res;
    String exceptionType = getExceptionType();
    if (exceptionType == null) {
        if (o.getExceptionType() != null) {
            return 1;
        }
    } else {
        String otherExceptionType = o.getExceptionType();
        if (otherExceptionType == null) {
            return -1;
        }
        res = exceptionType.compareTo(o.getExceptionType());
        if (res != 0) return res;
    }
    return Ints.compare(getHandlerCodeAddress(), o.getHandlerCodeAddress());
}
 
Example 2
Source File: CollectionUtils.java    From zjdroid with Apache License 2.0 6 votes vote down vote up
public static <T> int compareAsSet(@Nonnull Comparator<? super T> elementComparator,
                                   @Nonnull Collection<? extends T> list1,
                                   @Nonnull Collection<? extends T> list2) {
    int res = Ints.compare(list1.size(), list2.size());
    if (res != 0) return res;

    SortedSet<? extends T> set1 = toSortedSet(elementComparator, list1);
    SortedSet<? extends T> set2 = toSortedSet(elementComparator, list2);

    Iterator<? extends T> elements2 = set2.iterator();
    for (T element1: set1) {
        res = elementComparator.compare(element1, elements2.next());
        if (res != 0) return res;
    }
    return 0;
}
 
Example 3
Source File: GroupResourceService.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
private Iterable<Group> getOrderedCopy(Iterable<Group> groups) {
    Ordering<Group> byLengthOrdering = new Ordering<>() {
        @Override
        public int compare(Group left, Group right) {
            return Ints.compare(left.getInstancesSize(), right.getInstancesSize());
        }
    };
    return byLengthOrdering.sortedCopy(groups);
}
 
Example 4
Source File: CollectionUtils.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
public static <T extends Comparable<T>> int compareAsSet(@Nonnull Collection<? extends T> set1,
                                                         @Nonnull Collection<? extends T> set2) {
    int res = Ints.compare(set1.size(), set2.size());
    if (res != 0) return res;

    SortedSet<? extends T> sortedSet1 = toNaturalSortedSet(set1);
    SortedSet<? extends T> sortedSet2 = toNaturalSortedSet(set2);

    Iterator<? extends T> elements2 = set2.iterator();
    for (T element1: set1) {
        res = element1.compareTo(elements2.next());
        if (res != 0) return res;
    }
    return 0;
}
 
Example 5
Source File: MinValueFromList.java    From levelup-java-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void find_min_value_from_list_of_integers_guava_ordering() {

	Ordering<Integer> byYear = new Ordering<Integer>() {
		@Override
		public int compare(Integer left, Integer right) {
			return Ints.compare(left, right);
		}
	};

	assertEquals(new Integer(1920), byYear.min(CENTERS_ROOKIE_YEAR));
}
 
Example 6
Source File: CollectionUtils.java    From AppTroy with Apache License 2.0 5 votes vote down vote up
public static <T> int compareAsList(@Nonnull Comparator<? super T> elementComparator,
                                    @Nonnull Collection<? extends T> list1,
                                    @Nonnull Collection<? extends T> list2) {
    int res = Ints.compare(list1.size(), list2.size());
    if (res != 0) return res;
    Iterator<? extends T> elements2 = list2.iterator();
    for (T element1: list1) {
        res = elementComparator.compare(element1, elements2.next());
        if (res != 0) return res;
    }
    return 0;
}
 
Example 7
Source File: CollectionUtils.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
public static <T extends Comparable<T>> int compareAsSet(@Nonnull Collection<? extends T> set1,
                                                         @Nonnull Collection<? extends T> set2) {
    int res = Ints.compare(set1.size(), set2.size());
    if (res != 0) return res;

    SortedSet<? extends T> sortedSet1 = toNaturalSortedSet(set1);
    SortedSet<? extends T> sortedSet2 = toNaturalSortedSet(set2);

    Iterator<? extends T> elements2 = set2.iterator();
    for (T element1: set1) {
        res = element1.compareTo(elements2.next());
        if (res != 0) return res;
    }
    return 0;
}
 
Example 8
Source File: BaseStringEncodedValue.java    From zjdroid with Apache License 2.0 4 votes vote down vote up
@Override
public int compareTo(@Nonnull EncodedValue o) {
    int res = Ints.compare(getValueType(), o.getValueType());
    if (res != 0) return res;
    return getValue().compareTo(((StringEncodedValue)o).getValue());
}
 
Example 9
Source File: BaseNullEncodedValue.java    From ZjDroid with Apache License 2.0 4 votes vote down vote up
@Override
public int compareTo(@Nonnull EncodedValue o) {
    return Ints.compare(getValueType(), o.getValueType());
}
 
Example 10
Source File: BaseFloatEncodedValue.java    From zjdroid with Apache License 2.0 4 votes vote down vote up
@Override
public int compareTo(@Nonnull EncodedValue o) {
    int res = Ints.compare(getValueType(), o.getValueType());
    if (res != 0) return res;
    return Float.compare(getValue(), ((FloatEncodedValue)o).getValue());
}
 
Example 11
Source File: BaseNullEncodedValue.java    From ZjDroid with Apache License 2.0 4 votes vote down vote up
@Override
public int compareTo(@Nonnull EncodedValue o) {
    return Ints.compare(getValueType(), o.getValueType());
}
 
Example 12
Source File: GameInfo.java    From Rails with GNU General Public License v2.0 4 votes vote down vote up
public int compareTo(GameInfo other) {
    return Ints.compare(this.ordering, other.ordering);
}
 
Example 13
Source File: SmaliMethodParameter.java    From ZjDroid with Apache License 2.0 4 votes vote down vote up
@Override public int compare(WithRegister o1, WithRegister o2) {
    return Ints.compare(o1.getRegister(), o2.getRegister());
}
 
Example 14
Source File: BaseCharEncodedValue.java    From AppTroy with Apache License 2.0 4 votes vote down vote up
@Override
public int compareTo(@Nonnull EncodedValue o) {
    int res = Ints.compare(getValueType(), o.getValueType());
    if (res != 0) return res;
    return Chars.compare(getValue(), ((CharEncodedValue)o).getValue());
}
 
Example 15
Source File: IncidentJsonService.java    From glowroot with Apache License 2.0 4 votes vote down vote up
@Override
public int compare(OpenIncident left, OpenIncident right) {
    return Ints.compare(left.severity().getNumber(), right.severity().getNumber());
}
 
Example 16
Source File: BaseEnumEncodedValue.java    From AppTroy with Apache License 2.0 4 votes vote down vote up
@Override
public int compareTo(@Nonnull EncodedValue o) {
    int res = Ints.compare(getValueType(), o.getValueType());
    if (res != 0) return res;
    return getValue().compareTo(((EnumEncodedValue)o).getValue());
}
 
Example 17
Source File: BaseArrayEncodedValue.java    From HeyGirl with Apache License 2.0 4 votes vote down vote up
@Override public int compareTo(@Nonnull EncodedValue o) {
    int res = Ints.compare(getValueType(), o.getValueType());
    if (res != 0) return res;
    return CollectionUtils.compareAsList(getValue(), ((ArrayEncodedValue)o).getValue());
}
 
Example 18
Source File: BaseNullEncodedValue.java    From zjdroid with Apache License 2.0 4 votes vote down vote up
@Override
public int compareTo(@Nonnull EncodedValue o) {
    return Ints.compare(getValueType(), o.getValueType());
}
 
Example 19
Source File: BaseByteEncodedValue.java    From zjdroid with Apache License 2.0 4 votes vote down vote up
@Override
public int compareTo(@Nonnull EncodedValue o) {
    int res = Ints.compare(getValueType(), o.getValueType());
    if (res != 0) return res;
    return Ints.compare(getValue(), ((ByteEncodedValue)o).getValue());
}
 
Example 20
Source File: ProfiledSpan.java    From skywalking with Apache License 2.0 4 votes vote down vote up
@Override
public int compareTo(ProfiledSpan o) {
    return Ints.compare(Integer.parseInt(spanId), Integer.parseInt(o.spanId));
}