Example usage for org.apache.commons.lang3.builder CompareToBuilder toComparison

List of usage examples for org.apache.commons.lang3.builder CompareToBuilder toComparison

Introduction

In this page you can find the example usage for org.apache.commons.lang3.builder CompareToBuilder toComparison.

Prototype

public int toComparison() 

Source Link

Document

Returns a negative integer, a positive integer, or zero as the builder has judged the "left-hand" side as less than, greater than, or equal to the "right-hand" side.

Usage

From source file:org.bgp4j.net.attributes.MultiProtocolUnreachableNLRI.java

@Override
protected int subclassCompareTo(PathAttribute obj) {
    MultiProtocolUnreachableNLRI o = (MultiProtocolUnreachableNLRI) obj;

    CompareToBuilder builer = (new CompareToBuilder()).append(getAddressFamily(), o.getAddressFamily())
            .append(getSubsequentAddressFamily(), o.getSubsequentAddressFamily())
            .append(getNlris().size(), o.getNlris().size());

    if (builer.toComparison() == 0) {
        Iterator<NetworkLayerReachabilityInformation> lit = getNlris().iterator();
        Iterator<NetworkLayerReachabilityInformation> rit = o.getNlris().iterator();

        while (lit.hasNext())
            builer.append(lit.next(), rit.next());
    }//from  w  ww .  j  ava2s .c  o  m

    return builer.toComparison();
}

From source file:org.bgp4j.net.attributes.PathAttribute.java

@Override
public int compareTo(PathAttribute o) {
    CompareToBuilder builder = new CompareToBuilder();

    builder.append(internalType(), o.internalType()).append(getCategory(), o.getCategory())
            .append(isOptional(), o.isOptional()).append(isPartial(), o.isPartial())
            .append(isTransitive(), o.isTransitive());

    if (internalType() == o.internalType())
        builder.appendSuper(subclassCompareTo(o));

    return builder.toComparison();
}

From source file:org.bgp4j.net.BinaryNextHop.java

@Override
public int compareTo(NextHop o) {
    CompareToBuilder builder = (new CompareToBuilder()).append(getType(), o.getType());

    if (o.getType() == Type.Binary) {
        builder.append(getAddress(), ((BinaryNextHop) o).getAddress());
    }//ww  w . ja v  a2s .  co m

    return builder.toComparison();
}

From source file:org.bgp4j.net.InetAddressNextHop.java

@SuppressWarnings("unchecked")
@Override// w  ww  .  j a  v a  2s  .  c  o  m
public int compareTo(NextHop o) {
    CompareToBuilder builder = (new CompareToBuilder()).append(getType(), o.getType());

    if (o.getType() == Type.InetAddress) {
        builder.append(getAddress().getAddress(),
                ((InetAddressNextHop<InetAddress>) o).getAddress().getAddress());
    }

    return builder.toComparison();
}

From source file:org.bgp4j.net.NetworkLayerReachabilityInformation.java

@Override
public int compareTo(NetworkLayerReachabilityInformation other) {
    CompareToBuilder builder = new CompareToBuilder();

    builder.append(getPrefixLength(), other.getPrefixLength());

    if (builder.toComparison() == 0) {
        int byteLen = calculateOctetsForPrefixLength(this.prefixLength);
        int otherByteLen = calculateOctetsForPrefixLength(other.prefixLength);
        int commonByteLen = (byteLen > otherByteLen) ? otherByteLen : byteLen;
        int commonPrefixLen = (prefixLength > other.prefixLength) ? other.prefixLength : prefixLength;

        for (int i = 0; i < commonByteLen - 1; i++) {
            builder.append(getPrefix()[i], other.getPrefix()[i]);
        }//from  w ww.  j  a  va2  s .c  o  m

        if (builder.toComparison() == 0) {
            int bitsToCheck = commonPrefixLen % 8;

            if (bitsToCheck == 0) {
                if (commonByteLen > 0)
                    builder.append(getPrefix()[commonByteLen - 1], other.getPrefix()[commonByteLen - 1]);
            } else {
                for (int i = 0; i < bitsToCheck; i++) {
                    int mask = 1 << (7 - i);

                    builder.append(getPrefix()[commonByteLen - 1] & mask,
                            other.getPrefix()[commonByteLen - 1] & mask);
                    if (builder.toComparison() != 0)
                        break;
                }
            }

            if (builder.toComparison() == 0) {
                builder.append(getPrefixLength(), other.getPrefixLength());
            }
        }

    }

    return builder.toComparison();
}

From source file:org.broadleafcommerce.cms.web.processor.ContentProcessor.java

@Override
protected void modifyModelAttributes(final Arguments arguments, Element element) {
    String contentType = element.getAttributeValue("contentType");
    String contentName = element.getAttributeValue("contentName");
    String maxResultsStr = element.getAttributeValue("maxResults");

    if (StringUtils.isEmpty(contentType) && StringUtils.isEmpty(contentName)) {
        throw new IllegalArgumentException(
                "The content processor must have a non-empty attribute value for 'contentType' or 'contentName'");
    }/*from   w  w w .ja  va2 s  .  c  o  m*/

    Integer maxResults = null;
    if (maxResultsStr != null) {
        maxResults = Ints.tryParse(maxResultsStr);
    }
    if (maxResults == null) {
        maxResults = Integer.MAX_VALUE;
    }

    String contentListVar = getAttributeValue(element, "contentListVar", "contentList");
    String contentItemVar = getAttributeValue(element, "contentItemVar", "contentItem");
    String numResultsVar = getAttributeValue(element, "numResultsVar", "numResults");

    String fieldFilters = element.getAttributeValue("fieldFilters");
    final String sorts = element.getAttributeValue("sorts");

    IWebContext context = (IWebContext) arguments.getContext();
    HttpServletRequest request = context.getHttpServletRequest();
    BroadleafRequestContext blcContext = BroadleafRequestContext.getBroadleafRequestContext();

    Map<String, Object> mvelParameters = buildMvelParameters(request, arguments, element);
    SandBox currentSandbox = blcContext.getSandBox();

    List<StructuredContentDTO> contentItems;
    StructuredContentType structuredContentType = null;
    if (contentType != null) {
        structuredContentType = structuredContentService.findStructuredContentTypeByName(contentType);
    }

    Locale locale = blcContext.getLocale();

    contentItems = getContentItems(contentName, maxResults, request, mvelParameters, currentSandbox,
            structuredContentType, locale, arguments, element);

    if (contentItems.size() > 0) {

        // sort the resulting list by the configured property sorts on the tag
        if (StringUtils.isNotEmpty(sorts)) {
            Collections.sort(contentItems, new Comparator<StructuredContentDTO>() {
                @Override
                public int compare(StructuredContentDTO o1, StructuredContentDTO o2) {
                    AssignationSequence sortAssignments = AssignationUtils
                            .parseAssignationSequence(arguments.getConfiguration(), arguments, sorts, false);
                    CompareToBuilder compareBuilder = new CompareToBuilder();
                    for (Assignation sortAssignment : sortAssignments) {
                        String property = sortAssignment.getLeft().getStringRepresentation();

                        Object val1 = o1.getPropertyValue(property);
                        Object val2 = o2.getPropertyValue(property);

                        if (sortAssignment.getRight().execute(arguments.getConfiguration(), arguments)
                                .equals("ASCENDING")) {
                            compareBuilder.append(val1, val2);
                        } else {
                            compareBuilder.append(val2, val1);
                        }
                    }
                    return compareBuilder.toComparison();
                }
            });
        }

        List<Map<String, Object>> contentItemFields = new ArrayList<Map<String, Object>>();

        for (StructuredContentDTO item : contentItems) {
            if (StringUtils.isNotEmpty(fieldFilters)) {
                AssignationSequence assignments = AssignationUtils
                        .parseAssignationSequence(arguments.getConfiguration(), arguments, fieldFilters, false);
                boolean valid = true;
                for (Assignation assignment : assignments) {

                    if (ObjectUtils.notEqual(
                            assignment.getRight().execute(arguments.getConfiguration(), arguments),
                            item.getValues().get(assignment.getLeft().getStringRepresentation()))) {
                        LOG.info("Excluding content " + item.getId() + " based on the property value of "
                                + assignment.getLeft().getStringRepresentation());
                        valid = false;
                        break;
                    }
                }
                if (valid) {
                    contentItemFields.add(item.getValues());
                }
            } else {
                contentItemFields.add(item.getValues());
            }
        }

        Map<String, Object> contentItem = null;
        if (contentItemFields.size() > 0) {
            contentItem = contentItemFields.get(0);
        }

        addToModel(arguments, contentItemVar, contentItem);
        addToModel(arguments, contentListVar, contentItemFields);
        addToModel(arguments, numResultsVar, contentItems.size());
    } else {
        if (LOG.isInfoEnabled()) {
            LOG.info("**************************The contentItems is null*************************");
        }
        addToModel(arguments, contentItemVar, null);
        addToModel(arguments, contentListVar, null);
        addToModel(arguments, numResultsVar, 0);
    }

    String deepLinksVar = element.getAttributeValue("deepLinks");
    if (StringUtils.isNotBlank(deepLinksVar) && contentItems.size() > 0) {
        List<DeepLink> links = contentDeepLinkService.getLinks(contentItems.get(0));
        extensionManager.getProxy().addExtensionFieldDeepLink(links, arguments, element);
        extensionManager.getProxy().postProcessDeepLinks(links);
        addToModel(arguments, deepLinksVar, links);
    }
}

From source file:org.flowable.dmn.engine.impl.hitpolicy.HitPolicyOutputOrder.java

@Override
public void composeDecisionResults(final ELExecutionContext executionContext) {
    List<Map<String, Object>> ruleResults = new ArrayList<>(executionContext.getRuleResults().values());

    boolean outputValuesPresent = false;
    for (Map.Entry<String, List<Object>> entry : executionContext.getOutputValues().entrySet()) {
        List<Object> outputValues = entry.getValue();
        if (outputValues != null && !outputValues.isEmpty()) {
            outputValuesPresent = true;//from w  w  w  .j av  a2 s  .  c  om
            break;
        }
    }

    if (!outputValuesPresent) {
        if (CommandContextUtil.getDmnEngineConfiguration().isStrictMode()) {
            throw new FlowableException(
                    String.format("HitPolicy: %s; no output values present", getHitPolicyName()));
        }
    }

    // sort on predefined list(s) of output values
    Collections.sort(ruleResults, new Comparator<Map<String, Object>>() {

        @Override
        public int compare(Map<String, Object> o1, Map<String, Object> o2) {

            CompareToBuilder compareToBuilder = new CompareToBuilder();
            for (Map.Entry<String, List<Object>> entry : executionContext.getOutputValues().entrySet()) {
                List<Object> outputValues = entry.getValue();
                if (outputValues != null && !outputValues.isEmpty()) {
                    compareToBuilder.append(o1.get(entry.getKey()), o2.get(entry.getKey()),
                            new OutputOrderComparator<>(
                                    outputValues.toArray(new Comparable[outputValues.size()])));
                    compareToBuilder.toComparison();
                }
            }

            return compareToBuilder.toComparison();
        }
    });

    executionContext.getAuditContainer().setDecisionResult(ruleResults);
}

From source file:org.flowable.dmn.engine.impl.hitpolicy.HitPolicyPriority.java

@Override
public void composeDecisionResults(final ELExecutionContext executionContext) {

    List<Map<String, Object>> ruleResults = new ArrayList<>(executionContext.getRuleResults().values());

    // sort on predefined list(s) of output values
    Collections.sort(ruleResults, new Comparator<Object>() {
        boolean noOutputValuesPresent = true;

        @SuppressWarnings("unchecked")
        @Override// w  ww .ja va2 s .co  m
        public int compare(Object o1, Object o2) {
            CompareToBuilder compareToBuilder = new CompareToBuilder();
            for (Map.Entry<String, List<Object>> entry : executionContext.getOutputValues().entrySet()) {
                List<Object> outputValues = entry.getValue();
                if (outputValues != null || !outputValues.isEmpty()) {
                    noOutputValuesPresent = false;
                    compareToBuilder.append(((Map<String, Object>) o1).get(entry.getKey()),
                            ((Map<String, Object>) o2).get(entry.getKey()), new OutputOrderComparator<>(
                                    outputValues.toArray(new Comparable[outputValues.size()])));
                }
            }

            if (!noOutputValuesPresent) {
                return compareToBuilder.toComparison();

            } else {
                if (CommandContextUtil.getDmnEngineConfiguration().isStrictMode()) {
                    throw new FlowableException(
                            String.format("HitPolicy: %s; no output values present", getHitPolicyName()));
                }

                return 0;
            }
        }
    });

    executionContext.getAuditContainer().addDecisionResultObject(ruleResults.get(0));
}

From source file:org.kuali.coeus.common.notification.impl.lookup.keyvalue.KeyLabelSortByValue.java

@Override
public int compareTo(KeyValue o) {
    if (o == null) {
        throw new NullPointerException("the object to compare to is null");
    }/*from ww w  .  java2s  .  co  m*/
    CompareToBuilder builder = new CompareToBuilder();
    builder.append(this.getValue(), o.getValue(), String.CASE_INSENSITIVE_ORDER);

    if ((this.getKey() instanceof String) && (o.getKey() instanceof String))
        builder.append(this.getKey(), o.getKey(), String.CASE_INSENSITIVE_ORDER);
    else {
        builder.append(this.getKey(), o.getKey());
    }

    return builder.toComparison();

}

From source file:org.silverpeas.web.directory.model.AbstractDirectoryItem.java

@Override
public int compareTo(DirectoryItem other) {
    CompareToBuilder compareToBuilder = new CompareToBuilder();
    compareToBuilder.append(getLastName() != null ? getLastName().toLowerCase() : "",
            other.getLastName() != null ? other.getLastName().toLowerCase() : "");
    compareToBuilder.append(getFirstName() != null ? getFirstName().toLowerCase() : "",
            other.getFirstName() != null ? other.getFirstName().toLowerCase() : "");
    compareToBuilder.append(getType(), other.getType());
    compareToBuilder.append(other.getOriginalId(), getOriginalId());
    return compareToBuilder.toComparison();
}