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.opencms.ui.apps.CmsAppHierarchyBuilder.java

/**
 * Builds the tree of categories and apps.<p>
 *
 * This tree will only include those categories which are reachable by following the parent chain of
 * an available app configuration up to the root category (null).
 *
 * @return the root node of the tree/*from  w  ww  .  j a v a  2  s .c o  m*/
 */
public CmsAppCategoryNode buildHierarchy() {

    // STEP 0: Initialize everything and sort categories by priority

    Collections.sort(m_appCategoryList, new Comparator<I_CmsAppCategory>() {

        public int compare(I_CmsAppCategory cat1, I_CmsAppCategory cat2) {

            return ComparisonChain.start().compare(cat1.getPriority(), cat2.getPriority()).result();
        }
    });
    m_rootNode = new CmsAppCategoryNode();
    m_nodes.clear();
    m_nodes.put(null, m_rootNode);

    // STEP 1: Create a node for each category

    for (I_CmsAppCategory category : m_appCategoryList) {
        m_nodes.put(category.getId(), new CmsAppCategoryNode(category));
    }

    // STEP 2: Assign category nodes to nodes for their parent category

    for (CmsAppCategoryNode node : m_nodes.values()) {
        if (node != m_rootNode) {
            addNodeToItsParent(node);
        }
    }

    // STEP 3: Assign app configs to category nodes

    for (I_CmsWorkplaceAppConfiguration appConfig : m_appConfigs) {
        addAppConfigToCategory(appConfig);
    }

    // STEP 4: Validate whether there are unused categories / apps

    Set<String> usedNodes = findReachableNodes(m_rootNode, new HashSet<String>());
    if (usedNodes.size() < m_nodes.size()) {
        LOG.warn("Unused app categories: " + Sets.difference(m_nodes.keySet(), usedNodes));
    }
    Set<String> unusedApps = Sets.newHashSet();
    for (I_CmsWorkplaceAppConfiguration appConfig : m_appConfigs) {
        if (!usedNodes.contains(appConfig.getAppCategory())) {
            unusedApps.add(appConfig.getId());
        }
    }
    if (unusedApps.size() > 0) {
        LOG.warn("Unused apps: " + unusedApps);
    }

    // STEP 5: Remove parts of the hierarchy which don't contain any apps
    m_rootNode.removeApplessSubtrees();

    // STEP 6: Sort all categories and app configurations for each node
    m_rootNode.sortRecursively();

    return m_rootNode;
}

From source file:io.confluent.kafka.connect.source.io.processing.csv.FieldConfig.java

@Override
public int compareTo(FieldConfig that) {
    if (null == that) {
        return 1;
    }//from ww w . j a  va 2 s .  co m
    return ComparisonChain.start().compare(this.name, that.name, Ordering.natural().<String>nullsFirst())
            .compare(this.type, that.type)
            .compare(this.scale, that.scale, Ordering.natural().<Integer>nullsFirst())
            .compare(this.required, that.required).result();
}

From source file:me.flibio.jobslite.data.SignJobData.java

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

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

@SuppressWarnings("unchecked")
@Override/*from   w  ww .  j a v a  2 s  .co m*/
public int compareTo(MinecartBlockData o) {
    Map<?, ?> oTraits = o.block().get().getTraitMap();
    Map<?, ?> traits = this.block.getTraitMap();
    return ComparisonChain.start()
            .compare(oTraits.entrySet().containsAll(traits.entrySet()),
                    traits.entrySet().containsAll(oTraits.entrySet()))
            .compare((Integer) this.offset, o.offset().get()).result();
}

From source file:eu.project.ttc.models.TermVariation.java

@Override
public int compareTo(TermVariation tv) {
    return ComparisonChain.start()
            // sort by score desc
            .compare(tv.score, this.score)
            // then by non inclusion first
            .compare(this.includedIn ? 1 : 0, tv.includedIn ? 1 : 0)
            // then by length asc
            .compare(this.variant.getWords().size(), tv.variant.getWords().size())
            // then by term id
            .compare(this.variant.getGroupingKey(), tv.variant.getGroupingKey())
            // makes it consistent with equals
            .compare(this.base.getGroupingKey(), tv.base.getGroupingKey())
            .compare(this.variationType, tv.variationType).result();

}

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

@SuppressWarnings("unchecked")
@Override/*from w  w  w  . j a  v a  2  s. c  o m*/
public int compareTo(ImmutableMinecartBlockData o) {
    Map<?, ?> oTraits = o.block().get().getTraitMap();
    Map<?, ?> traits = this.block.getTraitMap();
    return ComparisonChain.start()
            .compare(oTraits.entrySet().containsAll(traits.entrySet()),
                    traits.entrySet().containsAll(oTraits.entrySet()))
            .compare((Integer) this.offset, o.offset().get()).result();
}

From source file:org.dllearner.core.EvaluatedAxiom.java

public int compareTo(EvaluatedAxiom<T> other) {
    return ComparisonChain.start().compare(other.getScore().getAccuracy(), score.getAccuracy())
            .compare(hypothesis, other.getAxiom()).result();
}

From source file:org.sosy_lab.cpachecker.cpa.blockcount.BlockCountState.java

@Override
public int compareTo(BlockCountState pO) {
    return ComparisonChain.start().compare(count, pO.count).compareFalseFirst(stop, pO.stop).result();
}

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

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

From source file:com.github.hilcode.versionator.maven.Pom.java

@Override
public int compareTo(final Pom other) {
    return ComparisonChain.start().compare(this.gav, other.gav).compare(this.groupIdSource, other.groupIdSource)
            .compare(this.versionSource, other.versionSource).compare(this.file, other.file)
            .compare(this.type, other.type)
            .compare(this.parent, other.parent, OptionalComparator.<Pom>instance())
            .compare(this.modules, other.modules, CollectionComparator.<String>instance())
            .compare(this.properties, other.properties, CollectionComparator.<Property>instance())
            .compare(this.dependencies, other.dependencies, CollectionComparator.<Gav>instance()).result();
}