Example usage for java.io Serializable equals

List of usage examples for java.io Serializable equals

Introduction

In this page you can find the example usage for java.io Serializable equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

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

Usage

From source file:org.eclipse.ecr.core.storage.sql.HierarchyContext.java

/**
 * Move a child to a new parent with a new name.
 *
 * @param source the source//from  w  w  w  .  j  a v a2s  .co  m
 * @param parentId the destination parent id
 * @param name the new name
 * @throws StorageException
 */
public void move(Node source, Serializable parentId, String name) throws StorageException {
    // a save() has already been done by the caller
    Serializable id = source.getId();
    SimpleFragment hierFragment = source.getHierFragment();
    Serializable oldParentId = hierFragment.get(model.HIER_PARENT_KEY);
    String oldName = hierFragment.getString(model.HIER_CHILD_NAME_KEY);
    if (!oldParentId.equals(parentId)) {
        checkNotUnder(parentId, id, "move");
    } else if (oldName.equals(name)) {
        // null move
        return;
    }
    boolean complexProp = complexProp(hierFragment);
    checkFreeName(parentId, name, complexProp);
    /*
     * Do the move.
     */
    if (!oldName.equals(name)) {
        hierFragment.put(model.HIER_CHILD_NAME_KEY, name);
    }
    removeChild(hierFragment, complexProp);
    hierFragment.put(model.HIER_PARENT_KEY, parentId);
    addExistingChild(hierFragment, complexProp, true);
}

From source file:org.eclipse.ecr.core.storage.sql.HierarchyContext.java

/**
 * Copy a child to a new parent with a new name.
 *
 * @param source the source of the copy//from  w ww.j  a  va2 s .  com
 * @param parentId the destination parent id
 * @param name the new name
 * @return the id of the copy
 */
public Serializable copy(Node source, Serializable parentId, String name) throws StorageException {
    Serializable id = source.getId();
    SimpleFragment hierFragment = source.getHierFragment();
    Serializable oldParentId = hierFragment.get(model.HIER_PARENT_KEY);
    if (!oldParentId.equals(parentId)) {
        checkNotUnder(parentId, id, "copy");
    }
    checkFreeName(parentId, name, complexProp(hierFragment));
    // do the copy

    CopyHierarchyResult res = mapper.copyHierarchy(new IdWithTypes(source), parentId, name, null);
    Serializable newId = res.copyId;
    context.markInvalidated(res.invalidations);
    // adds it as a new child of its parent:
    getHier(newId, false);
    return newId;
}

From source file:org.eclipse.ecr.core.storage.sql.PersistenceContext.java

protected void removeNode(Fragment hierFragment) throws StorageException {
    hierContext.removeNode(hierFragment);

    Serializable id = hierFragment.getId();

    // remove the lock using the lock manager
    session.removeLock(id, null, false);

    // find all the fragments with this id in the maps
    List<Fragment> fragments = new LinkedList<Fragment>();
    for (Fragment fragment : pristine.values()) {
        if (id.equals(fragment.getId())) {
            fragments.add(fragment);//from   w  w w. j a  v  a2  s  .c  o m
        }
    }
    for (Fragment fragment : modified.values()) {
        if (id.equals(fragment.getId())) {
            if (fragment.getState() != State.DELETED) {
                fragments.add(fragment);
            }
        }
    }
    // remove the fragments
    for (Fragment fragment : fragments) {
        removeFragment(fragment);
    }
}

From source file:org.eclipse.ecr.core.storage.sql.Selection.java

/**
 * Gets a fragment given its filtered value.
 * <p>/*from w ww . ja va2s  . c  om*/
 * Returns {@code null} if there is no such fragment.
 * <p>
 * Returns {@link SimpleFragment#UNKNOWN} if there's no info about it.
 *
 * @param filter the value to filter on (cannot be {@code null})
 * @return the fragment, or {@code null}, or {@link SimpleFragment#UNKNOWN}
 */
public SimpleFragment getFragmentByValue(Serializable filter) {
    if (existing != null) {
        for (Serializable id : existing) {
            SimpleFragment fragment;
            try {
                fragment = getFragment(id);
            } catch (StorageException e) {
                log.warn("Failed refetch for: " + id, e);
                continue;
            }
            if (fragment == null) {
                log.warn("Existing fragment missing: " + id);
                continue;
            }
            if (filter.equals(fragmentValue(fragment))) {
                return fragment;
            }
        }
    }
    if (created != null) {
        for (Serializable id : created) {
            SimpleFragment fragment = getFragmentIfPresent(id);
            if (fragment == null) {
                log.warn("Created fragment missing: " + id);
                continue;
            }
            if (filter.equals(fragmentValue(fragment))) {
                return fragment;
            }
        }
    }
    if (deleted != null) {
        for (Serializable id : deleted) {
            SimpleFragment fragment = getFragmentIfPresent(id);
            if (fragment == null) {
                log.warn("Deleted fragment missing: " + id);
                continue;
            }
            if (filter.equals(fragmentValue(fragment))) {
                return null;
            }
        }
    }
    return complete ? null : SimpleFragment.UNKNOWN;
}

From source file:org.eclipse.ecr.core.storage.sql.Selection.java

/**
 * Gets all the fragments, if the selection is complete.
 *
 * @param filter the value to filter on, or {@code null} for the whole
 *            selection//from   ww w  . ja v  a  2s  .  c  o  m
 * @return the fragments, or {@code null} if the list is not known to be
 *         complete
 */
public List<SimpleFragment> getFragmentsByValue(Serializable filter) {
    if (!complete) {
        return null;
    }
    // fetch fragments and maybe filter
    List<SimpleFragment> filtered = new LinkedList<SimpleFragment>();
    if (existing != null) {
        for (Serializable id : existing) {
            SimpleFragment fragment;
            try {
                fragment = getFragment(id);
            } catch (StorageException e) {
                log.warn("Failed refetch for: " + id, e);
                continue;
            }
            if (fragment == null) {
                log.warn("Existing fragment missing: " + id);
                continue;
            }
            if (filter == null || filter.equals(fragmentValue(fragment))) {
                filtered.add(fragment);
            }
        }
    }
    if (created != null) {
        for (Serializable id : created) {
            SimpleFragment fragment = getFragmentIfPresent(id);
            if (fragment == null) {
                log.warn("Created fragment missing: " + id);
                continue;
            }
            if (filter == null || filter.equals(fragmentValue(fragment))) {
                filtered.add(fragment);
            }
        }
    }
    return filtered;
}

From source file:org.force66.beantester.tests.SerializableTest.java

@Override
public boolean testBeanClass(Class<?> klass, Object[] constructorArgs) {
    this.setFailureReason(null);
    Object bean = InstantiationUtils.safeNewInstance(klass, constructorArgs);
    if (bean instanceof Serializable) {
        InjectionUtils.injectValues(bean, valueGeneratorFactory, false);

        Serializable sBean = (Serializable) bean;
        Serializable sBeanReconstituted = null;
        byte[] serializedObj;
        try {/*from  w w w  .  j a  va2 s . c  o m*/
            serializedObj = SerializationUtils.serialize(sBean);
            sBeanReconstituted = SerializationUtils.deserialize(serializedObj);
        } catch (Throwable e) {
            this.setFailureReason("Error serializing bean that implements serializable");
            throw new BeanTesterException("Error serializing bean that implements serializable", e)
                    .addContextValue("class", klass.getName());
        }

        /*
         * An equals() test is only valid if the bean isn't relying on Object.equals().
         */
        Method equalsMethod = MethodUtils.getAccessibleMethod(klass, "equals", Object.class);
        if (!equalsMethod.getDeclaringClass().equals(Object.class) && !sBean.equals(sBeanReconstituted)) {
            this.setFailureReason(
                    "Bean implements serializable, but the reconstituted bean doesn't equal it's original");
            throw new BeanTesterException(
                    "Bean implements serializable, but the reconstituted bean doesn't equal it's original")
                            .addContextValue("class", klass.getName());
        }
    }
    return true;
}

From source file:org.jsecurity.web.session.DefaultWebSessionManager.java

protected void storeSessionId(Serializable currentId, ServletRequest request, ServletResponse response) {
    if (currentId == null) {
        String msg = "sessionId cannot be null when persisting for subsequent requests.";
        throw new IllegalArgumentException(msg);
    }/*from   ww  w  . j  av a  2 s . c o  m*/
    //ensure that the id has been set in the idStore, or if it already has, that it is not different than the
    //'real' session value:
    Serializable existingId = retrieveSessionId(request, response);
    if (existingId == null || !currentId.equals(existingId)) {
        getSessionIdCookieAttribute().storeValue(currentId, request, response);
    }
}

From source file:org.nuxeo.ecm.core.storage.dbs.DBSSession.java

protected void orderBefore(String parentId, String sourceId, String destId) throws DocumentException {
    if (!isOrderable(parentId)) {
        // TODO throw exception?
        return;/*from   ww w .  ja  v  a 2s.com*/
    }
    if (sourceId.equals(destId)) {
        return;
    }
    // This is optimized by assuming the number of children is small enough
    // to be manageable in-memory.
    // fetch children
    List<DBSDocumentState> docStates = transaction.getChildrenStates(parentId);
    // sort children in order
    Collections.sort(docStates, POS_COMPARATOR);
    // renumber
    int i = 0;
    DBSDocumentState source = null; // source if seen
    Long destPos = null;
    for (DBSDocumentState docState : docStates) {
        Serializable id = docState.getId();
        if (id.equals(destId)) {
            destPos = Long.valueOf(i);
            i++;
            if (source != null) {
                source.put(KEY_POS, destPos);
            }
        }
        Long setPos;
        if (id.equals(sourceId)) {
            i--;
            source = docState;
            setPos = destPos;
        } else {
            setPos = Long.valueOf(i);
        }
        if (setPos != null) {
            if (!setPos.equals(docState.get(KEY_POS))) {
                docState.put(KEY_POS, setPos);
            }
        }
        i++;
    }
    if (destId == null) {
        Long setPos = Long.valueOf(i);
        if (!setPos.equals(source.get(KEY_POS))) {
            source.put(KEY_POS, setPos);
        }
    }
}

From source file:org.nuxeo.ecm.core.storage.sql.Children.java

/**
 * Gets a fragment given its name./*from   w w  w  .  j  av  a2  s .  c  o  m*/
 * <p>
 * Returns {@code null} if there is no such child.
 * <p>
 * Returns {@link SimpleFragment#UNKNOWN} if there's no info about it.
 *
 * @param value the name
 * @return the fragment, or {@code null}, or {@link SimpleFragment#UNKNOWN}
 */
public SimpleFragment getFragmentByValue(Serializable value) {
    if (existing != null) {
        for (Serializable id : existing) {
            SimpleFragment fragment;
            try {
                fragment = (SimpleFragment) context.get(id, false);
            } catch (StorageException e) {
                log.warn("Failed refetch for: " + id, e);
                continue;
            }
            if (fragment == null) {
                log.warn("Existing fragment missing: " + id);
                continue;
            }
            if (value.equals(fragmentValue(fragment))) {
                return fragment;
            }
        }
    }
    if (created != null) {
        for (Serializable id : created) {
            SimpleFragment fragment = (SimpleFragment) context.getIfPresent(id);
            if (fragment == null) {
                log.warn("Created fragment missing: " + id);
                continue;
            }
            if (value.equals(fragmentValue(fragment))) {
                return fragment;
            }
        }
    }
    if (deleted != null) {
        for (Serializable id : deleted) {
            SimpleFragment fragment = (SimpleFragment) context.getIfPresent(id);
            if (fragment == null) {
                log.warn("Deleted fragment missing: " + id);
                continue;
            }
            if (value.equals(fragmentValue(fragment))) {
                return null;
            }
        }
    }
    return complete ? null : SimpleFragment.UNKNOWN;
}

From source file:org.nuxeo.ecm.core.storage.sql.Children.java

/**
 * Gets all the fragments, if the list of children is complete.
 *
 * @param value the name to filter on, or {@code null} for all children
 * @return the fragments, or {@code null} if the list is not known to be
 *         complete/*from   w  ww.  j a va 2s .  c  om*/
 */
public List<SimpleFragment> getFragmentsByValue(Serializable value) {
    if (!complete) {
        return null;
    }
    // fetch fragments and maybe filter by name
    List<SimpleFragment> filtered = new LinkedList<SimpleFragment>();
    if (existing != null) {
        for (Serializable id : existing) {
            SimpleFragment fragment;
            try {
                fragment = (SimpleFragment) context.get(id, false);
            } catch (StorageException e) {
                log.warn("Failed refetch for: " + id, e);
                continue;
            }
            if (fragment == null) {
                log.warn("Existing fragment missing: " + id);
                continue;
            }
            if (value == null || value.equals(fragmentValue(fragment))) {
                filtered.add(fragment);
            }
        }
    }
    if (created != null) {
        for (Serializable id : created) {
            SimpleFragment fragment = (SimpleFragment) context.getIfPresent(id);
            if (fragment == null) {
                log.warn("Created fragment missing: " + id);
                continue;
            }
            if (value == null || value.equals(fragmentValue(fragment))) {
                filtered.add(fragment);
            }
        }
    }
    return filtered;
}