Example usage for org.apache.commons.lang ObjectUtils notEqual

List of usage examples for org.apache.commons.lang ObjectUtils notEqual

Introduction

In this page you can find the example usage for org.apache.commons.lang ObjectUtils notEqual.

Prototype

public static boolean notEqual(Object object1, Object object2) 

Source Link

Document

Compares two objects for inequality, where either one or both objects may be null.

 ObjectUtils.notEqual(null, null)                  = false ObjectUtils.notEqual(null, "")                    = true ObjectUtils.notEqual("", null)                    = true ObjectUtils.notEqual("", "")                      = false ObjectUtils.notEqual(Boolean.TRUE, null)          = true ObjectUtils.notEqual(Boolean.TRUE, "true")        = true ObjectUtils.notEqual(Boolean.TRUE, Boolean.TRUE)  = false ObjectUtils.notEqual(Boolean.TRUE, Boolean.FALSE) = true 

Usage

From source file:org.batoo.jpa.core.impl.collections.ManagedList.java

/**
 * {@inheritDoc}//from www . j ava 2  s.c  om
 * 
 */
@Override
public E set(int index, E element) {
    this.snapshot();

    if (this.delegate.contains(element) && ObjectUtils.notEqual(element, this.delegate.get(index))) {
        throw this.noDuplicates();
    }

    this.changed();
    return this.delegate.set(index, element);
}

From source file:org.beangle.model.util.HierarchyEntityUtil.java

public static <T extends HierarchyEntity<T>> void addParent(Collection<T> nodes, T toRoot) {
    Set<T> parents = CollectUtils.newHashSet();
    for (T node : nodes) {
        while (null != node.getParent() && !parents.contains(node.getParent())
                && ObjectUtils.notEqual(node.getParent(), toRoot)) {
            parents.add(node.getParent());
            node = node.getParent();//from w w  w  .j  a v a 2  s.c  o  m
        }
    }
    nodes.addAll(parents);
}

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 ww .ja  v  a  2s  .  c  om*/

    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.dspace.identifier.DOIIdentifierProviderTest.java

@Test
public void testGet_DSpaceObject_by_DOI() throws SQLException, AuthorizeException, IOException,
        IllegalArgumentException, IdentifierException, WorkflowException, IllegalAccessException {
    Item item = newItem();//  w  w  w.  j a  v a2s. c  o m
    String doi = this.createDOI(item, DOIIdentifierProvider.IS_REGISTERED, false);

    DSpaceObject dso = provider.getObjectByDOI(context, doi);

    assertNotNull("Failed to load DSpaceObject by DOI.", dso);
    if (item.getType() != dso.getType() || ObjectUtils.notEqual(item.getID(), dso.getID())) {
        fail("Object loaded by DOI was another object then expected!");
    }
}

From source file:org.dspace.identifier.DOIIdentifierProviderTest.java

@Test
public void testResolve_DOI() throws SQLException, AuthorizeException, IOException, IllegalArgumentException,
        IdentifierException, WorkflowException, IllegalAccessException {
    Item item = newItem();/* www . j  a v  a 2 s .  c o m*/
    String doi = this.createDOI(item, DOIIdentifierProvider.IS_REGISTERED, false);

    DSpaceObject dso = provider.resolve(context, doi);

    assertNotNull("Failed to resolve DOI.", dso);
    if (item.getType() != dso.getType() || ObjectUtils.notEqual(item.getID(), dso.getID())) {
        fail("Object return by DOI lookup was another object then expected!");
    }
}

From source file:org.eclipse.smarthome.binding.homematic.handler.HomematicThingHandler.java

@Override
public void handleConfigurationUpdate(Map<String, Object> configurationParameters)
        throws ConfigValidationException {
    super.handleConfigurationUpdate(configurationParameters);

    try {// w  w w. j a va2  s  .co m
        HomematicGateway gateway = getHomematicGateway();
        HmDevice device = gateway.getDevice(UidUtils.getHomematicAddress(getThing()));

        for (Entry<String, Object> configurationParameter : configurationParameters.entrySet()) {
            String key = configurationParameter.getKey();
            Object newValue = configurationParameter.getValue();

            if (key.startsWith("HMP_")) {
                key = StringUtils.removeStart(key, "HMP_");
                Integer channelNumber = NumberUtils.toInt(StringUtils.substringBefore(key, "_"));
                String dpName = StringUtils.substringAfter(key, "_");

                HmDatapointInfo dpInfo = new HmDatapointInfo(device.getAddress(), HmParamsetType.MASTER,
                        channelNumber, dpName);
                HmDatapoint dp = device.getChannel(channelNumber).getDatapoint(dpInfo);

                if (dp != null) {
                    try {
                        if (newValue != null) {
                            if (newValue instanceof BigDecimal) {
                                final BigDecimal decimal = (BigDecimal) newValue;
                                if (dp.isIntegerType()) {
                                    newValue = decimal.intValue();
                                } else if (dp.isFloatType()) {
                                    newValue = decimal.doubleValue();
                                }
                            }
                            if (ObjectUtils.notEqual(dp.isEnumType() ? dp.getOptionValue() : dp.getValue(),
                                    newValue)) {
                                sendDatapoint(dp, new HmDatapointConfig(), newValue);
                            }
                        }
                    } catch (IOException ex) {
                        logger.error("Error setting thing property {}: {}", dpInfo, ex.getMessage());
                    }
                } else {
                    logger.error("Can't find datapoint for thing property {}", dpInfo);
                }
            }
        }
        gateway.triggerDeviceValuesReload(device);
    } catch (HomematicClientException | GatewayNotAvailableException ex) {
        logger.error("Error setting thing properties: {}", ex.getMessage(), ex);
    }
}

From source file:org.kuali.kfs.module.ld.businessobject.lookup.EmployeeFundingLookupableHelperServiceImpl.java

/** 
 * Searches the given collection for an element that is equal to the given exhibit for purposes of consolidation.
 *
 * @param coll The collection to search for a like element.
 * @param exhibit The search criteria./*from www  .  j  a v  a  2s. com*/
 *
 * @return The element from the collection that matches the exhibit or null if 1) no items match or 
 *   the 2) exhibit is null.
 *
 */
private static EmployeeFunding findEmployeeFunding(Collection<EmployeeFunding> coll, EmployeeFunding exhibit) {
    if (exhibit == null) {
        return null;
    }

    for (EmployeeFunding temp : coll) {
        if (temp == null) {
            continue;
        }

        if (ObjectUtils.notEqual(temp.getEmplid(), exhibit.getEmplid())) {
            continue;
        }
        if (ObjectUtils.notEqual(temp.getUniversityFiscalYear(), exhibit.getUniversityFiscalYear())) {
            continue;
        }
        if (ObjectUtils.notEqual(temp.getChartOfAccountsCode(), exhibit.getChartOfAccountsCode())) {
            continue;
        }
        if (ObjectUtils.notEqual(temp.getAccountNumber(), exhibit.getAccountNumber())) {
            continue;
        }
        if (ObjectUtils.notEqual(temp.getSubAccountNumber(), exhibit.getSubAccountNumber())) {
            continue;
        }
        if (ObjectUtils.notEqual(temp.getFinancialObjectCode(), exhibit.getFinancialObjectCode())) {
            continue;
        }
        if (ObjectUtils.notEqual(temp.getFinancialSubObjectCode(), exhibit.getFinancialSubObjectCode())) {
            continue;
        }
        if (ObjectUtils.notEqual(temp.getPositionNumber(), exhibit.getPositionNumber())) {
            continue;
        }
        return temp;
    }
    /*no items in the collection match the exhibit.*/
    return null;
}

From source file:org.kuali.rice.krad.web.bind.UifViewBeanWrapper.java

/**
 * Overridden to perform processing before and after the value is set.
 *
 * <p>First binding security is checked to determine whether the path allows binding. Next,
 * access security is checked to determine whether the value needs decrypted. Finally, if
 * change tracking is enabled, the original value is compared with the new for indicating a
 * modified path.</p>//from   www .  j  av  a 2 s  . co  m
 *
 * {@inheritDoc}
 */
@Override
public void setPropertyValue(PropertyValue pv) throws BeansException {
    boolean isPropertyAccessible = checkPropertyBindingAccess(pv.getName());
    if (!isPropertyAccessible) {
        return;
    }

    Object value = processValueBeforeSet(pv.getName(), pv.getValue());

    pv = new PropertyValue(pv, value);

    // save off the original value if we are change tracking
    boolean originalValueSaved = true;
    Object originalValue = null;
    if (bindingResult.isChangeTracking()) {
        try {
            originalValue = getPropertyValue(pv.getName());
        } catch (Exception e) {
            // be failsafe here, if an exception happens here then we can't make any assumptions about whether
            // the property value changed or not
            originalValueSaved = false;
        }
    }

    // since auto grows is explicity turned off for get, we need to turn it on for set (so our objects
    // will grow if necessary for user entered data)
    setAutoGrowNestedPaths(true);

    // set the actual property value
    super.setPropertyValue(pv);

    // if we are change tracking and we saved original value, check if it's modified
    if (bindingResult.isChangeTracking() && originalValueSaved) {
        try {
            Object newValue = getPropertyValue(pv.getName());
            if (ObjectUtils.notEqual(originalValue, newValue)) {
                // if they are not equal, it's been modified!
                bindingResult.addModifiedPath(pv.getName());
            }
        } catch (Exception e) {
            // failsafe here as well
        }
    }
}

From source file:org.kuali.rice.krad.web.bind.UifViewBeanWrapper.java

/**
 * Overridden to perform processing before and after the value is set.
 *
 * <p>First binding security is checked to determine whether the path allows binding. Next,
 * access security is checked to determine whether the value needs decrypted. Finally, if
 * change tracking is enabled, the original value is compared with the new for indicating a
 * modified path.</p>//from w  w w  . ja v  a2s.c o m
 *
 * {@inheritDoc}
 */
@Override
public void setPropertyValue(String propertyName, Object value) throws BeansException {
    boolean isPropertyAccessible = checkPropertyBindingAccess(propertyName);
    if (!isPropertyAccessible) {
        return;
    }

    value = processValueBeforeSet(propertyName, value);

    // save off the original value
    boolean originalValueSaved = true;
    Object originalValue = null;
    try {
        originalValue = getPropertyValue(propertyName);
    } catch (Exception e) {
        // be failsafe here, if an exception happens here then we can't make any assumptions about whether
        // the property value changed or not
        originalValueSaved = false;
    }

    setAutoGrowNestedPaths(true);

    // set the actual property value
    super.setPropertyValue(propertyName, value);

    // only check if it's modified if we were able to save the original value
    if (originalValueSaved) {
        try {
            Object newValue = getPropertyValue(propertyName);
            if (ObjectUtils.notEqual(originalValue, newValue)) {
                // if they are not equal, it's been modified!
                bindingResult.addModifiedPath(propertyName);
            }
        } catch (Exception e) {
            // failsafe here as well
        }
    }
}

From source file:org.openengsb.connector.usernamepassword.internal.UsernamePasswordServiceImpl.java

@Override
public Authentication authenticate(String username, Credentials credentials) throws AuthenticationException {
    String actualPassword;/*  w  w  w .j  a v  a  2  s .  c o m*/
    try {
        actualPassword = userManager.getUserCredentials(username, "password");
    } catch (UserNotFoundException e) {
        throw new AuthenticationException(e);
    }
    String givenPassword = ((Password) credentials).getValue();
    if (ObjectUtils.notEqual(givenPassword, actualPassword)) {
        throw new AuthenticationException("wrong password");
    }
    Authentication authentication = new Authentication(username);
    return authentication;

}