Example usage for com.google.common.collect ComparisonChain start

List of usage examples for com.google.common.collect ComparisonChain start

Introduction

In this page you can find the example usage for com.google.common.collect ComparisonChain start.

Prototype

public static ComparisonChain start() 

Source Link

Document

Begins a new chained comparison statement.

Usage

From source file:com.dmdirc.addons.ui_swing.components.NicklistComparator.java

@Override
public int compare(final GroupChatUser client1, final GroupChatUser client2) {
    ComparisonChain comparisonChain = ComparisonChain.start();
    if (sortByMode) {
        comparisonChain = comparisonChain.compare(client1.getAllModes(), client2.getAllModes(),
                client1.getModeComparator());
    }/*from  www .  ja  v  a2s .c  om*/
    if (sortByCase) {
        comparisonChain = comparisonChain.compare(client1.getNickname(), client2.getNickname());
    } else {
        comparisonChain = comparisonChain.compare(client1.getNickname().toLowerCase(),
                client2.getNickname().toLowerCase());
    }
    return comparisonChain.result();
}

From source file:org.sosy_lab.cpachecker.cpa.smg.objects.sll.SMGSingleLinkedListShape.java

@Override
public int compareTo(SMGSingleLinkedListShape other) {
    return ComparisonChain.start().compare(nfo, other.nfo, Ordering.<Integer>natural().nullsFirst())
            .compare(hfo, other.hfo, Ordering.<Integer>natural().nullsFirst()).result();
}

From source file:io.druid.timeline.partition.NumberedPartitionChunk.java

@Override
public int compareTo(PartitionChunk<T> other) {
    if (other instanceof NumberedPartitionChunk) {
        final NumberedPartitionChunk castedOther = (NumberedPartitionChunk) other;
        return ComparisonChain.start().compare(chunks, castedOther.chunks)
                .compare(chunkNumber, castedOther.chunkNumber).result();
    } else {//from   w w w.jav a  2s. co  m
        throw new IllegalArgumentException(
                "Cannot compare against something that is not a NumberedPartitionChunk.");
    }
}

From source file:me.yanaga.opes.Email.java

@Override
public int compareTo(Email o) {
    return ComparisonChain.start().compare(this.value, o.value).result();
}

From source file:com.facebook.buck.model.Pair.java

/**
 * Provides a comparison using the natural ordering of contained types (which my be comparable).
 *//* w ww  .  j av a2  s.  co  m*/
public static <FIRST extends Comparable<FIRST>, SECOND extends Comparable<SECOND>> Comparator<Pair<FIRST, SECOND>> comparator() {
    return new Comparator<Pair<FIRST, SECOND>>() {
        @Override
        public int compare(Pair<FIRST, SECOND> o1, Pair<FIRST, SECOND> o2) {
            if (o1 == o2) {
                return 0;
            }

            return ComparisonChain.start().compare(o1.first, o2.first).compare(o1.second, o2.second).result();
        }
    };
}

From source file:fr.xebia.cocktail.Cocktail.java

@Override
public int compareTo(Cocktail other) {
    return ComparisonChain.start() //
            .compare(this.name, other.name) //
            .result();//  w w  w  . j  av a  2s  .co m
}

From source file:org.apache.jackrabbit.oak.segment.PropertyTemplate.java

@Override
public int compareTo(@Nonnull PropertyTemplate template) {
    checkNotNull(template);/*from ww w  .j a  va2  s .c  o m*/
    return ComparisonChain.start().compare(hashCode(), template.hashCode()) // important
            .compare(name, template.name).compare(type, template.type).result();
}

From source file:org.apache.isis.applib.util.ObjectContracts.java

private static <T> int compare(final T p, final T q, final Iterable<String> propertyNamesIter) {
    final Iterable<Clause> clauses = clausesFor(propertyNamesIter);
    ComparisonChain chain = ComparisonChain.start();
    for (final Clause clause : clauses) {
        final Comparable<T> propertyValueOfP = (Comparable<T>) clause.getValueOf(p);
        final Comparable<T> propertyValueOfQ = (Comparable<T>) clause.getValueOf(q);
        chain = chain.compare(propertyValueOfP, propertyValueOfQ, clause.getDirection().getOrdering());
    }//ww w.  j  a  va2  s .  co  m
    return chain.result();
}

From source file:org.n52.iceland.ds.OperationHandlerKey.java

@Override
public int compareTo(OperationHandlerKey o) {
    return ComparisonChain.start().compare(getService(), o.getService())
            .compare(getOperationName(), o.getOperationName()).result();
}

From source file:org.onlab.util.LongBandwidth.java

@Override
public int compareTo(Bandwidth other) {
    if (other instanceof LongBandwidth) {
        return ComparisonChain.start().compare(this.bps, ((LongBandwidth) other).bps).result();
    }/*from w w  w  .j a v  a 2s. co  m*/
    return ComparisonChain.start().compare(this.bps, other.bps()).result();
}