Example usage for org.apache.commons.collections.map ListOrderedMap keySet

List of usage examples for org.apache.commons.collections.map ListOrderedMap keySet

Introduction

In this page you can find the example usage for org.apache.commons.collections.map ListOrderedMap keySet.

Prototype

public Set keySet() 

Source Link

Usage

From source file:com.doculibre.constellio.wicket.panels.spellchecker.SpellCheckerPanel.java

@SuppressWarnings("unchecked")
public boolean hasManySuggestions() {
    boolean manySuggestions = false;
    boolean firstSuggestion = true;
    ListOrderedMap suggestedSearch = (ListOrderedMap) getModelObject();
    for (String motOriginal : (Set<String>) suggestedSearch.keySet()) {
        List<String> suggestedWords = (List<String>) suggestedSearch.get(motOriginal);
        if (suggestedWords != null && suggestedWords.size() > 1) {
            if (firstSuggestion) {
                firstSuggestion = false;
            } else {
                manySuggestions = true;//from w ww . j  a  va2 s.  c  om
                break;
            }
        }
    }
    return manySuggestions;
}

From source file:com.doculibre.constellio.wicket.panels.spellchecker.SpellCheckerPanel.java

@SuppressWarnings("unchecked")
private String getSuggestedSearchAsString() {
    StringBuffer sb = new StringBuffer();
    ListOrderedMap suggestedSearch = (ListOrderedMap) getModelObject();
    for (String motOriginal : (Set<String>) suggestedSearch.keySet()) {
        List<String> suggestedWords = (List<String>) suggestedSearch.get(motOriginal);
        if (suggestedWords == null || suggestedWords.isEmpty()) {
            sb.append(motOriginal);//from  w  w w .j a va  2s.  c  om
        } else {
            // First word
            sb.append(suggestedWords.get(0));
        }
        sb.append(" ");
    }
    if (sb.length() > 0) {
        // Supprimer le dernier espace
        sb.replace(sb.length() - 1, sb.length(), "");
    }
    return sb.toString();
}

From source file:org.apache.ddlutils.io.DatabaseDataIO.java

/**
 * Sorts the given table according to their foreign key order.
 * //from   www  .  j a  va2s  .  com
 * @param tables The tables
 * @return The sorted tables
 */
private List sortTables(Table[] tables) {
    ArrayList result = new ArrayList();
    HashSet processed = new HashSet();
    ListOrderedMap pending = new ListOrderedMap();

    for (int idx = 0; idx < tables.length; idx++) {
        Table table = tables[idx];

        if (table.getForeignKeyCount() == 0) {
            result.add(table);
            processed.add(table);
        } else {
            HashSet waitedFor = new HashSet();

            for (int fkIdx = 0; fkIdx < table.getForeignKeyCount(); fkIdx++) {
                Table waitedForTable = table.getForeignKey(fkIdx).getForeignTable();

                if (!table.equals(waitedForTable)) {
                    waitedFor.add(waitedForTable);
                }
            }
            pending.put(table, waitedFor);
        }
    }

    HashSet newProcessed = new HashSet();

    while (!processed.isEmpty() && !pending.isEmpty()) {
        newProcessed.clear();
        for (Iterator it = pending.entrySet().iterator(); it.hasNext();) {
            Map.Entry entry = (Map.Entry) it.next();
            Table table = (Table) entry.getKey();
            HashSet waitedFor = (HashSet) entry.getValue();

            waitedFor.removeAll(processed);
            if (waitedFor.isEmpty()) {
                it.remove();
                result.add(table);
                newProcessed.add(table);
            }
        }
        processed.clear();

        HashSet tmp = processed;

        processed = newProcessed;
        newProcessed = tmp;
    }
    // the remaining are within circular dependencies
    for (Iterator it = pending.keySet().iterator(); it.hasNext();) {
        result.add(it.next());
    }
    return result;
}

From source file:org.apache.ddlutils.platform.SqlBuilder.java

/**
 * Writes a statement that copies the data from the source to the target table. Note
 * that this copies only those columns that are in both tables.
 * Database-specific implementations might redefine this method though it usually
 * suffices to redefine the {@link #writeCastExpression(Column, Column)} method.
 * /*from   w w  w . j a v  a2 s .c o  m*/
 * @param sourceTable The source table
 * @param targetTable The target table
 */
protected void copyData(Table sourceTable, Table targetTable) throws IOException {
    ListOrderedMap columns = new ListOrderedMap();

    for (int idx = 0; idx < sourceTable.getColumnCount(); idx++) {
        Column sourceColumn = sourceTable.getColumn(idx);
        Column targetColumn = targetTable.findColumn(sourceColumn.getName(),
                getPlatform().isDelimitedIdentifierModeOn());

        if (targetColumn != null) {
            columns.put(sourceColumn, targetColumn);
        }
    }

    print("INSERT INTO ");
    printIdentifier(getTableName(targetTable));
    print(" (");
    for (Iterator columnIt = columns.keySet().iterator(); columnIt.hasNext();) {
        printIdentifier(getColumnName((Column) columnIt.next()));
        if (columnIt.hasNext()) {
            print(",");
        }
    }
    print(") SELECT ");
    for (Iterator columnsIt = columns.entrySet().iterator(); columnsIt.hasNext();) {
        Map.Entry entry = (Map.Entry) columnsIt.next();

        writeCastExpression((Column) entry.getKey(), (Column) entry.getValue());
        if (columnsIt.hasNext()) {
            print(",");
        }
    }
    print(" FROM ");
    printIdentifier(getTableName(sourceTable));
    printEndOfStatement();
}

From source file:org.jahia.services.content.ConflictResolver.java

private List<Diff> compare(JCRNodeWrapper sourceNode, JCRNodeWrapper targetNode, String basePath)
        throws RepositoryException {

    List<Diff> diffs = new ArrayList<Diff>();

    boolean remotelyPublished = targetNode.isNodeType("jmix:remotelyPublished");

    if (!remotelyPublished) {

        final ListOrderedMap targetUuids = getChildEntries(targetNode, targetNode.getSession());
        final ListOrderedMap sourceUuids = getChildEntries(sourceNode, sourceNode.getSession());

        if (!targetUuids.values().equals(sourceUuids.values())) {
            for (Iterator<?> iterator = sourceUuids.keySet().iterator(); iterator.hasNext();) {
                String key = (String) iterator.next();
                if (targetUuids.containsKey(key) && !targetUuids.get(key).equals(sourceUuids.get(key))) {
                    diffs.add(new ChildRenamedDiff(key, addPath(basePath, (String) targetUuids.get(key)),
                            addPath(basePath, (String) sourceUuids.get(key))));
                }//  w ww . ja  v a  2 s.c  om
            }
        }

        // Child nodes
        if (!targetUuids.keyList().equals(sourceUuids.keyList())) {

            @SuppressWarnings("unchecked")
            List<String> addedUuids = new ArrayList<String>(sourceUuids.keySet());
            addedUuids.removeAll(targetUuids.keySet());
            @SuppressWarnings("unchecked")
            List<String> removedUuids = new ArrayList<String>(targetUuids.keySet());
            removedUuids.removeAll(sourceUuids.keySet());

            // Ordering
            if (targetNode.getPrimaryNodeType().hasOrderableChildNodes()) {
                Map<String, String> newOrdering = getOrdering(sourceUuids, Collections.<String>emptyList());
                @SuppressWarnings("unchecked")
                List<String> oldUuidsList = new ArrayList<String>(targetUuids.keySet());
                oldUuidsList.removeAll(removedUuids);
                @SuppressWarnings("unchecked")
                List<String> newUuidsList = new ArrayList<String>(sourceUuids.keySet());
                newUuidsList.removeAll(addedUuids);
                if (!oldUuidsList.equals(newUuidsList)) {
                    for (int i = 1; i < oldUuidsList.size(); i++) {
                        String x = oldUuidsList.get(i);
                        int j = i;
                        while (j > 0 && sourceUuids.indexOf(oldUuidsList.get(j - 1)) > sourceUuids.indexOf(x)) {
                            oldUuidsList.set(j, oldUuidsList.get(j - 1));
                            j--;
                        }
                        if (j != i) {
                            String orderBeforeUuid = (j + 1 == oldUuidsList.size()) ? null
                                    : oldUuidsList.get(j + 1);
                            diffs.add(new ChildNodeReorderedDiff(x, orderBeforeUuid,
                                    addPath(basePath, (String) sourceUuids.get(x)),
                                    (String) sourceUuids.get(orderBeforeUuid), newOrdering));
                            logger.debug("reorder " + sourceUuids.get(x) + " before "
                                    + sourceUuids.get(orderBeforeUuid));
                            oldUuidsList.set(j, x);
                        }
                    }
                }
            }

            // Removed nodes
            for (String removedUuid : removedUuids) {
                try {
                    this.sourceNode.getSession().getNodeByUUID(removedUuid);
                } catch (ItemNotFoundException e) {
                    // Item has been moved
                    diffs.add(new ChildRemovedDiff(removedUuid,
                            addPath(basePath, (String) targetUuids.get(removedUuid)), removedUuid));
                }
            }

            // Added nodes
            for (String addedUuid : addedUuids) {
                diffs.add(new ChildAddedDiff(addedUuid, addPath(basePath, (String) sourceUuids.get(addedUuid)),
                        addedUuid.equals(sourceUuids.lastKey()) ? null
                                : (String) sourceUuids
                                        .get(sourceUuids.get(sourceUuids.indexOf(addedUuid) + 1))));
            }
        }
    }

    PropertyIterator targetProperties = targetNode.getProperties();

    while (targetProperties.hasNext()) {

        JCRPropertyWrapper targetProperty = (JCRPropertyWrapper) targetProperties.next();

        String propertyName = targetProperty.getName();
        if (IGNORED_PROPRTIES.contains(propertyName)) {
            continue;
        }

        if (!sourceNode.hasProperty(propertyName)) {
            if (targetProperty.isMultiple()) {
                Value[] values = targetProperty.getRealValues();
                for (Value value : values) {
                    diffs.add(new PropertyRemovedDiff(addPath(basePath, propertyName), value));
                }
            } else {
                diffs.add(new PropertyChangedDiff(addPath(basePath, propertyName), null));
            }
        } else {

            JCRPropertyWrapper sourceProperty = sourceNode.getProperty(propertyName);

            if (targetProperty.isMultiple() != sourceProperty.isMultiple()) {
                throw new RepositoryException();
            }

            if (targetProperty.isMultiple()) {

                List<? extends Value> targetValues = Arrays.asList(targetProperty.getRealValues());
                List<? extends Value> sourceValues = Arrays.asList(sourceProperty.getRealValues());

                Map<String, Value> addedValues = new HashMap<String, Value>();
                for (Value value : sourceValues) {
                    addedValues.put(value.getString(), value);
                }
                for (Value value : targetValues) {
                    addedValues.remove(value.getString());
                }
                for (Value value : addedValues.values()) {
                    diffs.add(new PropertyAddedDiff(addPath(basePath, propertyName), value));
                }

                Map<String, Value> removedValues = new HashMap<String, Value>();
                for (Value value : targetValues) {
                    removedValues.put(value.getString(), value);
                }
                for (Value value : sourceValues) {
                    removedValues.remove(value.getString());
                }
                for (Value value : removedValues.values()) {
                    diffs.add(new PropertyRemovedDiff(addPath(basePath, propertyName), value));
                }
            } else {
                if (!equalsValue(targetProperty.getRealValue(), sourceProperty.getRealValue())) {
                    diffs.add(new PropertyChangedDiff(addPath(basePath, propertyName),
                            sourceProperty.getRealValue()));
                }
            }
        }
    }

    PropertyIterator sourceProperties = sourceNode.getProperties();

    while (sourceProperties.hasNext()) {

        JCRPropertyWrapper sourceProperty = (JCRPropertyWrapper) sourceProperties.next();

        String propertyName = sourceProperty.getName();

        if (IGNORED_PROPRTIES.contains(propertyName)) {
            continue;
        }
        if (!targetNode.hasProperty(propertyName)) {
            if (sourceProperty.isMultiple()) {
                Value[] values = sourceProperty.getRealValues();
                for (Value value : values) {
                    diffs.add(new PropertyAddedDiff(addPath(basePath, sourceProperty.getName()), value));
                }
            } else {
                diffs.add(new PropertyChangedDiff(addPath(basePath, sourceProperty.getName()),
                        sourceProperty.getRealValue()));
            }
        }

    }

    for (Diff diff : new ArrayList<Diff>(diffs)) {
        if (diff instanceof PropertyAddedDiff
                && ((PropertyAddedDiff) diff).propertyPath.endsWith(Constants.JCR_MIXINTYPES)) {
            diffs.remove(diff);
            diffs.add(0, diff);
        }
    }

    for (Diff diff : new ArrayList<Diff>(diffs)) {
        if (diff instanceof PropertyRemovedDiff
                && ((PropertyRemovedDiff) diff).propertyPath.endsWith(Constants.JCR_MIXINTYPES)) {
            diffs.remove(diff);
            diffs.add(0, diff);
        }
    }

    if (!remotelyPublished) {
        NodeIterator targetSubNodes = targetNode.getNodes();
        while (targetSubNodes.hasNext()) {
            JCRNodeWrapper targetSubNode = (JCRNodeWrapper) targetSubNodes.next();
            if (sourceNode.hasNode(targetSubNode.getName()) && !targetSubNode.isVersioned()
                    && !sourceNode.getNode(targetSubNode.getName()).isVersioned()
                    && JCRPublicationService.supportsPublication(targetSubNode.getSession(), targetSubNode)) {
                diffs.addAll(compare(sourceNode.getNode(targetSubNode.getName()), targetSubNode,
                        addPath(basePath, targetSubNode.getName())));
            }
        }
    }

    return diffs;
}