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

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

Introduction

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

Prototype

public static boolean equals(Object object1, Object object2) 

Source Link

Document

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

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

Usage

From source file:com.opengamma.analytics.financial.simpleinstruments.pricing.SimpleFutureDataBundle.java

@Override
public boolean equals(final Object obj) {
    if (this == obj) {
        return true;
    }// w w w  .ja va2 s  .c o  m
    if (obj == null) {
        return false;
    }
    if (getClass() != obj.getClass()) {
        return false;
    }
    final SimpleFutureDataBundle other = (SimpleFutureDataBundle) obj;
    if (Double.doubleToLongBits(_costOfCarry) != Double.doubleToLongBits(other._costOfCarry)) {
        return false;
    }
    if (Double.doubleToLongBits(_spot) != Double.doubleToLongBits(other._spot)) {
        return false;
    }
    if (!ObjectUtils.equals(_yieldCurve, other._yieldCurve)) {
        return false;
    }
    return true;
}

From source file:com.opengamma.analytics.financial.var.parametric.DeltaCovarianceMatrixStandardDeviationCalculator.java

@Override
public boolean equals(final Object obj) {
    if (this == obj) {
        return true;
    }//from ww  w  . jav a2  s  . c o m
    if (obj == null) {
        return false;
    }
    if (getClass() != obj.getClass()) {
        return false;
    }
    final DeltaCovarianceMatrixStandardDeviationCalculator other = (DeltaCovarianceMatrixStandardDeviationCalculator) obj;
    return ObjectUtils.equals(_algebra, other._algebra);
}

From source file:com.ocs.dynamo.domain.model.util.EntityModelUtil.java

/**
 * Compares two entities based on the entity model and reports a list of the differences
 * //ww  w . j  ava  2s  .c o m
 * @param oldEntity
 *            the old entity
 * @param newEntity
 *            the new entity
 * @param model
 *            the entity model
 * @param entityModelFactory
 * @param messageService
 *            the message service
 * @param ignore
 *            the names of the fields to ignore
 */
public static List<String> compare(Object oldEntity, Object newEntity, EntityModel<?> model,
        EntityModelFactory entityModelFactory, MessageService messageService, String... ignore) {
    List<String> results = new ArrayList<>();

    Set<String> toIgnore = new HashSet<>();
    if (ignore != null) {
        toIgnore = Sets.newHashSet(ignore);
    }
    toIgnore.addAll(ALWAYS_IGNORE);

    String noValue = messageService.getMessage("ocs.no.value");

    for (AttributeModel am : model.getAttributeModels()) {
        if ((AttributeType.BASIC.equals(am.getAttributeType())
                || AttributeType.MASTER.equals(am.getAttributeType())) && !toIgnore.contains(am.getName())) {

            Object oldValue = ClassUtils.getFieldValue(oldEntity, am.getName());
            Object newValue = ClassUtils.getFieldValue(newEntity, am.getName());

            if (!ObjectUtils.equals(oldValue, newValue)) {
                String oldValueStr = TableUtils.formatPropertyValue(entityModelFactory, model, messageService,
                        am.getName(), oldValue);
                String newValueStr = TableUtils.formatPropertyValue(entityModelFactory, model, messageService,
                        am.getName(), newValue);
                results.add(messageService.getMessage("ocs.value.changed", am.getDisplayName(),
                        oldValue == null ? noValue : oldValueStr, newValue == null ? noValue : newValueStr));
            }
        } else if (AttributeType.DETAIL.equals(am.getAttributeType())) {
            Collection<?> ocol = (Collection<?>) ClassUtils.getFieldValue(oldEntity, am.getName());
            Collection<?> ncol = (Collection<?>) ClassUtils.getFieldValue(newEntity, am.getName());

            for (Object o : ncol) {
                if (!ocol.contains(o)) {
                    results.add(messageService.getMessage("ocs.value.added",
                            getDescription(o, am.getNestedEntityModel()), am.getDisplayName()));
                }
            }

            for (Object o : ocol) {
                if (!ncol.contains(o)) {
                    results.add(messageService.getMessage("ocs.value.removed",
                            getDescription(o, am.getNestedEntityModel()), am.getDisplayName()));
                }
            }

            for (Object o : ocol) {
                for (Object o2 : ncol) {
                    if (o.equals(o2)) {
                        List<String> nested = compare(o, o2, am.getNestedEntityModel(), entityModelFactory,
                                messageService, ignore);
                        results.addAll(nested);
                    }
                }
            }

        }
    }
    return results;
}

From source file:com.opengamma.master.config.impl.MockViewDefinition.java

@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }//from  w ww .j ava  2  s .c  o  m

    if (!(obj instanceof MockViewDefinition)) {
        return false;
    }

    MockViewDefinition other = (MockViewDefinition) obj;
    boolean basicPropertiesEqual = ObjectUtils.equals(getName(), other.getName())
            && ObjectUtils.equals(getPortfolioId(), other.getPortfolioId());
    if (!basicPropertiesEqual) {
        return false;
    }
    return true;
}

From source file:com.haulmont.cuba.core.entity.KeyValueEntity.java

@Override
public void setValue(String name, Object value, boolean checkEquals) {
    Object oldValue = getValue(name);
    if ((!checkEquals) || (!ObjectUtils.equals(oldValue, value))) {
        properties.put(name, value);//from  www .j a v a2s .c  om
        propertyChanged(name, oldValue, value);
    }
}

From source file:com.haulmont.cuba.gui.data.impl.testmodel1.TestDetailEntity.java

public void setEmbeddable(TestEmbeddableEntity embeddable) {
    TestEmbeddableEntity o = this.embeddable;
    this.embeddable = embeddable;
    if (!ObjectUtils.equals(o, embeddable))
        propertyChanged("embeddable", o, embeddable);
}

From source file:de.codesourcery.jasm16.ast.OperatorNode.java

@Override
public boolean equals(Object obj) {
    if (obj == this) {
        return true;
    }//from w ww.  ja  v a 2 s  .c  o m
    if (obj instanceof OperatorNode) {
        return ObjectUtils.equals(operator, ((OperatorNode) obj).operator);
    }
    return false;
}

From source file:com.opengamma.analytics.financial.instrument.index.GeneratorInstrument.java

@Override
public boolean equals(final Object obj) {
    if (this == obj) {
        return true;
    }//w  w w .java  2 s.co  m
    if (obj == null) {
        return false;
    }
    if (getClass() != obj.getClass()) {
        return false;
    }
    final GeneratorInstrument<?> other = (GeneratorInstrument<?>) obj;
    if (!ObjectUtils.equals(_name, other._name)) {
        return false;
    }
    return true;
}

From source file:com.github.k0zka.contentcompress.ContentGzipMojo.java

public void execute() throws MojoExecutionException {
    getLog().info("Compressing static resources with gzip...");
    try {/*from   w ww . java  2 s  .  c o  m*/
        if (!ObjectUtils.equals(webappDirectory, outputDirectory)) {
            FileUtils.copyDirectory(webappDirectory, outputDirectory, new DotNotFilter());
        }
        seekAndGzip(outputDirectory);
    } catch (IOException e) {
        throw new MojoExecutionException("IO exception when gzipping files", e);
    }
}

From source file:com.ocs.dynamo.filter.Contains.java

@Override
public boolean equals(Object obj) {
    // Only objects of the same class can be equal
    if (obj == null || !getClass().equals(obj.getClass())) {
        return false;
    }/*from  ww w .  j a  v a2  s.co m*/
    Contains c = (Contains) obj;

    return ObjectUtils.equals(propertyId, c.getPropertyId()) && ObjectUtils.equals(value, c.getValue());
}