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.jclouds.glacier.domain.VaultMetadata.java

@Override
public int compareTo(VaultMetadata o) {
    return ComparisonChain.start().compare(this.vaultName, o.getVaultName()).result();
}

From source file:com.opengamma.strata.collect.tuple.ObjIntPair.java

/**
 * Compares the pair based on the first element followed by the second element.
 * <p>//  ww w. jav a  2  s.  c  om
 * The first element must be {@code Comparable}.
 * 
 * @param other  the other pair
 * @return negative if this is less, zero if equal, positive if greater
 * @throws ClassCastException if the object is not comparable
 */
@Override
public int compareTo(ObjIntPair<A> other) {
    return ComparisonChain.start().compare((Comparable<?>) first, (Comparable<?>) other.first)
            .compare(second, other.second).result();
}

From source file:domainapp.modules.simple.dom.impl.SimpleObject.java

public int compareTo(final SimpleObject other) {
    return ComparisonChain.start()
            .compare(this.getName(), other.getName())
            .result();//from  w  w w  .  j  a  va2 s .c o m
}

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

@Override
public int compareTo(MovementSpeedData o) {
    return ComparisonChain.start().compare(o.walkSpeed().get().doubleValue(), this.walkSpeed)
            .compare(o.flySpeed().get().doubleValue(), this.flySpeed).result();
}

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

@Override
public int compareTo(BodyPartRotationalData o) {
    int mapSizeComp = Integer.compare(this.rotations.size(), o.partRotation().size());

    if (mapSizeComp != 0) {
        return mapSizeComp;
    }/*from  ww  w . ja va2 s  . com*/
    ComparisonChain comparison = ComparisonChain.start();
    Map<BodyPart, Vector3d> parts = o.partRotation().get();
    parts.forEach((part, vec) -> {
        comparison.compare(vec, this.rotations.get(part));
    });
    return comparison.result();
}

From source file:com.opengamma.strata.collect.tuple.ObjDoublePair.java

/**
 * Compares the pair based on the first element followed by the second element.
 * <p>// w ww .  j a v  a 2s.  co  m
 * The first element must be {@code Comparable}.
 * 
 * @param other  the other pair
 * @return negative if this is less, zero if equal, positive if greater
 * @throws ClassCastException if the object is not comparable
 */
@Override
public int compareTo(ObjDoublePair<A> other) {
    return ComparisonChain.start().compare((Comparable<?>) first, (Comparable<?>) other.first)
            .compare(second, other.second).result();
}

From source file:org.apache.hadoop.util.VersionUtil.java

/**
 * This function splits the two versions on &quot;.&quot; and performs a
 * naturally-ordered comparison of the resulting components. For example, the
 * version string "0.3" is considered to precede "0.20", despite the fact that
 * lexical comparison would consider "0.20" to precede "0.3". This method of
 * comparison is similar to the method used by package versioning systems like
 * deb and RPM.//from ww w. j ava  2s .c  om
 * 
 * Version components are compared numerically whenever possible, however a
 * version component can contain non-numeric characters. When a non-numeric
 * group of characters is found in a version component, this group is compared
 * with the similarly-indexed group in the other version component. If the
 * other group is numeric, then the numeric group is considered to precede the
 * non-numeric group. If both groups are non-numeric, then a lexical
 * comparison is performed.
 * 
 * If two versions have a different number of components, then only the lower
 * number of components are compared. If those components are identical
 * between the two versions, then the version with fewer components is
 * considered to precede the version with more components.
 * 
 * In addition to the above rules, there is one special case: maven SNAPSHOT
 * releases are considered to precede a non-SNAPSHOT release with an
 * otherwise identical version number. For example, 2.0-SNAPSHOT precedes
 * 2.0.
 * 
 * This function returns a negative integer if version1 precedes version2, a
 * positive integer if version2 precedes version1, and 0 if and only if the
 * two versions' components are identical in value and cardinality.
 * 
 * @param version1
 *          the first version to compare
 * @param version2
 *          the second version to compare
 * @return a negative integer if version1 precedes version2, a positive
 *         integer if version2 precedes version1, and 0 if and only if the two
 *         versions are equal.
 */
public static int compareVersions(String version1, String version2) {
    boolean isSnapshot1 = version1.endsWith(SNAPSHOT_SUFFIX);
    boolean isSnapshot2 = version2.endsWith(SNAPSHOT_SUFFIX);
    version1 = stripSnapshotSuffix(version1);
    version2 = stripSnapshotSuffix(version2);

    String[] version1Parts = version1.split("\\.");
    String[] version2Parts = version2.split("\\.");

    for (int i = 0; i < version1Parts.length && i < version2Parts.length; i++) {
        String component1 = version1Parts[i];
        String component2 = version2Parts[i];
        if (!component1.equals(component2)) {
            Matcher matcher1 = COMPONENT_GROUPS.matcher(component1);
            Matcher matcher2 = COMPONENT_GROUPS.matcher(component2);

            while (matcher1.find() && matcher2.find()) {
                String group1 = matcher1.group();
                String group2 = matcher2.group();
                if (!group1.equals(group2)) {
                    if (isNumeric(group1) && isNumeric(group2)) {
                        return Integer.parseInt(group1) - Integer.parseInt(group2);
                    } else if (!isNumeric(group1) && !isNumeric(group2)) {
                        return group1.compareTo(group2);
                    } else {
                        return isNumeric(group1) ? -1 : 1;
                    }
                }
            }
            return component1.length() - component2.length();
        }
    }

    return ComparisonChain.start().compare(version1Parts.length, version2Parts.length)
            .compare(isSnapshot2, isSnapshot1).result();
}

From source file:org.spongepowered.common.data.manipulator.immutable.tileentity.ImmutableSpongeBannerData.java

@Override
public int compareTo(ImmutableBannerData o) {
    return ComparisonChain.start().compare(o.baseColor().get().getId(), this.base.getId())
            .compare(o.patterns().get().containsAll(this.layers), this.layers.containsAll(o.patterns().get()))
            .result();/* w w w  .  jav  a2s .c  o m*/
}

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

@Override
public int compareTo(CommandData o) {
    return ComparisonChain.start().compare(o.doesTrackOutput().get(), this.tracks)
            .compare(o.lastOutput().get().isPresent(), this.lastOutput != null)
            .compare(o.storedCommand().get(), this.command)
            .compare(o.successCount().get().intValue(), this.success).result();
}

From source file:$.Key.java

@Override
    public int compareTo(Key that) {
        return ComparisonChain.start().compare(this.name, that.name).compare(this.created, that.created).result();
    }//w  ww . j  av  a 2s  .c o  m