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.nuxeo.ecm.core.storage.sql.PersistenceContext.java

/**
 * Copy a child to a new parent with a new name.
 *
 * @param source the source of the copy/*w w w. ja  v  a 2 s. c o m*/
 * @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 != null && !oldParentId.equals(parentId)) {
        checkNotUnder(parentId, id, "copy");
    }
    checkFreeName(parentId, name, complexProp(hierFragment));
    // do the copy
    CopyResult copyResult = mapper.copy(new IdWithTypes(source), parentId, name, null);
    Serializable newId = copyResult.copyId;
    // read new child in this session (updates children Selection)
    SimpleFragment copy = getHier(newId, false);
    // invalidate child in other sessions' children Selection
    markInvalidated(copyResult.invalidations);
    // read new proxies in this session (updates Selections)
    List<RowId> rowIds = new ArrayList<RowId>();
    for (Serializable proxyId : copyResult.proxyIds) {
        rowIds.add(new RowId(Model.PROXY_TABLE_NAME, proxyId));
    }
    // multi-fetch will register the new fragments with the Selections
    List<Fragment> fragments = getMulti(rowIds, true);
    // invalidate Selections in other sessions
    for (Fragment fragment : fragments) {
        seriesProxies.recordExisting((SimpleFragment) fragment, true);
        targetProxies.recordExisting((SimpleFragment) fragment, true);
    }
    // version copy fixup
    if (source.isVersion()) {
        copy.put(Model.MAIN_IS_VERSION_KEY, null);
    }
    return newId;
}

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

/**
 * Gets a fragment given its filtered value.
 * <p>/*from   w w  w  . j a v a 2  s . c  o  m*/
 * 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) {
                // common case
                continue;
            }
            if (filter.equals(fragmentValue(fragment))) {
                return null;
            }
        }
    }
    return complete ? null : SimpleFragment.UNKNOWN;
}

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

/**
 * Collect modified document IDs into two separate set, one for the docs and
 * the other for parents/*w  w w  .  jav a  2s . c  o  m*/
 * <p>
 * Collects ids as Strings (not Serializables) as these are then sent to
 * high-level event code.
 *
 * @param invalidations
 * @param docs
 * @param parents
 */
protected void collectModified(Invalidations invalidations, Set<String> docs, Set<String> parents) {
    if (invalidations == null || invalidations.modified == null) {
        return;
    }
    for (RowId rowId : invalidations.modified) {
        Serializable id = rowId.id;
        Serializable docId;
        try {
            docId = getContainingDocument(id);
        } catch (StorageException e) {
            log.error("Cannot get containing document for: " + id, e);
            docId = null;
        }
        if (docId == null) {
            continue;
        }
        if (Invalidations.PARENT.equals(rowId.tableName)) {
            if (docId.equals(id)) {
                parents.add(model.idToString(docId));
            } else { // complex prop added/removed
                docs.add(model.idToString(docId));
            }
        } else {
            docs.add(model.idToString(docId));
        }
    }
}

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

@Override
public void setProxyTarget(Node proxy, Serializable targetId) throws StorageException {
    if (!repository.getRepositoryDescriptor().getProxiesEnabled()) {
        throw new StorageException("Proxies are disabled by configuration");
    }//from   ww  w .  jav a2  s . c  om
    SimpleProperty prop = proxy.getSimpleProperty(Model.PROXY_TARGET_PROP);
    Serializable oldTargetId = prop.getValue();
    if (!oldTargetId.equals(targetId)) {
        SimpleFragment proxyFragment = (SimpleFragment) proxy.fragments.get(Model.PROXY_TABLE_NAME);
        context.removedProxyTarget(proxyFragment);
        proxy.setSimpleProperty(Model.PROXY_TARGET_PROP, targetId);
        context.addedProxyTarget(proxyFragment);
    }
}

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

@Override
public List<Node> getProxies(Node document, Node parent) throws StorageException {
    checkLive();/*from w w w  . ja v  a 2s  .  c o m*/
    if (!repository.getRepositoryDescriptor().getProxiesEnabled()) {
        return Collections.emptyList();
    }

    List<Serializable> ids;
    if (document.isVersion()) {
        ids = context.getTargetProxyIds(document.getId());
    } else {
        Serializable versionSeriesId;
        if (document.isProxy()) {
            versionSeriesId = document.getSimpleProperty(Model.PROXY_VERSIONABLE_PROP).getValue();
        } else {
            versionSeriesId = document.getId();
        }
        ids = context.getSeriesProxyIds(versionSeriesId);
    }

    List<Node> nodes = new LinkedList<Node>();
    for (Serializable id : ids) {
        Node node = getNodeById(id);
        if (node != null || Boolean.TRUE.booleanValue()) { // XXX
            // null if deleted, which means selection wasn't correctly
            // updated
            nodes.add(node);
        }
    }

    if (parent != null) {
        // filter by parent
        Serializable parentId = parent.getId();
        for (Iterator<Node> it = nodes.iterator(); it.hasNext();) {
            Node node = it.next();
            if (!parentId.equals(node.getParentId())) {
                it.remove();
            }
        }
    }

    return nodes;
}

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

/**
 * Gets the dirty fields (fields changed since last clear).
 *
 * @return the dirty fields/*ww  w. j  a v a2s . com*/
 */
public Collection<String> getDirty() {
    List<String> dirty = new LinkedList<String>();
    for (int i = 0; i < size; i += 3) {
        Serializable value = data[i + 1];
        Serializable oldValue = data[i + 2];
        if (value == null) {
            if (oldValue != null) {
                dirty.add((String) data[i]);
            }
        } else if (!value.equals(oldValue)) {
            dirty.add((String) data[i]);
        }
    }
    return dirty;
}

From source file:org.nuxeo.ecm.webapp.security.GroupManagerActionsBean.java

public boolean isSelectedGroupReadOnly() {
    Serializable virtualFlag = selectedGroup.getContextData().getScopedValue("virtual");
    return (virtualFlag != null && virtualFlag.equals(true));
}

From source file:org.openiot.gsn.wrappers.general.CSVHandler.java

public ArrayList<TreeMap<String, Serializable>> parseValues(Reader datainput, long previousCheckPoint,
        int samplingCountPerPeriod) throws IOException {
    ArrayList<TreeMap<String, Serializable>> toReturn = new ArrayList<TreeMap<String, Serializable>>();
    CSVReader reader = new CSVReader(datainput, getSeparator(), getStringSeparator(), getSkipFirstXLines());
    String[] values;// w w w  .  j  av a2 s . c  o  m
    long currentLine = 0;
    Serializable currentTimeStamp = null;
    boolean quit = false;
    while ((values = reader.readNext()) != null) {
        TreeMap<String, Serializable> se = convertTo(formats, fields, getNulls(), values, getSeparator());
        if (isEmpty(se)) {
            continue;
        }
        if (se.containsKey(TIMESTAMP)) {
            if (((Long) se.get(TIMESTAMP)) <= previousCheckPoint) {
                continue;
            }
        } else {// assuming useCounterForCheckPoint = true

            if (logger.isDebugEnabled()) {
                String symbol = (currentLine < previousCheckPoint) ? " < " : " >= ";
                logger.debug("currentLine=" + currentLine + symbol + "checkpoint=" + previousCheckPoint);
            }

            if (currentLine < previousCheckPoint) {// skipping already read lines, based on line count
                logger.debug("skipping");
                currentLine++;
                continue;
            }
        }
        if (quit) {
            if (se.containsKey(TIMESTAMP)) {
                if (currentTimeStamp == null || !currentTimeStamp.equals(se.get(TIMESTAMP))) {
                    break;
                }
            } else {
                break;
            }
        }
        toReturn.add(se);
        currentLine++;
        loggedNoChange = false;
        if (toReturn.size() >= samplingCountPerPeriod) {
            // Move outside the loop as in each call we only read x values;
            // But if we use timeStampMode, still check the next value, since
            // if the timestamp is the same we have to return it, or data
            // would be lost.
            logger.trace("Time to quit.");
            quit = true;
            if (se.containsKey(TIMESTAMP)) {
                currentTimeStamp = se.get(TIMESTAMP);
            } else {
                break;
            }
        }
    }
    if (logger.isDebugEnabled() && toReturn.isEmpty() && loggedNoChange == false) {
        logger.debug("There is no new item after most recent checkpoint(previousCheckPoint:"
                + new DateTime(previousCheckPoint) + ").");
        loggedNoChange = true;
    }

    reader.close();
    return toReturn;
}

From source file:org.projectforge.database.xstream.XStreamSavingConverter.java

protected void registerEntityMapping(final Class<?> entityClass, final Serializable oldId,
        final Serializable newId) {
    final Serializable registeredNewId = getNewId(entityClass, oldId);
    if (registeredNewId != null && registeredNewId.equals(newId) == false) {
        log.error("Oups, double entity mapping found for entity '" + entityClass + "' with old id=" + oldId
                + " . New id " + newId + " ignored, using previous stored id " + registeredNewId + " instead.");
    } else {// w  w w.j ava 2  s  . co m
        this.entityMapping.put(getClassname4History(entityClass) + oldId, newId);
    }
}

From source file:org.spout.api.datatable.DataMap.java

@Override
public boolean equals(Object obj) {
    if (!(obj instanceof DataMap)) {
        return false;
    }/* ww w  .j a va  2  s  .  c om*/

    DataMap other = (DataMap) obj;
    if (isEmpty() && other.isEmpty()) {
        return true;
    }

    for (Map.Entry<? extends String, ? extends Serializable> e : entrySet()) {
        Serializable value = e.getValue();
        Serializable otherValue = other.get(e.getKey());
        if (value != null) {
            if (!value.equals(otherValue)) {
                return false;
            }
        } else if (otherValue != null) {
            return false;
        }
    }
    return true;
}