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.guiceyfruit.spring.testbeans.TestBean.java

public boolean equals(Object other) {
    if (this == other) {
        return true;
    }/*  w w  w.java  2 s  . co  m*/
    if (other == null || !(other instanceof TestBean)) {
        return false;
    }
    TestBean tb2 = (TestBean) other;
    return (ObjectUtils.nullSafeEquals(this.name, tb2.name) && this.age == tb2.age);
}

From source file:com.springsource.hq.plugin.tcserver.serverconfig.services.connector.Connector.java

public void validate(Object target, Errors errors) {
    Connector connector = (Connector) target;
    if (!errors.hasFieldErrors("port")) {
        if (connector.getPort() == null) {
            errors.rejectValue("port", "service.connector.port.required");
        } else if (connector.getPort() < 0 || connector.getPort() > 65535) {
            errors.rejectValue("port", "invalid.port");
        }//from  w w w . jav  a2  s  .  c o m
    }

    if (!errors.hasFieldErrors("proxyPort")) {
        if (connector.getProxyPort() != null) {
            if (connector.getProxyPort() < 0 || connector.getProxyPort() > 65535) {
                errors.rejectValue("proxyPort", "invalid.port");
            }
        }
    }
    if (!errors.hasFieldErrors("redirectPort")) {
        if (connector.getRedirectPort() != null) {
            if (connector.getRedirectPort() < 0 || connector.getRedirectPort() > 65535) {
                errors.rejectValue("redirectPort", "invalid.port");
            }
        }
    }
    if (!errors.hasFieldErrors("connectionTimeout")) {
        if (connector.getConnectionTimeout() != null) {
            if (connector.getConnectionTimeout() < 0) {
                errors.rejectValue("connectionTimeout", "service.connector.connectionTimeout.tooLow");
            }
        }
    }
    if (!errors.hasFieldErrors("maxThreads")) {
        if (connector.getMaxThreads() != null) {
            if (connector.getMaxThreads() < 1) {
                errors.rejectValue("maxThreads", "service.connector.maxThreads.tooLow");
            }
        }
    }
    if (connector.parent() != null) {
        for (Service service : connector.parent().parent().getServices()) {
            for (Connector c : service.getConnectors()) {
                if (c != connector && ObjectUtils.nullSafeEquals(c.getAddress(), connector.getAddress())
                        && (connector.getPort() != null)
                        && ObjectUtils.nullSafeEquals(c.getPort(), connector.getPort())) {
                    errors.reject("service.connector.unique",
                            new Object[] { connector.getAddress(), connector.getPort().toString() }, null);
                }
            }
        }
    }
}

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

@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }/*from   w w w .  j  ava 2  s.c  om*/
    if (!(obj instanceof DbcpConnectionPool)) {
        return false;
    }
    DbcpConnectionPool connectionPool = (DbcpConnectionPool) obj;
    return ObjectUtils.nullSafeEquals(this.getAccessToUnderlyingConnectionAllowed(),
            connectionPool.getAccessToUnderlyingConnectionAllowed())
            && ObjectUtils.nullSafeEquals(this.getDefaultAutoCommit(), connectionPool.getDefaultAutoCommit())
            && ObjectUtils.nullSafeEquals(this.getDefaultCatalog(), connectionPool.getDefaultCatalog())
            && ObjectUtils.nullSafeEquals(this.getDefaultReadOnly(), connectionPool.getDefaultReadOnly())
            && ObjectUtils.nullSafeEquals(this.getDefaultTransactionIsolation(),
                    connectionPool.getDefaultTransactionIsolation())
            && ObjectUtils.nullSafeEquals(this.getInitialSize(), connectionPool.getInitialSize())
            && ObjectUtils.nullSafeEquals(this.getLogAbandoned(), connectionPool.getLogAbandoned())
            && ObjectUtils.nullSafeEquals(this.getMaxActive(), connectionPool.getMaxActive())
            && ObjectUtils.nullSafeEquals(this.getMaxIdle(), connectionPool.getMaxIdle())
            && ObjectUtils.nullSafeEquals(this.getMaxOpenPreparedStatements(),
                    connectionPool.getMaxOpenPreparedStatements())
            && ObjectUtils.nullSafeEquals(this.getMaxWait(), connectionPool.getMaxWait())
            && ObjectUtils.nullSafeEquals(this.getMinEvictableIdleTimeMillis(),
                    connectionPool.getMinEvictableIdleTimeMillis())
            && ObjectUtils.nullSafeEquals(this.getMinIdle(), connectionPool.getMinIdle())
            && ObjectUtils.nullSafeEquals(this.getNumTestsPerEvictionRun(),
                    connectionPool.getNumTestsPerEvictionRun())
            && ObjectUtils.nullSafeEquals(this.getPoolPreparedStatements(),
                    connectionPool.getPoolPreparedStatements())
            && ObjectUtils.nullSafeEquals(this.getRemoveAbandoned(), connectionPool.getRemoveAbandoned())
            && ObjectUtils.nullSafeEquals(this.getRemoveAbandonedTimeout(),
                    connectionPool.getRemoveAbandonedTimeout())
            && ObjectUtils.nullSafeEquals(this.getTestOnBorrow(), connectionPool.getTestOnBorrow())
            && ObjectUtils.nullSafeEquals(this.getTestOnReturn(), connectionPool.getTestOnReturn())
            && ObjectUtils.nullSafeEquals(this.getTestWhileIdle(), connectionPool.getTestWhileIdle())
            && ObjectUtils.nullSafeEquals(this.getTimeBetweenEvictionRunsMillis(),
                    connectionPool.getTimeBetweenEvictionRunsMillis())
            && ObjectUtils.nullSafeEquals(this.getValidationQuery(), connectionPool.getValidationQuery());
}

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

@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }/*from www  .j a  v  a 2  s  .c  o  m*/
    if (!(obj instanceof Host)) {
        return false;
    }
    Host host = (Host) obj;
    return ObjectUtils.nullSafeEquals(this.getAppBase(), host.getAppBase())
            && ObjectUtils.nullSafeEquals(this.getAutoDeploy(), host.getAutoDeploy())
            && ObjectUtils.nullSafeEquals(this.getDeployOnStartup(), host.getDeployOnStartup())
            && ObjectUtils.nullSafeEquals(this.getDeployXML(), host.getDeployXML())
            && ObjectUtils.nullSafeEquals(this.getLogging(), host.getLogging())
            && ObjectUtils.nullSafeEquals(this.getName(), host.getName())
            && ObjectUtils.nullSafeEquals(this.getUnpackWARs(), host.getUnpackWARs())
            && ObjectUtils.nullSafeEquals(this.getWorkDir(), host.getWorkDir());
}

From source file:test.beans.BeanTestImpl.java

public boolean equals(Object other) {
    if (this == other) {
        return true;
    }/*from  w ww. j a  v a 2 s  . co  m*/
    if (other == null || !(other instanceof BeanTestImpl)) {
        return false;
    }
    BeanTestImpl tb2 = (BeanTestImpl) other;
    return (ObjectUtils.nullSafeEquals(this.name, tb2.name) && this.age == tb2.age);
}

From source file:com.springsource.hq.plugin.tcserver.serverconfig.services.connector.Connector.java

@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }/*w  ww . jav  a  2  s . c  o  m*/
    if (!(obj instanceof Connector)) {
        return false;
    }
    Connector connector = (Connector) obj;
    return ObjectUtils.nullSafeEquals(this.getAddress(), connector.getAddress())
            && ObjectUtils.nullSafeEquals(this.getConnectionTimeout(), connector.getConnectionTimeout())
            && ObjectUtils.nullSafeEquals(this.getMaxThreads(), connector.getMaxThreads())
            && ObjectUtils.nullSafeEquals(this.getPort(), connector.getPort())
            && ObjectUtils.nullSafeEquals(this.getProxyName(), connector.getProxyName())
            && ObjectUtils.nullSafeEquals(this.getProxyPort(), connector.getProxyPort())
            && ObjectUtils.nullSafeEquals(this.getRedirectPort(), connector.getRedirectPort())
            && ObjectUtils.nullSafeEquals(this.getScheme(), connector.getScheme());
}

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

@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }//from ww  w .  ja va  2  s. co  m
    if (!(obj instanceof TomcatConnectionPool)) {
        return false;
    }
    TomcatConnectionPool tomcatConnectionPool = (TomcatConnectionPool) obj;
    return ObjectUtils.nullSafeEquals(this.getFairQueue(), tomcatConnectionPool.getFairQueue())
            && ObjectUtils.nullSafeEquals(this.getInitSQL(), tomcatConnectionPool.getInitSQL())
            && ObjectUtils.nullSafeEquals(this.getJdbcInterceptors(),
                    tomcatConnectionPool.getJdbcInterceptors())
            && ObjectUtils.nullSafeEquals(this.getJmxEnabled(), tomcatConnectionPool.getJmxEnabled())
            && ObjectUtils.nullSafeEquals(this.getUseEquals(), tomcatConnectionPool.getUseEquals())
            && ObjectUtils.nullSafeEquals(this.getValidationInterval(),
                    tomcatConnectionPool.getValidationInterval())
            && ObjectUtils.nullSafeEquals(this.getDefaultAutoCommit(),
                    tomcatConnectionPool.getDefaultAutoCommit())
            && ObjectUtils.nullSafeEquals(this.getDefaultCatalog(), tomcatConnectionPool.getDefaultCatalog())
            && ObjectUtils.nullSafeEquals(this.getDefaultReadOnly(), tomcatConnectionPool.getDefaultReadOnly())
            && ObjectUtils.nullSafeEquals(this.getDefaultTransactionIsolation(),
                    tomcatConnectionPool.getDefaultTransactionIsolation())
            && ObjectUtils.nullSafeEquals(this.getInitialSize(), tomcatConnectionPool.getInitialSize())
            && ObjectUtils.nullSafeEquals(this.getLogAbandoned(), tomcatConnectionPool.getLogAbandoned())
            && ObjectUtils.nullSafeEquals(this.getMaxActive(), tomcatConnectionPool.getMaxActive())
            && ObjectUtils.nullSafeEquals(this.getMaxIdle(), tomcatConnectionPool.getMaxIdle())
            && ObjectUtils.nullSafeEquals(this.getMaxWait(), tomcatConnectionPool.getMaxWait())
            && ObjectUtils.nullSafeEquals(this.getMinEvictableIdleTimeMillis(),
                    tomcatConnectionPool.getMinEvictableIdleTimeMillis())
            && ObjectUtils.nullSafeEquals(this.getMinIdle(), tomcatConnectionPool.getMinIdle())
            && ObjectUtils.nullSafeEquals(this.getRemoveAbandoned(), tomcatConnectionPool.getRemoveAbandoned())
            && ObjectUtils.nullSafeEquals(this.getRemoveAbandonedTimeout(),
                    tomcatConnectionPool.getRemoveAbandonedTimeout())
            && ObjectUtils.nullSafeEquals(this.getTestOnBorrow(), tomcatConnectionPool.getTestOnBorrow())
            && ObjectUtils.nullSafeEquals(this.getTestOnReturn(), tomcatConnectionPool.getTestOnReturn())
            && ObjectUtils.nullSafeEquals(this.getTestWhileIdle(), tomcatConnectionPool.getTestWhileIdle())
            && ObjectUtils.nullSafeEquals(this.getTimeBetweenEvictionRunsMillis(),
                    tomcatConnectionPool.getTimeBetweenEvictionRunsMillis())
            && ObjectUtils.nullSafeEquals(this.getValidationQuery(), tomcatConnectionPool.getValidationQuery());
}

From source file:com.turbospaces.spaces.tx.TransactionModificationContext.java

private static void notifyById(final Map<EntryKeyLockQuard, WriteTakeEntry> map, final Object uniqueIdentifier,
        final SpaceNotificationListener listener, final SpaceStore memoryManager, final Object template,
        final boolean returnAsBytes) {
    if (!CollectionUtils.isEmpty(map))
        for (Entry<EntryKeyLockQuard, WriteTakeEntry> next : map.entrySet()) {
            Object keyCandidate = next.getKey().getKey();
            final WriteTakeEntry entry = next.getValue();

            if (ObjectUtils.nullSafeEquals(keyCandidate, uniqueIdentifier) && ObjectUtils.nullSafeEquals(
                    entry.getPersistentEntity().getOriginalPersistentEntity().getType(), template.getClass())) {
                assert entry.getObj() != null;
                memoryManager.getSpaceConfiguration().getListeningExecutorService().execute(new Runnable() {
                    @Override//from w ww  .  j a  v a  2  s  . c  om
                    public void run() {
                        listener.handleNotification(
                                returnAsBytes ? entry.getPointer().getSerializedDataBuffer() : entry.getObj(),
                                entry.getSpaceOperation());
                    }
                });
            }
        }
}

From source file:cat.albirar.framework.dynabean.impl.DynaBeanImpl.java

/**
 * Dynamically implemented {@link Object#equals(Object)} method.
 * //  ww w .  j  a va  2s. c om
 * @param oOrigin The 'other' object
 * @return as equals specification
 * @see java.lang.Object#equals(java.lang.Object)
 */
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public boolean equals(Object oOrigin) {
    T theOther;
    DynaBeanImpl theOtherDynaBean = null;
    Object o;

    // Check if 'other' is a null
    if (oOrigin == null) {
        return false;
    }
    if (Proxy.isProxyClass(oOrigin.getClass())) {
        o = Proxy.getInvocationHandler(oOrigin);
    } else {
        o = oOrigin;
    }
    // Check for self-equals...
    if (o == this) {
        return true;
    }
    // Check if 'the other' is a 'implementedType' type...
    if (descriptor.getImplementedType().isAssignableFrom(o.getClass()) == false) {
        // ...if not, can be a dynaBean?...
        if (DynaBeanImpl.class.isAssignableFrom(o.getClass())) {
            theOtherDynaBean = (DynaBeanImpl) o;

            // Yes, check if the implementedType is the same or derived
            if (getImplementedType().isAssignableFrom(theOtherDynaBean.getImplementedType()) == false) {
                return false;
            }
        } else {
            // Is not implemented type nor ProxyBeanImpl...
            return false;
        }
    }
    theOther = (T) o;
    for (DynaBeanPropertyDescriptor property : descriptor.getProperties()) {
        try {
            Object value;
            if (theOtherDynaBean != null) {
                value = theOtherDynaBean.values.get(property.propertyName);
            } else {
                value = property.getterMethod.invoke(theOther);
            }

            if (ObjectUtils.nullSafeEquals(values.get(property.propertyName), value) == false) {
                return false;
            }
        } catch (SecurityException | IllegalArgumentException | IllegalAccessException
                | InvocationTargetException e) {
            throw new RuntimeException("On equals call!", e);
        }
    }
    return true;
}

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

@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }/*from   w  w  w. j  av a2  s .c  om*/
    if (!(obj instanceof JspDefaults)) {
        return false;
    }
    JspDefaults jspDefaults = (JspDefaults) obj;
    return ObjectUtils.nullSafeEquals(this.getCheckInterval(), jspDefaults.getCheckInterval())
            && ObjectUtils.nullSafeEquals(this.getClassdebuginfo(), jspDefaults.getClassdebuginfo())
            && ObjectUtils.nullSafeEquals(this.getCompiler(), jspDefaults.getCompiler())
            && ObjectUtils.nullSafeEquals(this.getCompilerSourceVM(), jspDefaults.getCompilerSourceVM())
            && ObjectUtils.nullSafeEquals(this.getCompilerTargetVM(), jspDefaults.getCompilerTargetVM())
            && ObjectUtils.nullSafeEquals(this.getDevelopment(), jspDefaults.getDevelopment())
            && ObjectUtils.nullSafeEquals(this.getDisplaySourceFragment(),
                    jspDefaults.getDisplaySourceFragment())
            && ObjectUtils.nullSafeEquals(this.getDumpSmap(), jspDefaults.getDumpSmap())
            && ObjectUtils.nullSafeEquals(this.getEnablePooling(), jspDefaults.getEnablePooling())
            && ObjectUtils.nullSafeEquals(this.getEngineOptionsClass(), jspDefaults.getEngineOptionsClass())
            && ObjectUtils.nullSafeEquals(this.getErrorOnUseBeanInvalidClassAttribute(),
                    jspDefaults.getErrorOnUseBeanInvalidClassAttribute())
            && ObjectUtils.nullSafeEquals(this.getFork(), jspDefaults.getFork())
            && ObjectUtils.nullSafeEquals(this.getGenStrAsCharArray(), jspDefaults.getGenStrAsCharArray())
            && ObjectUtils.nullSafeEquals(this.getIeClassId(), jspDefaults.getIeClassId())
            && ObjectUtils.nullSafeEquals(this.getJavaEncoding(), jspDefaults.getJavaEncoding())
            && ObjectUtils.nullSafeEquals(this.getKeepgenerated(), jspDefaults.getKeepgenerated())
            && ObjectUtils.nullSafeEquals(this.getMappedfile(), jspDefaults.getMappedfile())
            && ObjectUtils.nullSafeEquals(this.getModificationTestInterval(),
                    jspDefaults.getModificationTestInterval())
            && ObjectUtils.nullSafeEquals(this.getScratchdir(), jspDefaults.getScratchdir())
            && ObjectUtils.nullSafeEquals(this.getSuppressSmap(), jspDefaults.getSuppressSmap())
            && ObjectUtils.nullSafeEquals(this.getTrimSpaces(), jspDefaults.getTrimSpaces())
            && ObjectUtils.nullSafeEquals(this.getXpoweredBy(), jspDefaults.getXpoweredBy());
}