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.apache.click.extras.jpa.JpaForm.java

/**
 * Return a JPA value object from the form with the form field values
 * copied into the object's properties./*from w w  w .java2 s. co  m*/
 *
 * @return the JPA object from the form with the form field values
 * applied to the object properties.
 */
public Object getValueObject() {
    if (StringUtils.isNotBlank(classField.getValue())) {
        try {
            Class valueClass = Class.forName(classField.getValue());

            Serializable oid = (Serializable) oidField.getValueObject();

            Object valueObject = null;
            if (oid != null && !oid.equals("")) {
                valueObject = getEntityManager().find(valueClass, oid);
            } else {
                valueObject = valueClass.newInstance();
            }

            copyTo(valueObject);

            return valueObject;

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    return null;
}

From source file:org.apache.jcs.engine.memory.lru.LRUMemoryCache.java

/**
 * Checks to see if all the items that should be in the cache are. Checks consistency between
 * List and map./*from  w w w .ja  va 2s  .  c  o m*/
 */
private void verifyCache() {
    if (!log.isDebugEnabled()) {
        return;
    }

    boolean found = false;
    log.debug("verifycache[" + cacheName + "]: mapContains " + map.size() + " elements, linked list contains "
            + dumpCacheSize() + " elements");
    log.debug("verifycache: checking linked list by key ");
    for (MemoryElementDescriptor li = (MemoryElementDescriptor) list
            .getFirst(); li != null; li = (MemoryElementDescriptor) li.next) {
        Object key = li.ce.getKey();
        if (!map.containsKey(key)) {
            log.error("verifycache[" + cacheName + "]: map does not contain key : " + li.ce.getKey());
            log.error("li.hashcode=" + li.ce.getKey().hashCode());
            log.error("key class=" + key.getClass());
            log.error("key hashcode=" + key.hashCode());
            log.error("key toString=" + key.toString());
            if (key instanceof GroupAttrName) {
                GroupAttrName name = (GroupAttrName) key;
                log.error("GroupID hashcode=" + name.groupId.hashCode());
                log.error("GroupID.class=" + name.groupId.getClass());
                log.error("AttrName hashcode=" + name.attrName.hashCode());
                log.error("AttrName.class=" + name.attrName.getClass());
            }
            dumpMap();
        } else if (map.get(li.ce.getKey()) == null) {
            log.error("verifycache[" + cacheName + "]: linked list retrieval returned null for key: "
                    + li.ce.getKey());
        }
    }

    log.debug("verifycache: checking linked list by value ");
    for (MemoryElementDescriptor li3 = (MemoryElementDescriptor) list
            .getFirst(); li3 != null; li3 = (MemoryElementDescriptor) li3.next) {
        if (map.containsValue(li3) == false) {
            log.error("verifycache[" + cacheName + "]: map does not contain value : " + li3);
            dumpMap();
        }
    }

    log.debug("verifycache: checking via keysets!");
    for (Iterator itr2 = map.keySet().iterator(); itr2.hasNext();) {
        found = false;
        Serializable val = null;
        try {
            val = (Serializable) itr2.next();
        } catch (NoSuchElementException nse) {
            log.error("verifycache: no such element exception");
        }

        for (MemoryElementDescriptor li2 = (MemoryElementDescriptor) list
                .getFirst(); li2 != null; li2 = (MemoryElementDescriptor) li2.next) {
            if (val.equals(li2.ce.getKey())) {
                found = true;
                break;
            }
        }
        if (!found) {
            log.error("verifycache[" + cacheName + "]: key not found in list : " + val);
            dumpCacheEntries();
            if (map.containsKey(val)) {
                log.error("verifycache: map contains key");
            } else {
                log.error("verifycache: map does NOT contain key, what the HECK!");
            }
        }
    }
}

From source file:org.apache.jcs.utils.struct.LRUMap.java

/**
 * Checks to see if all the items that should be in the cache are. Checks consistency between
 * List and map./*from  www  .  j av a2 s. c om*/
 */
protected void verifyCache() {
    if (!log.isDebugEnabled()) {
        return;
    }

    boolean found = false;
    log.debug("verifycache: mapContains " + map.size() + " elements, linked list contains " + dumpCacheSize()
            + " elements");
    log.debug("verifycache: checking linked list by key ");
    for (LRUElementDescriptor li = (LRUElementDescriptor) list
            .getFirst(); li != null; li = (LRUElementDescriptor) li.next) {
        Object key = li.getKey();
        if (!map.containsKey(key)) {
            log.error("verifycache: map does not contain key : " + li.getKey());
            log.error("li.hashcode=" + li.getKey().hashCode());
            log.error("key class=" + key.getClass());
            log.error("key hashcode=" + key.hashCode());
            log.error("key toString=" + key.toString());
            if (key instanceof GroupAttrName) {
                GroupAttrName name = (GroupAttrName) key;
                log.error("GroupID hashcode=" + name.groupId.hashCode());
                log.error("GroupID.class=" + name.groupId.getClass());
                log.error("AttrName hashcode=" + name.attrName.hashCode());
                log.error("AttrName.class=" + name.attrName.getClass());
            }
            dumpMap();
        } else if (map.get(li.getKey()) == null) {
            log.error("verifycache: linked list retrieval returned null for key: " + li.getKey());
        }
    }

    log.debug("verifycache: checking linked list by value ");
    for (LRUElementDescriptor li3 = (LRUElementDescriptor) list
            .getFirst(); li3 != null; li3 = (LRUElementDescriptor) li3.next) {
        if (map.containsValue(li3) == false) {
            log.error("verifycache: map does not contain value : " + li3);
            dumpMap();
        }
    }

    log.debug("verifycache: checking via keysets!");
    for (Iterator itr2 = map.keySet().iterator(); itr2.hasNext();) {
        found = false;
        Serializable val = null;
        try {
            val = (Serializable) itr2.next();
        } catch (NoSuchElementException nse) {
            log.error("verifycache: no such element exception");
        }

        for (LRUElementDescriptor li2 = (LRUElementDescriptor) list
                .getFirst(); li2 != null; li2 = (LRUElementDescriptor) li2.next) {
            if (val.equals(li2.getKey())) {
                found = true;
                break;
            }
        }
        if (!found) {
            log.error("verifycache: key not found in list : " + val);
            dumpCacheEntries();
            if (map.containsKey(val)) {
                log.error("verifycache: map contains key");
            } else {
                log.error("verifycache: map does NOT contain key, what the HECK!");
            }
        }
    }
}

From source file:org.codice.alliance.security.banner.marking.BannerCommonMarkingExtractor.java

private void checkSecurityAttribute(String name, Serializable oldVal, Serializable newVal) {
    if (!isSecurityAttribute(name) || StringUtils.isBlank((String) oldVal)) {
        return;//  w  w w.j a v a 2s .co m
    }

    if (!newVal.equals(oldVal)) {
        throwSecurityMismatchException(name);
    }
}

From source file:org.craftercms.cstudio.alfresco.util.ContentUtils.java

/**
 * check if two serializable values are the same
 * //from   w w w.j av  a 2s .c  o  m
 * @param value1
 * @param value2
 * @return true if they are equal
 */
public static boolean areEqual(Serializable value1, Serializable value2) {
    if (value1 == null && value2 == null) {
        return true;
    } else if (value1 == null || value2 == null) {
        return false;
    } else {
        return value1.equals(value2);
    }
}

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

/**
 * Gets a fragment given its name./* ww w.j  a  v  a  2  s .  com*/
 * <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 = hierContext.getHier(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 = hierContext.getHierIfPresent(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 = hierContext.getHierIfPresent(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.eclipse.ecr.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//www  .ja  v  a2  s . 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 = hierContext.getHier(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 = hierContext.getHierIfPresent(id);
            if (fragment == null) {
                log.warn("Created fragment missing: " + id);
                continue;
            }
            if (value == null || value.equals(fragmentValue(fragment))) {
                filtered.add(fragment);
            }
        }
    }
    return filtered;
}

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

/**
 * Checks if an id is a (strict) descendant of a given base id.
 *
 * @param conn the connection to the database
 * @param id the id to check for// ww w .  j a va2 s  .c  o m
 * @param baseId the base id
 */
public static boolean isInTree(Connection conn, Serializable id, Serializable baseId) throws SQLException {
    if (baseId == null || id == null || baseId.equals(id)) {
        // containment check is strict
        return false;
    }
    PreparedStatement ps = null;
    try {
        ps = conn.prepareStatement("SELECT PARENTID FROM HIERARCHY WHERE ID = ?");
        do {
            ps.setObject(1, id);
            ResultSet rs = ps.executeQuery();
            if (!rs.next()) {
                // no such id
                return false;
            }
            if (id instanceof String) {
                id = rs.getString(1);
            } else {
                id = Long.valueOf(rs.getLong(1));
            }
            if (rs.wasNull()) {
                id = null;
            }
            rs.close();
            if (baseId.equals(id)) {
                // found a match
                return true;
            }
        } while (id != null);
        // got to the root
        return false;
    } finally {
        if (ps != null) {
            ps.close();
        }
    }
}

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

/** Checks that we don't move/copy under ourselves. */
protected void checkNotUnder(Serializable parentId, Serializable id, String op) throws StorageException {
    Serializable pid = parentId;
    do {/*  w  ww.ja v a 2 s .  c o m*/
        if (pid.equals(id)) {
            throw new StorageException(
                    "Cannot " + op + " a node under itself: " + parentId + " is under " + id);
        }
        SimpleFragment p = getHier(pid, false);
        if (p == null) {
            // cannot happen
            throw new StorageException("No parent: " + pid);
        }
        pid = p.get(model.HIER_PARENT_KEY);
    } while (pid != null);
}

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

/**
 * Order a child before another./*ww w .jav  a 2 s.c o  m*/
 *
 * @param parentId the parent id
 * @param sourceId the node id to move
 * @param destId the node id before which to place the source node, if
 *            {@code null} then move the source to the end
 */
public void orderBefore(Serializable parentId, Serializable sourceId, Serializable destId)
        throws StorageException {
    boolean complexProp = false;
    if (!isOrderable(parentId, complexProp)) {
        // TODO throw exception?
        return;
    }
    if (sourceId.equals(destId)) {
        return;
    }
    // This is optimized by assuming the number of children is small enough
    // to be manageable in-memory.
    // fetch children and relevant nodes
    List<SimpleFragment> fragments = getChildren(parentId, null, complexProp);
    // renumber fragments
    int i = 0;
    SimpleFragment source = null; // source if seen
    Long destPos = null;
    for (SimpleFragment fragment : fragments) {
        Serializable id = fragment.getId();
        if (id.equals(destId)) {
            destPos = Long.valueOf(i);
            i++;
            if (source != null) {
                source.put(model.HIER_CHILD_POS_KEY, destPos);
            }
        }
        Long setPos;
        if (id.equals(sourceId)) {
            i--;
            source = fragment;
            setPos = destPos;
        } else {
            setPos = Long.valueOf(i);
        }
        if (setPos != null) {
            if (!setPos.equals(fragment.get(model.HIER_CHILD_POS_KEY))) {
                fragment.put(model.HIER_CHILD_POS_KEY, setPos);
            }
        }
        i++;
    }
    if (destId == null) {
        Long setPos = Long.valueOf(i);
        if (!setPos.equals(source.get(model.HIER_CHILD_POS_KEY))) {
            source.put(model.HIER_CHILD_POS_KEY, setPos);
        }
    }
}