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:com.springsource.hq.plugin.tcserver.serverconfig.configuration.Configuration.java

@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }/* ww w .j  ava2 s.c  o  m*/
    if (!(obj instanceof Configuration)) {
        return false;
    }
    Configuration configuration = (Configuration) obj;
    return ObjectUtils.nullSafeEquals(this.getContextContainer(), configuration.getContextContainer())
            && ObjectUtils.nullSafeEquals(this.getGeneralConfig(), configuration.getGeneralConfig())
            && ObjectUtils.nullSafeEquals(this.getEnvironment(), configuration.getEnvironment())
            && ObjectUtils.nullSafeEquals(this.getServerDefaults(), configuration.getServerDefaults());
}

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

@RequestMapping(value = "/{token}", method = RequestMethod.PUT)
public String reset(@PathVariable String token,
        @Validated @ModelAttribute(FORM_MODEL_KEY) PasswordResetForm form, BindingResult errors,
        BlogLanguage blogLanguage, RedirectAttributes redirectAttributes) {
    redirectAttributes.addFlashAttribute(FORM_MODEL_KEY, form);
    redirectAttributes.addFlashAttribute(ERRORS_MODEL_KEY, errors);

    PasswordResetToken passwordResetToken = userService.getPasswordResetToken(token);
    if (passwordResetToken == null) {
        redirectAttributes.addFlashAttribute(INVALID_PASSOWRD_RESET_LINK_ATTR_NAME, true);
        return "redirect:/password-reset";
    }//  w  ww. j  a va 2s . co m
    LocalDateTime now = LocalDateTime.now();
    if (now.isAfter(passwordResetToken.getExpiredAt())) {
        redirectAttributes.addFlashAttribute(INVALID_PASSOWRD_RESET_LINK_ATTR_NAME, true);
        return "redirect:/password-reset";
    }

    if (!errors.hasFieldErrors("newPassword")) {
        if (!ObjectUtils.nullSafeEquals(form.getNewPassword(), form.getNewPasswordRetype())) {
            errors.rejectValue("newPasswordRetype", "MatchRetype");
        }
    }
    if (errors.hasFieldErrors("newPassword*")) {
        return "redirect:/password-reset/{token}";
    }

    PasswordUpdateRequest request = new PasswordUpdateRequest().withUserId(passwordResetToken.getUser().getId())
            .withPassword(form.getNewPassword()).withLanguage(blogLanguage.getLanguage());
    userService.updatePassword(request, passwordResetToken);

    redirectAttributes.getFlashAttributes().clear();
    return "redirect:/login";
}

From source file:com.springsource.hq.plugin.tcserver.serverconfig.configuration.serverdefaults.StaticDefaults.java

@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }/*  www.ja  va2  s.c o m*/
    if (!(obj instanceof StaticDefaults)) {
        return false;
    }
    StaticDefaults staticDefaults = (StaticDefaults) obj;
    return ObjectUtils.nullSafeEquals(this.getDebug(), staticDefaults.getDebug())
            && ObjectUtils.nullSafeEquals(this.getFileEncoding(), staticDefaults.getFileEncoding())
            && ObjectUtils.nullSafeEquals(this.getInput(), staticDefaults.getInput())
            && ObjectUtils.nullSafeEquals(this.getListings(), staticDefaults.getListings())
            && ObjectUtils.nullSafeEquals(this.getOutput(), staticDefaults.getOutput())
            && ObjectUtils.nullSafeEquals(this.getReadmeFile(), staticDefaults.getReadmeFile())
            && ObjectUtils.nullSafeEquals(this.getReadonly(), staticDefaults.getReadonly())
            && ObjectUtils.nullSafeEquals(this.getSendfileSize(), staticDefaults.getSendfileSize());
}

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

@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }// www .  j a v a  2s .co  m
    if (!(obj instanceof Memory)) {
        return false;
    }
    Memory memory = (Memory) obj;
    return ObjectUtils.nullSafeEquals(this.getMaxNewSize(), memory.getMaxNewSize())
            && ObjectUtils.nullSafeEquals(this.getMaxPermSize(), memory.getMaxPermSize())
            && ObjectUtils.nullSafeEquals(this.getMs(), memory.getMs())
            && ObjectUtils.nullSafeEquals(this.getMx(), memory.getMx())
            && ObjectUtils.nullSafeEquals(this.getNewSize(), memory.getNewSize())
            && ObjectUtils.nullSafeEquals(this.getPermSize(), memory.getPermSize())
            && ObjectUtils.nullSafeEquals(this.getSs(), memory.getSs());
}

From source file:org.springmodules.validation.bean.conf.loader.xml.handler.AbstractPropertyValidationElementHandler.java

/**
 * Determines whether the given element is supported by this handler. The check is done by comparing the element
 * tag name and namespace with the ones that are configured with this handler.
 *
 * @see org.springmodules.validation.bean.conf.loader.xml.handler.PropertyValidationElementHandler#supports(org.w3c.dom.Element, Class, java.beans.PropertyDescriptor)
 *///from  ww  w.j  a v  a 2  s  .c  o  m
public boolean supports(Element element, Class clazz, PropertyDescriptor descriptor) {
    String localName = element.getLocalName();
    if (!localName.equals(elementName)) {
        return false;
    }
    String ns = element.getNamespaceURI();
    return ObjectUtils.nullSafeEquals(ns, namespaceUri);
}

From source file:com.googlecode.flyway.core.validation.DbValidator.java

/**
 * Validate the checksum of all existing sql migration in the metadata table with the checksum of the sql migrations
 * in the classpath/*from ww  w.ja  v  a 2  s  . co m*/
 *
 * @param resolvedMigrations All migrations available on the classpath, sorted by version, newest first.
 * @return description of validation error or NULL if no validation error was found
 */
public String validate(List<Migration> resolvedMigrations) {
    if (ValidationMode.NONE.equals(validationMode)) {
        return null;
    }

    LOG.debug(String.format("Validating (mode %s) migrations ...", validationMode));
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();

    final List<MetaDataTableRow> appliedMigrations = new ArrayList<MetaDataTableRow>(
            metaDataTable.allAppliedMigrations());
    if (appliedMigrations.isEmpty()) {
        LOG.info("No migrations applied yet. No validation necessary.");
        return null;
    }

    List<Migration> migrations = new ArrayList<Migration>(resolvedMigrations);
    // migrations now with newest last
    Collections.reverse(migrations);
    final MetaDataTableRow firstAppliedMigration = appliedMigrations.get(0);
    if (MigrationType.INIT.equals(firstAppliedMigration.getMigrationType())) {
        // if first migration is INIT, just check checksum of following migrations
        final SchemaVersion initVersion = firstAppliedMigration.getVersion();
        appliedMigrations.remove(firstAppliedMigration);

        Iterator<Migration> iterator = migrations.iterator();
        while (iterator.hasNext()) {
            Migration migration = iterator.next();
            if (migration.getVersion().compareTo(initVersion) <= 0) {
                iterator.remove();
            }
        }
    }

    if (appliedMigrations.size() > migrations.size()) {
        List<SchemaVersion> schemaVersions = new ArrayList<SchemaVersion>();
        for (MetaDataTableRow metaDataTableRow : appliedMigrations) {
            schemaVersions.add(metaDataTableRow.getVersion());
        }
        for (Migration migration : migrations) {
            schemaVersions.remove(migration.getVersion());
        }

        String diff = StringUtils.collectionToCommaDelimitedString(schemaVersions);

        return String.format(
                "More applied migrations than classpath migrations: DB=%s, Classpath=%s, Missing migrations=(%s)",
                appliedMigrations.size(), migrations.size(), diff);
    }

    for (int i = 0; i < appliedMigrations.size(); i++) {
        MetaDataTableRow appliedMigration = appliedMigrations.get(i);
        //Migrations are sorted in the opposite order: newest first.
        Migration classpathMigration = migrations.get(i);

        if (!appliedMigration.getVersion().equals(classpathMigration.getVersion())) {
            return String.format("Version mismatch for migration %s: DB=%s, Classpath=%s",
                    appliedMigration.getScript(), appliedMigration.getVersion(),
                    classpathMigration.getVersion());

        }
        if (!appliedMigration.getMigrationType().equals(classpathMigration.getMigrationType())) {
            return String.format("Migration Type mismatch for migration %s: DB=%s, Classpath=%s",
                    appliedMigration.getScript(), appliedMigration.getMigrationType(),
                    classpathMigration.getMigrationType());
        }

        final Integer appliedChecksum = appliedMigration.getChecksum();
        final Integer classpathChecksum = classpathMigration.getChecksum();
        if (!ObjectUtils.nullSafeEquals(appliedChecksum, classpathChecksum)) {
            return String.format("Checksum mismatch for migration %s: DB=%s, Classpath=%s",
                    appliedMigration.getScript(), appliedChecksum, classpathMigration.getChecksum());
        }
    }

    stopWatch.stop();
    if (appliedMigrations.size() == 1) {
        LOG.info(String.format("Validated 1 migration (mode: %s) (execution time %s)", validationMode,
                TimeFormat.format(stopWatch.getTotalTimeMillis())));
    } else {
        LOG.info(String.format("Validated %d migrations (mode: %s) (execution time %s)",
                appliedMigrations.size(), validationMode, TimeFormat.format(stopWatch.getTotalTimeMillis())));
    }

    return null;
}

From source file:cat.albirar.framework.dynabean.impl.models.test.ModelImpl.java

/**
 * {@inheritDoc}/*from   w ww  .  j av a 2  s .  c  o  m*/
 */
@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    if (obj == null || IModel.class.isAssignableFrom(obj.getClass()) == false) {
        return false;
    }
    IModel other = (IModel) obj;

    return (id == other.getId() && ObjectUtils.nullSafeEquals(name, other.getName())
            && ObjectUtils.nullSafeEquals(lastName, other.getLastName())
            && ObjectUtils.nullSafeEquals(birthDate, other.getBirthDate())
            && ObjectUtils.nullSafeEquals(gender, other.getGender())
            && numberOfChildren == other.getNumberOfChildren() && incomingYear == other.getIncomingYear()
            && ObjectUtils.nullSafeEquals(names, other.getNames()));
}

From source file:com.springsource.hq.plugin.tcserver.serverconfig.services.engine.Engine.java

@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }/*ww w.j ava  2s  . co  m*/
    if (!(obj instanceof Engine)) {
        return false;
    }
    Engine host = (Engine) obj;
    return ObjectUtils.nullSafeEquals(this.getDefaultHost(), host.getDefaultHost())
            && ObjectUtils.nullSafeEquals(this.getHosts(), host.getHosts())
            && ObjectUtils.nullSafeEquals(this.getJvmRoute(), host.getJvmRoute())
            && ObjectUtils.nullSafeEquals(this.getLogging(), host.getLogging())
            && ObjectUtils.nullSafeEquals(this.getName(), host.getName())
            && ObjectUtils.nullSafeEquals(this.getThreadDiagnostics(), host.getThreadDiagnostics());
}

From source file:com.springsource.hq.plugin.tcserver.serverconfig.configuration.general.JmxListener.java

@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }//from w w w.j av a 2s . c om
    if (!(obj instanceof JmxListener)) {
        return false;
    }
    JmxListener serverProperties = (JmxListener) obj;
    return ObjectUtils.nullSafeEquals(this.getAccessFile(), serverProperties.getAccessFile())
            && ObjectUtils.nullSafeEquals(this.getAuthenticate(), serverProperties.getAuthenticate())
            && ObjectUtils.nullSafeEquals(this.getBind(), serverProperties.getBind())
            && ObjectUtils.nullSafeEquals(this.getCipherSuites(), serverProperties.getCipherSuites())
            && ObjectUtils.nullSafeEquals(this.getClientAuth(), serverProperties.getClientAuth())
            && ObjectUtils.nullSafeEquals(this.getKeystoreFile(), serverProperties.getKeystoreFile())
            && ObjectUtils.nullSafeEquals(this.getKeystorePass(), serverProperties.getKeystorePass())
            && ObjectUtils.nullSafeEquals(this.getPasswordFile(), serverProperties.getPasswordFile())
            && ObjectUtils.nullSafeEquals(this.getPort(), serverProperties.getPort())
            && ObjectUtils.nullSafeEquals(this.getProtocols(), serverProperties.getProtocols())
            && ObjectUtils.nullSafeEquals(this.getTruststoreFile(), serverProperties.getTruststoreFile())
            && ObjectUtils.nullSafeEquals(this.getTruststorePass(), serverProperties.getTruststorePass())
            && ObjectUtils.nullSafeEquals(this.getUseJdkClientFactory(),
                    serverProperties.getUseJdkClientFactory())
            && ObjectUtils.nullSafeEquals(this.getUseSSL(), serverProperties.getUseSSL());
}

From source file:ru.anr.base.BaseParent.java

/**
 * Returns the result of the equals operation even if the arguments are
 * null./*from w w  w.ja  v a2  s . c  o  m*/
 * 
 * @param arg1
 *            A first argument
 * @param arg2
 *            A second argument
 * @return The result of the equals operation or false if one or both
 *         arguments are null
 */
public static boolean safeEquals(Object arg1, Object arg2) {

    return ObjectUtils.nullSafeEquals(arg1, arg2);
}