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:org.onebusaway.transit_data_federation.bundle.tasks.stif.model.RunTripEntry.java

@Override
public int compareTo(RunTripEntry other) {

    if (this == other)
        return 0;

    int res = ComparisonChain.start().compare(entry.getId(), other.getTripEntry().getId())
            .compare(runId, other.runId).compare(reliefTime, other.reliefTime).compare(relief, other.relief)
            .result();/*w  ww . ja  va2  s. c  o  m*/

    return res;
}

From source file:com.google.gerrit.server.group.ListMembers.java

public List<AccountInfo> apply(AccountGroup.UUID groupId) throws MethodNotAllowedException, OrmException {
    final Map<Account.Id, AccountInfo> members = getMembers(groupId, new HashSet<AccountGroup.UUID>());
    final List<AccountInfo> memberInfos = Lists.newArrayList(members.values());
    Collections.sort(memberInfos, new Comparator<AccountInfo>() {
        @Override/*from  w  w w  .  ja  v a2  s  .  c o m*/
        public int compare(AccountInfo a, AccountInfo b) {
            return ComparisonChain.start().compare(a.name, b.name, Ordering.natural().nullsFirst())
                    .compare(a.email, b.email, Ordering.natural().nullsFirst())
                    .compare(a._account_id, b._account_id, Ordering.natural().nullsFirst()).result();
        }
    });
    return memberInfos;
}

From source file:com.smoketurner.notification.application.riak.CursorObject.java

@Override
public int compareTo(final CursorObject that) {
    return ComparisonChain.start().compare(this.value, that.value, Ordering.natural().reverse()).result();
}

From source file:org.spongepowered.common.data.manipulator.mutable.entity.SpongeExperienceHolderData.java

@Override
public int compareTo(ExperienceHolderData o) {
    return ComparisonChain.start().compare(o.level().get().intValue(), this.level)
            .compare(o.totalExperience().get().intValue(), this.totalExp)
            .compare(o.experienceSinceLevel().get().intValue(), this.expSinceLevel).result();
}

From source file:org.spongepowered.common.data.manipulator.immutable.entity.ImmutableSpongeTameableData.java

@Override
public int compareTo(ImmutableTameableData o) {
    return ComparisonChain.start()
            .compare(this.owner, o.owner().get().orElse(null), Ordering.natural().nullsFirst()).result();
}

From source file:org.spongepowered.common.data.manipulator.mutable.entity.SpongeHealthData.java

@Override
public int compareTo(HealthData o) {
    return ComparisonChain.start().compare(o.health().get().doubleValue(), this.health)
            .compare(o.maxHealth().get().doubleValue(), this.maxHealth).result();
}

From source file:org.spongepowered.common.data.manipulator.immutable.entity.ImmutableSpongeHealthData.java

@Override
public int compareTo(ImmutableHealthData o) {
    return ComparisonChain.start().compare(o.health().get().doubleValue(), this.health)
            .compare(o.maxHealth().get().doubleValue(), this.maxHealth).result();
}

From source file:org.obiba.opal.core.domain.ReportTemplate.java

@Override
public int compareTo(@NotNull ReportTemplate other) {
    return ComparisonChain.start().compare(project, other.project).compare(name, other.name).result();
}

From source file:org.apache.crunch.Pair.java

private int cmp(Object lhs, Object rhs) {
    if (lhs == rhs) {
        return 0;
    } else if (lhs != null && Comparable.class.isAssignableFrom(lhs.getClass())) {
        return Ordering.natural().nullsLast().compare((Comparable) lhs, (Comparable) rhs);//(Comparable) lhs).compareTo(rhs);
    }// w  w  w  .  ja va  2 s. c o m
    if (lhs == null) {
        return 1; // nulls last
    }
    if (rhs == null) {
        return -1; // nulls last
    }
    if (lhs.equals(rhs)) {
        return 0;
    }

    // Now we compare based on hash code. We already know that the two sides are not equal, so
    // if the hash codes are equal, we just use arbitrary (but consistent) ordering
    return ComparisonChain.start().compare(lhs.hashCode(), rhs.hashCode())
            .compare(lhs, rhs, Ordering.arbitrary()).result();
}

From source file:org.jclouds.gogrid.domain.internal.ErrorResponse.java

@Override
public int compareTo(ErrorResponse that) {
    return ComparisonChain.start().compare(errorCode, that.errorCode).compare(message, that.message).result();
}