Example usage for java.lang Object equals

List of usage examples for java.lang Object equals

Introduction

In this page you can find the example usage for java.lang Object equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Indicates whether some other object is "equal to" this one.

Usage

From source file:com.subakva.formicid.converters.PathConverter.java

public Path convert(Class type, Object value) {
    if (value == null || value.equals(Undefined.instance)) {
        throw new ConversionException("No value specified");
    }/*from  w  ww  . jav a 2 s.  c o  m*/
    if (value instanceof Path) {
        return (Path) value;
    } else if (value instanceof Scriptable) {
        Path path = createNewPath();
        Scriptable js = ((Scriptable) value);
        Object[] ids = js.getIds();
        for (int i = 0; i < ids.length; i++) {
            String id = (String) ids[i];
            Object sub = js.get(id, js);
            path.add(this.convert(type, sub));
        }
        return path;
    } else if (value instanceof String) {
        Path path = createNewPath();
        FileList fileList = new FileList();
        fileList.setProject(getProject());
        fileList.setFiles((String) value);
        path.addFilelist(fileList);
        return path;
    } else {
        throw new ConversionException("" + value);
    }
}

From source file:jmri.InstanceManager.java

/**
 * Set an object of type T as the default for that type.
 * <p>/*  w w w . j  a v  a 2  s.c om*/
 * Also registers (stores) the object if not already present.
 * <p>
 * Now, we do that moving the item to the back of the list; see the
 * {@link #getDefault} method
 *
 * @param <T>  The type of the class
 * @param type The Class object for val
 * @param item The object to make default for type
 * @return The default for type (normally this is the item passed in)
 */
@Nonnull
static public <T> T setDefault(@Nonnull Class<T> type, @Nonnull T item) {
    log.trace("setDefault for type {}", type.getName());
    if (item == null) {
        NullPointerException npe = new NullPointerException();
        log.error("Should not set default of type {} to null value", type.getName());
        throw npe;
    }
    Object oldDefault = containsDefault(type) ? getNullableDefault(type) : null;
    List<T> l = getList(type);
    l.remove(item);
    l.add(item);
    if (oldDefault == null || !oldDefault.equals(item)) {
        getDefault().pcs.firePropertyChange(getDefaultsPropertyName(type), oldDefault, item);
    }
    return getDefault(type);
}

From source file:com.amalto.core.storage.hibernate.EntityFinder.java

/**
 * Starting from <code>wrapper</code>, goes up the containment tree using references introspection in metadata.
 * @param wrapper A {@link Wrapper} instance (so an object managed by {@link HibernateStorage}.
 * @param storage A {@link HibernateStorage} instance. It will be used to compute references from the internal
 *                data model./*from  w w  w . ja  v a2  s.  com*/
 * @param session A Hibernate {@link Session}.
 * @return The top level (aka the Wrapper instance that represent a MDM entity).
 */
public static Wrapper findEntity(Wrapper wrapper, HibernateStorage storage, Session session) {
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    if (!(contextClassLoader instanceof StorageClassLoader)) {
        throw new IllegalStateException("Expects method to be called in the context of a storage operation.");
    }
    StorageClassLoader classLoader = (StorageClassLoader) contextClassLoader;
    ComplexTypeMetadata wrapperType = classLoader.getTypeFromClass(wrapper.getClass());
    if (wrapperType == null) {
        throw new IllegalArgumentException(
                "Wrapper '" + wrapper.getClass().getName() + "' isn't known in current storage.");
    }
    if (wrapperType.isInstantiable()) {
        return wrapper;
    }
    InboundReferences incomingReferences = new InboundReferences(wrapperType);
    InternalRepository internalRepository = storage.getTypeEnhancer();
    Set<ReferenceFieldMetadata> references = internalRepository.getInternalRepository()
            .accept(incomingReferences);
    if (references.isEmpty()) {
        throw new IllegalStateException("Cannot find container type for '" + wrapperType.getName() + "'.");
    }
    String keyFieldName = wrapperType.getKeyFields().iterator().next().getName();
    Object id = wrapper.get(keyFieldName);
    for (ReferenceFieldMetadata reference : references) {
        ComplexTypeMetadata containingType = reference.getContainingType();
        Class<? extends Wrapper> clazz = classLoader.getClassFromType(containingType);
        Criteria criteria = session.createCriteria(clazz, "a0"); //$NON-NLS-1$
        criteria.createAlias("a0." + reference.getName(), "a1", CriteriaSpecification.INNER_JOIN); //$NON-NLS-1$
        criteria.add(Restrictions.eq("a1." + keyFieldName, id)); //$NON-NLS-1$
        List list = criteria.list();
        if (!list.isEmpty()) {
            Wrapper container = (Wrapper) list.get(0);
            if (list.size() > 1) {
                Object previousItem = list.get(0);
                for (int i = 1; i < list.size(); i++) {
                    Object currentItem = list.get(i);
                    if (!previousItem.equals(currentItem)) {
                        throw new IllegalStateException("Expected contained instance to have only one owner.");
                    }
                    previousItem = currentItem;
                }
            }
            return findEntity(container, storage, session);
        }
    }
    return null;
}

From source file:com.playtech.portal.platform.common.util.Validator.java

/**
 * Returns <code>true</code> if the objects are either equal, the same
 * instance, or both <code>null</code>.
 *
 * @param  obj1 the first object// www . jav a 2s  . c o  m
 * @param  obj2 the second object
 * @return <code>true</code> if the objects are either equal, the same
 *         instance, or both <code>null</code>; <code>false</code> otherwise
 */
public static boolean equals(Object obj1, Object obj2) {
    if ((obj1 == null) && (obj2 == null)) {
        return true;
    } else if ((obj1 == null) || (obj2 == null)) {
        return false;
    } else {
        return obj1.equals(obj2);
    }
}

From source file:de.tor.tribes.ui.models.REFTargetTableModel.java

public void addRow(final Village pVillage) {
    Object result = CollectionUtils.find(elements, new Predicate() {

        @Override/*from  w w w .  j  a v  a  2 s  .  co m*/
        public boolean evaluate(Object o) {
            return o.equals(pVillage);
        }
    });

    if (result == null) {
        elements.add(pVillage);
        fireTableDataChanged();
    }
}

From source file:org.codehaus.groovy.grails.scaffolding.DomainClassPropertyComparator.java

public int compare(Object o1, Object o2) {
    if (o1.equals(domainClass.getIdentifier())) {
        return -1;
    }//w  ww .j a v a2  s  .  c om
    if (o2.equals(domainClass.getIdentifier())) {
        return 1;
    }

    GrailsDomainClassProperty prop1 = (GrailsDomainClassProperty) o1;
    GrailsDomainClassProperty prop2 = (GrailsDomainClassProperty) o2;

    ConstrainedProperty cp1 = (ConstrainedProperty) constrainedProperties.get(prop1.getName());
    ConstrainedProperty cp2 = (ConstrainedProperty) constrainedProperties.get(prop2.getName());

    if (cp1 == null & cp2 == null) {
        return prop1.getName().compareTo(prop2.getName());
    }

    if (cp1 == null) {
        return 1;
    }

    if (cp2 == null) {
        return -1;
    }

    if (cp1.getOrder() > cp2.getOrder()) {
        return 1;
    }

    if (cp1.getOrder() < cp2.getOrder()) {
        return -1;
    }

    return 0;
}

From source file:net.sf.jasperreports.crosstabs.fill.calculation.ArbitraryRankComparator.java

@Override
public int compare(Object o1, Object o2) {
    if (o1 == o2 || o1.equals(o2)) {
        return 0;
    }//  w  ww. j  av  a 2s.  c o  m

    long rank1 = rank(o1);
    long rank2 = rank(o2);

    if (rank1 < rank2) {
        return -1;
    }

    if (rank1 > rank2) {
        return 1;
    }

    // this should not happen
    throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_FOUND_OBJECTS_WITH_SAME_RANK, (Object[]) null);
}

From source file:it.unibas.spicygui.controllo.mapping.ActionExportAppendInstancesCsv.java

public void update(Observable o, Object stato) {
    if (stato.equals(LastActionBean.TRANSLATE) || stato.equals(LastActionBean.SOLVE_AND_TRANSLATE)) {
        this.setEnabled(true);
    } else if (stato.equals(LastActionBean.CLOSE) || (stato.equals(LastActionBean.NO_SCENARIO_SELECTED))) {
        this.setEnabled(false);
    }/*from   ww  w .  ja  va  2 s. co  m*/
}

From source file:com.subakva.formicid.converters.ManifestConverter.java

public Manifest convert(Class type, Object value) {
    if (value == null || value.equals(Undefined.instance)) {
        throw new ConversionException("No value specified");
    }//from  ww  w  .  j a  va  2s.c om
    if (value instanceof Manifest) {
        return (Manifest) value;
    } else if (value instanceof String) {
        try {
            Manifest manifest = new Manifest(new FileReader(new File((String) value)));
            return manifest;
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (ManifestException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    } else if (value instanceof Scriptable) {
        Manifest manifest = new Manifest();
        Scriptable props = (Scriptable) value;
        Object[] ids = props.getIds();
        for (int i = 0; i < ids.length; i++) {
            try {
                String attrValue = (String) ids[i];
                String attrName = (String) props.get(attrValue, props);
                Manifest.Attribute attr = new Manifest.Attribute(attrValue, attrName);
                manifest.addConfiguredAttribute(attr);
            } catch (ManifestException e) {
                throw new RuntimeException(e);
            }
        }
        return manifest;
    } else {
        throw new ConversionException("" + value);
    }
}

From source file:com.itemanalysis.psychometrics.cmh.CmhTableRow.java

public boolean validCode(Object rowValue) {
    return rowValue.equals(this.rowValue);
}