Example usage for org.springframework.util ObjectUtils nullSafeEquals

List of usage examples for org.springframework.util ObjectUtils nullSafeEquals

Introduction

In this page you can find the example usage for org.springframework.util ObjectUtils nullSafeEquals.

Prototype

public static boolean nullSafeEquals(@Nullable Object o1, @Nullable Object o2) 

Source Link

Document

Determine if the given objects are equal, returning true if both are null or false if only one is null .

Usage

From source file:org.hdiv.web.servlet.tags.form.SelectedValueComparatorHDIV.java

/**
 * Returns <code>true</code> if the supplied candidate value is equal to the value bound to
 * the supplied {@link BindStatus}. Equality in this case differs from standard Java equality and
 * is described in more detail <a href="#equality-contract">here</a>.
 *//*from   w  ww .  jav  a  2s. c om*/
public static boolean isSelected(BindStatus bindStatus, Object candidateValue) {
    if (bindStatus == null) {
        return (candidateValue == null);
    }

    // Check obvious equality matches with the candidate first,
    // both with the rendered value and with the original value.
    Object boundValue = bindStatus.getValue();
    if (ObjectUtils.nullSafeEquals(boundValue, candidateValue)) {
        return true;
    }
    Object actualValue = bindStatus.getActualValue();
    if (actualValue != null && actualValue != boundValue
            && ObjectUtils.nullSafeEquals(actualValue, candidateValue)) {
        return true;
    }
    if (actualValue != null) {
        boundValue = actualValue;
    } else if (boundValue == null) {
        return false;
    }

    // Non-null value but no obvious equality with the candidate value:
    // go into more exhaustive comparisons.
    boolean selected = false;
    if (boundValue.getClass().isArray()) {
        selected = collectionCompare(CollectionUtils.arrayToList(boundValue), candidateValue, bindStatus);
    } else if (boundValue instanceof Collection) {
        selected = collectionCompare((Collection) boundValue, candidateValue, bindStatus);
    } else if (boundValue instanceof Map) {
        selected = mapCompare((Map) boundValue, candidateValue, bindStatus);
    }
    if (!selected) {
        selected = exhaustiveCompare(boundValue, candidateValue, bindStatus.getEditor(), null);
    }
    return selected;
}

From source file:org.wallride.web.controller.guest.user.PasswordUpdateController.java

@RequestMapping(method = RequestMethod.PUT)
public String update(@Validated @ModelAttribute(FORM_MODEL_KEY) PasswordUpdateForm form, BindingResult errors,
        AuthorizedUser authorizedUser, RedirectAttributes redirectAttributes) {
    redirectAttributes.addFlashAttribute(FORM_MODEL_KEY, form);
    redirectAttributes.addFlashAttribute(ERRORS_MODEL_KEY, errors);

    if (!errors.hasFieldErrors("newPassword")) {
        if (!ObjectUtils.nullSafeEquals(form.getNewPassword(), form.getNewPasswordRetype())) {
            errors.rejectValue("newPasswordRetype", "MatchRetype");
        }/*  w  w  w .  j a v  a2  s  .com*/
    }

    if (!errors.hasErrors()) {
        User user = userService.getUserById(authorizedUser.getId());
        PasswordEncoder passwordEncoder = new StandardPasswordEncoder();
        if (!passwordEncoder.matches(form.getCurrentPassword(), user.getLoginPassword())) {
            errors.rejectValue("currentPassword", "MatchCurrentPassword");
        }
    }

    if (errors.hasErrors()) {
        return "redirect:/settings/password?step.edit";
    }

    PasswordUpdateRequest request = new PasswordUpdateRequest().withUserId(authorizedUser.getId())
            .withPassword(form.getNewPassword());
    userService.updatePassword(request, authorizedUser);

    redirectAttributes.getFlashAttributes().clear();
    redirectAttributes.addFlashAttribute("updatedPassword", true);
    return "redirect:/settings/password";
}

From source file:org.springmodules.cache.config.DomElementStub.java

/**
 * @see java.lang.Object#equals(java.lang.Object)
 *///from  ww w .ja va2s. c  om
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    if (!(obj instanceof DomElementStub)) {
        return false;
    }

    DomElementStub other = (DomElementStub) obj;

    if (!ObjectUtils.nullSafeEquals(nodeName, other.nodeName)) {
        return false;
    }
    if (!ObjectUtils.nullSafeEquals(attributes, other.attributes)) {
        return false;
    }
    if (!ObjectUtils.nullSafeEquals(children, other.children)) {
        return false;
    }

    return true;
}

From source file:org.eclipse.gemini.blueprint.test.internal.util.ManifestUtilsTest.java

public void testExportEntries() throws Exception {
    Manifest mf = new Manifest();
    Attributes attrs = mf.getMainAttributes();
    String[] packages = new String[] { "foo.bar; version:=1", "bar.foo", "hop.trop" };
    attrs.putValue(Constants.EXPORT_PACKAGE, StringUtils.arrayToCommaDelimitedString(packages));
    createJar(mf);/*from w ww . ja  v  a 2s .c  o  m*/
    String[] entries = ManifestUtils
            .determineImportPackages(new Resource[] { storage.getResource(), storage.getResource() });
    assertEquals(3, entries.length);
    ObjectUtils.nullSafeEquals(packages, entries);
}

From source file:com.springsource.hq.plugin.tcserver.serverconfig.resources.jdbc.DbcpDataSource.java

@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }//from   w ww  .  ja v  a  2  s .  c om
    if (!(obj instanceof DbcpDataSource)) {
        return false;
    }
    DbcpDataSource dataSource = (DbcpDataSource) obj;
    return ObjectUtils.nullSafeEquals(this.getConnection(), dataSource.getConnection())
            && ObjectUtils.nullSafeEquals(this.getConnectionPool(), dataSource.getConnectionPool())
            && ObjectUtils.nullSafeEquals(this.getGeneral(), dataSource.getGeneral());
}

From source file:com.springsource.hq.plugin.tcserver.serverconfig.resources.jdbc.DataSource.java

@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }/*ww  w  .jav  a2 s  . co  m*/
    if (!(obj instanceof DataSource)) {
        return false;
    }
    DataSource dataSource = (DataSource) obj;
    return ObjectUtils.nullSafeEquals(this.getConnection(), dataSource.getConnection())
            && ObjectUtils.nullSafeEquals(this.getGeneral(), dataSource.getGeneral());
}

From source file:org.springmodules.validation.util.condition.bean.EqualPropertiesBeanCondition.java

/**
 * Checks whether a set of properties of the given bean have the same value. The properties are resolved based on
 * the property names associated with this condition.
 *
 * @param bean The bean to be checked./*w  w  w  .  j a v  a2  s  .  c o  m*/
 * @return <code>true</code> if all the compared properties are equal, <code>false</code> otherwise.
 */
protected boolean checkBean(BeanWrapper bean) {
    Object value = bean.getPropertyValue(propertyNames[0]);
    for (int i = 1; i < propertyNames.length; i++) {
        Object currentValue = bean.getPropertyValue(propertyNames[i]);
        if (!ObjectUtils.nullSafeEquals(value, currentValue)) {
            return false;
        }
    }
    return true;
}

From source file:org.robotframework.swing.tree.TreePathWaitable.java

private boolean nodeTextEquals(String nodeName, Object node) {
    String nodeText = getNodeText(node);
    return ObjectUtils.nullSafeEquals(nodeText, nodeName);
}

From source file:com.springsource.hq.plugin.tcserver.serverconfig.configuration.jvm.Environment.java

@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }//from  ww w.j  av  a  2s  .  c o  m
    if (!(obj instanceof Environment)) {
        return false;
    }
    Environment environment = (Environment) obj;
    return ObjectUtils.nullSafeEquals(this.getJavaHome(), environment.getJavaHome())
            && ObjectUtils.nullSafeEquals(this.getJvmOptions(), environment.getJvmOptions());
}

From source file:org.zkybase.kite.circuitbreaker.interceptor.CircuitBreakerSourcePointcut.java

@Override
public boolean equals(Object other) {
    if (this == other) {
        return true;
    }/*from   w w w. j av a  2 s  .  c o m*/
    if (!(other instanceof CircuitBreakerSourcePointcut)) {
        return false;
    }
    CircuitBreakerSourcePointcut otherPc = (CircuitBreakerSourcePointcut) other;
    return ObjectUtils.nullSafeEquals(source, otherPc.source);
}