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:info.archinnov.achilles.internal.table.ColumnMetaDataComparator.java

public boolean isEqual(ColumnMetadata source, ColumnMetadata target) {
    boolean isEqual;
    final String sourceName = source.getName();
    final TableMetadata sourceTable = source.getTable();
    final DataType sourceType = source.getType();
    final Class<?> sourceClass = sourceType.asJavaClass();
    final List<DataType> sourceTypeParams = sourceType.getTypeArguments();

    final String targetName = target.getName();
    final TableMetadata targetTable = target.getTable();
    final DataType targetType = target.getType();
    final Class<?> targetClass = targetType.asJavaClass();
    final List<DataType> targetTypeParams = targetType.getTypeArguments();

    final boolean isPartiallyEqual = ComparisonChain.start().compare(sourceName, targetName)
            .compare(sourceTable.getName(), targetTable.getName())
            .compare(sourceType.getName(), targetType.getName())
            .compareFalseFirst(sourceType.isCollection(), targetType.isCollection()).result() == 0;
    final boolean isSameClass = sourceClass.equals(targetClass);
    final boolean bothHaveTypeParameters = (sourceTypeParams != null && targetTypeParams != null)
            || (sourceTypeParams == null && targetTypeParams == null);

    isEqual = isPartiallyEqual && isSameClass && bothHaveTypeParameters;
    if (isEqual && sourceTypeParams != null) {
        isEqual = (sourceTypeParams.size() == targetTypeParams.size());
        if (isEqual) {
            for (int i = 0; i < sourceTypeParams.size(); i++) {
                final DataType sourceParamType = sourceTypeParams.get(i);
                final DataType targetParamType = targetTypeParams.get(i);

                final boolean sameParamType = ComparisonChain.start()
                        .compare(sourceParamType.getName(), targetParamType.getName()).result() == 0;
                if (!sameParamType) {
                    return false;
                }/*w w  w.  j  ava  2s  . c o m*/
            }
        }
    }
    return isEqual;
}

From source file:com.github.hilcode.versionator.PomAndGav.java

@Override
public int compareTo(final PomAndGav other) {
    return ComparisonChain.start().compare(this.pom, other.pom).compare(this.gav, other.gav).result();
}

From source file:com.facebook.buck.rules.AbstractArchiveMemberSourcePath.java

@Override
public int compareTo(SourcePath other) {
    if (other == this) {
        return 0;
    }/*from   w ww. j  av  a  2 s. c  om*/

    int classComparison = compareClasses(other);
    if (classComparison != 0) {
        return classComparison;
    }

    AbstractArchiveMemberSourcePath that = (AbstractArchiveMemberSourcePath) other;

    return ComparisonChain.start().compare(getArchiveSourcePath(), that.getArchiveSourcePath())
            .compare(getMemberPath(), that.getMemberPath()).result();
}

From source file:org.dllearner.utilities.datastructures.RDFNodeTuple.java

@Override
public int compareTo(RDFNodeTuple t) {
    NodeComparator comparator = new NodeComparator();
    return ComparisonChain.start().compare(a.asNode(), t.a.asNode(), comparator)
            .compare(b.asNode(), t.b.asNode(), comparator).result();
}

From source file:org.gradle.jvm.tasks.api.internal.Member.java

protected ComparisonChain compare(Member o) {
    return ComparisonChain.start().compare(name, o.name);
}

From source file:com.github.jcustenborder.kafka.connect.cdc.ConnectionKey.java

@Override
public int compareTo(ConnectionKey that) {
    return ComparisonChain.start().compare(this.server, that.server).compare(this.port, that.port)
            .compare(this.username, that.username)
            .compare(this.databaseName, that.databaseName, Ordering.natural().nullsLast()).result();
}

From source file:com.android.tools.idea.editors.hierarchyview.model.ViewProperty.java

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

From source file:com.github.hilcode.versionator.Key.java

@Override
public int compareTo(final Key other) {
    return ComparisonChain.start().compare(this.value, other.value).result();
}

From source file:org.dllearner.utilities.owl.EvaluatedDescriptionComparator.java

@Override
public int compare(EvaluatedDescription<? extends Score> ed1, EvaluatedDescription<? extends Score> ed2) {
    return ComparisonChain.start().compare(ed1.getAccuracy(), ed2.getAccuracy()) // higher accuracy is better
            .compare(getLength(ed2), getLength(ed1)) // shorter is better
            .compare(ed1.getDescription(), ed2.getDescription()) // syntactic sorting
            .result();// w  ww  .j ava2  s . c om
}

From source file:org.apache.qpid.disttest.results.formatting.CSVOrderParticipantResultComparator.java

@Override
public int compare(ParticipantResult left, ParticipantResult right) {
    return ComparisonChain.start()
            .compare(getTypeCode(left), getTypeCode(right), Ordering.natural().nullsFirst())
            .compare(left.getParticipantName(), right.getParticipantName(), Ordering.natural().nullsFirst())
            .result();// ww w  .j av a  2s.c  om
}