Example usage for org.apache.commons.collections CollectionUtils addAll

List of usage examples for org.apache.commons.collections CollectionUtils addAll

Introduction

In this page you can find the example usage for org.apache.commons.collections CollectionUtils addAll.

Prototype

public static void addAll(Collection collection, Object[] elements) 

Source Link

Document

Adds all elements in the array to the given collection.

Usage

From source file:org.apache.ojb.broker.util.BrokerHelper.java

/**
 * Returns an object array for {@link java.util.Collection}, array or
 * {@link org.apache.ojb.broker.ManageableCollection} instances.
 *
 * @param collectionOrArray a none <em>null</em> object of type {@link java.util.Collection},
 * Array or {@link org.apache.ojb.broker.ManageableCollection}.
 * @return Object array able to handle given collection or array object
 *///from   w w w. ja  v a2s  . com
public static Object[] getCollectionArray(Object collectionOrArray) {
    Object[] result;
    if (collectionOrArray instanceof Collection) {
        result = ((Collection) collectionOrArray).toArray();
    } else if (collectionOrArray instanceof ManageableCollection) {
        Collection newCol = new ArrayList();
        CollectionUtils.addAll(newCol, ((ManageableCollection) collectionOrArray).ojbIterator());
        result = newCol.toArray();
    } else if (collectionOrArray.getClass().isArray()) {
        result = (Object[]) collectionOrArray;
    } else {
        throw new OJBRuntimeException("Given object collection of type '"
                + (collectionOrArray != null ? collectionOrArray.getClass().toString() : "null")
                + "' can not be managed by OJB. Use Array, Collection or ManageableCollection instead!");
    }
    return result;
}

From source file:org.apache.sysml.hops.codegen.opt.ReachabilityGraph.java

public ReachabilityGraph(PlanPartition part, CPlanMemoTable memo) {
    //create repository of materialization points
    _matPoints = new HashMap<>();
    for (InterestingPoint p : part.getMatPointsExt())
        _matPoints.put(Pair.of(p._fromHopID, p._toHopID), new NodeLink(p));

    //create reachability graph
    _root = new NodeLink(null);
    HashSet<VisitMarkCost> visited = new HashSet<>();
    for (Long hopID : part.getRoots()) {
        Hop rootHop = memo.getHopRefs().get(hopID);
        addInputNodeLinks(rootHop, _root, part, memo, visited);
    }/*from   w ww . j a v a  2 s.c  o  m*/

    //create candidate cutsets 
    List<NodeLink> tmpCS = _matPoints.values().stream().filter(p -> p._inputs.size() > 0 && p._p != null)
            .sorted().collect(Collectors.toList());

    //short-cut for partitions without cutsets
    if (tmpCS.isEmpty()) {
        _cutSets = new CutSet[0];
        //sort materialization points in decreasing order of their sizes
        //which can improve the pruning efficiency by skipping larger sub-spaces.
        _searchSpace = sortBySize(part.getMatPointsExt(), memo, false);
        return;
    }

    //create composite cutsets 
    ArrayList<ArrayList<NodeLink>> candCS = new ArrayList<>();
    ArrayList<NodeLink> current = new ArrayList<>();
    for (NodeLink node : tmpCS) {
        if (current.isEmpty())
            current.add(node);
        else if (current.get(0).equals(node))
            current.add(node);
        else {
            candCS.add(current);
            current = new ArrayList<>();
            current.add(node);
        }
    }
    if (!current.isEmpty())
        candCS.add(current);

    //evaluate cutsets (single, and duplicate pairs)
    ArrayList<ArrayList<NodeLink>> remain = new ArrayList<>();
    ArrayList<Pair<CutSet, Double>> cutSets = evaluateCutSets(candCS, remain);
    if (!remain.isEmpty() && remain.size() < 5) {
        //second chance: for pairs for remaining candidates
        ArrayList<ArrayList<NodeLink>> candCS2 = new ArrayList<>();
        for (int i = 0; i < remain.size() - 1; i++)
            for (int j = i + 1; j < remain.size(); j++) {
                ArrayList<NodeLink> tmp = new ArrayList<>();
                tmp.addAll(remain.get(i));
                tmp.addAll(remain.get(j));
                candCS2.add(tmp);
            }
        ArrayList<Pair<CutSet, Double>> cutSets2 = evaluateCutSets(candCS2, remain);
        //ensure constructed cutsets are disjoint
        HashSet<InterestingPoint> testDisjoint = new HashSet<>();
        for (Pair<CutSet, Double> cs : cutSets2) {
            if (!CollectionUtils.containsAny(testDisjoint, Arrays.asList(cs.getLeft().cut))) {
                cutSets.add(cs);
                CollectionUtils.addAll(testDisjoint, cs.getLeft().cut);
            }
        }
    }

    //sort and linearize search space according to scores
    _cutSets = cutSets.stream().sorted(Comparator.comparing(p -> p.getRight())).map(p -> p.getLeft())
            .toArray(CutSet[]::new);

    //created sorted order of materialization points
    //(cut sets in predetermined order, other points sorted by size)
    HashMap<InterestingPoint, Integer> probe = new HashMap<>();
    ArrayList<InterestingPoint> lsearchSpace = new ArrayList<>();
    for (CutSet cs : _cutSets) {
        CollectionUtils.addAll(lsearchSpace, cs.cut);
        for (InterestingPoint p : cs.cut)
            probe.put(p, probe.size());
    }
    //sort materialization points in decreasing order of their sizes
    //which can improve the pruning efficiency by skipping larger sub-spaces.
    for (InterestingPoint p : sortBySize(part.getMatPointsExt(), memo, false))
        if (!probe.containsKey(p)) {
            lsearchSpace.add(p);
            probe.put(p, probe.size());
        }
    _searchSpace = lsearchSpace.toArray(new InterestingPoint[0]);

    //finalize cut sets (update positions wrt search space)
    for (CutSet cs : _cutSets)
        cs.updatePositions(probe);

    //final sanity check of interesting points
    if (_searchSpace.length != part.getMatPointsExt().length)
        throw new RuntimeException("Corrupt linearized search space: " + _searchSpace.length + " vs "
                + part.getMatPointsExt().length);
}

From source file:org.apache.zookeeper.RemoveWatchesTest.java

/**
 * Checks if a session is registered with the server as a watcher.
 *
 * @param long sessionId the session ID to check
 * @param path the path to check for watchers
 * @param type the type of watcher//from w w w  .java2 s . c  om
 * @return true if the client session is a watcher on path for the type
 */
private boolean isServerSessionWatcher(long sessionId, String path, WatcherType type) {
    Set<ServerCnxn> cnxns = new HashSet<>();
    CollectionUtils.addAll(cnxns, serverFactory.getConnections().iterator());
    for (ServerCnxn cnxn : cnxns) {
        if (cnxn.getSessionId() == sessionId) {
            return getServer(serverFactory).getZKDatabase().getDataTree().containsWatcher(path, type, cnxn);
        }
    }
    return false;
}

From source file:org.asqatasun.webapp.controller.AbstractAuditResultController.java

private Collection<String> getTestResultSortSelection(AuditResultSortCommand asuc) {
    Collection<String> selectedValues = new HashSet<>();
    if ((asuc.getSortOptionMap().get(testResultSortKey)) instanceof Object[]) {
        CollectionUtils.addAll(selectedValues, ((Object[]) asuc.getSortOptionMap().get(testResultSortKey)));
    } else if ((asuc.getSortOptionMap().get(testResultSortKey)) instanceof String) {
        selectedValues.add((String) asuc.getSortOptionMap().get(testResultSortKey));
    }/*w ww.  j av  a  2  s  .  c o  m*/
    return selectedValues;
}

From source file:org.asqatasun.webapp.form.parameterization.helper.FormFieldHelper.java

/**
 * /*from   ww w  .jav a 2 s.co m*/
 * @param formFieldList
 * @param formValueMap 
 */
public static void setValueToFormField(List<FormField> formFieldList, Map<String, Object> formValueMap) {
    for (FormField ff : formFieldList) {
        if (ff instanceof SelectFormField) {
            for (Map.Entry<String, List<SelectElement>> entry : ((SelectFormField) ff).getSelectElementMap()
                    .entrySet()) {
                for (SelectElement se : entry.getValue()) {
                    se.setDefault(false);
                    if (formValueMap.get(entry.getKey()).equals(se.getValue())) {
                        se.setDefault(true);
                    }
                }
            }
        } else if (ff instanceof CheckboxFormField) {
            // retrieve the user selection and select the UI elements
            CheckboxFormField cff = ((CheckboxFormField) ff);
            Collection<String> selectedValues = new HashSet<String>();
            if ((formValueMap.get(cff.getCode()) instanceof String[])) {
                CollectionUtils.addAll(selectedValues, ((String[]) formValueMap.get(cff.getCode())));
            } else if ((formValueMap.get(cff.getCode()) instanceof String)) {
                selectedValues.add(((String) formValueMap.get(cff.getCode())));
            }
            for (CheckboxElement ce : cff.getCheckboxElementList()) {
                if (selectedValues.add(ce.getValue())) {
                    ce.setSelected(true);
                } else {
                    ce.setSelected(false);
                }
            }
        } else {
            ff.setValue(formValueMap.get(ff.getI18nKey()).toString());
        }
    }
}

From source file:org.codehaus.groovy.grails.web.binding.DataBindingUtils.java

@SuppressWarnings("unchecked")
private static void updateAllowed(GrailsDataBinder binder, List allowed) {
    if (allowed == null) {
        return;/*from ww w  .  ja  v a2  s  .c o m*/
    }

    String[] currentAllowed = binder.getAllowedFields();
    List newAllowed = new ArrayList(allowed);
    CollectionUtils.addAll(newAllowed, currentAllowed);
    String[] value = new String[newAllowed.size()];
    newAllowed.toArray(value);
    binder.setAllowedFields(value);
}

From source file:org.codehaus.groovy.grails.web.binding.DataBindingUtils.java

@SuppressWarnings("unchecked")
private static void updateDisallowed(GrailsDataBinder binder, List allowed, List disallowed) {
    if (disallowed == null) {
        return;/*from   w  ww . ja va 2s .c o m*/
    }

    String[] currentDisallowed = binder.getDisallowedFields();
    List newDisallowed = new ArrayList(disallowed);
    if (allowed == null) {
        CollectionUtils.addAll(newDisallowed, currentDisallowed);
    } else {
        for (String s : currentDisallowed) {
            if (!allowed.contains(s)) {
                newDisallowed.add(s);
            }
        }
    }
    String[] value = new String[newDisallowed.size()];
    newDisallowed.toArray(value);
    binder.setDisallowedFields(value);
}

From source file:org.codice.ddf.admin.core.impl.AdminConsoleService.java

/**
 * @see AdminConsoleServiceMBean#updateForLocation(java.lang.String, java.lang.String,
 *     java.util.Map)//from  w  ww.  j  a va 2s .c  o  m
 */
public void updateForLocation(final String pid, String location, Map<String, Object> configurationTable)
        throws IOException {
    if (pid == null || pid.length() < 1) {
        throw loggedException(ILLEGAL_PID_MESSAGE);
    }
    if (configurationTable == null) {
        throw loggedException(ILLEGAL_TABLE_MESSAGE);
    }

    final Configuration config = configurationAdmin.getConfiguration(pid, location);
    if (isPermittedToViewService(config.getPid())) {
        final Metatype metatype = configurationAdminImpl.findMetatypeForConfig(config);
        if (metatype == null) {
            throw loggedException("Could not find metatype for " + pid);
        }

        final List<Map.Entry<String, Object>> configEntries = new ArrayList<>();
        CollectionUtils.addAll(configEntries, configurationTable.entrySet().iterator());
        CollectionUtils.transform(configEntries,
                new CardinalityTransformer(metatype.getAttributeDefinitions(), pid));

        final Dictionary<String, Object> configProperties = config.getProperties();
        final Dictionary<String, Object> newConfigProperties = (configProperties != null) ? configProperties
                : new Hashtable<>();

        // If the configuration entry is a password, and its updated configuration value is
        // "password", do not update the password.
        for (Map.Entry<String, Object> configEntry : configEntries) {
            final String configEntryKey = configEntry.getKey();
            Object configEntryValue = sanitizeUIConfiguration(pid, configEntryKey, configEntry.getValue());
            if (configEntryValue.equals("password")) {
                for (Map<String, Object> metatypeProperties : metatype.getAttributeDefinitions()) {
                    if (metatypeProperties.get("id").equals(configEntry.getKey())
                            && AttributeDefinition.PASSWORD == (Integer) metatypeProperties.get("type")
                            && configProperties != null) {
                        configEntryValue = configProperties.get(configEntryKey);
                        break;
                    }
                }
            }
            newConfigProperties.put(configEntryKey, configEntryValue);
        }

        config.update(newConfigProperties);
    }
}

From source file:org.codice.ddf.ui.admin.api.ConfigurationAdmin.java

/**
 * @see ConfigurationAdminMBean#updateForLocation(java.lang.String, java.lang.String,
 * java.util.Map)//from w  ww.  ja v a 2s.  c o m
 */
public void updateForLocation(final String pid, String location, Map<String, Object> configurationTable)
        throws IOException {
    if (pid == null || pid.length() < 1) {
        throw loggedException("Argument pid cannot be null or empty");
    }
    if (configurationTable == null) {
        throw loggedException("Argument configurationTable cannot be null");
    }

    Configuration config = configurationAdmin.getConfiguration(pid, location);

    final List<Map<String, Object>> metatype = findMetatypeForConfig(config);
    List<Map.Entry<String, Object>> configEntries = new ArrayList<>();

    CollectionUtils.addAll(configEntries, configurationTable.entrySet().iterator());

    if (metatype == null) {
        throw loggedException("Could not find metatype for " + pid);
    }
    // now we have to filter each property based on its cardinality
    CollectionUtils.transform(configEntries, new CardinalityTransformer(metatype, pid));

    Dictionary<String, Object> configurationProperties = new Hashtable<>();
    for (Map.Entry<String, Object> configEntry : configEntries) {
        configurationProperties.put(configEntry.getKey(), configEntry.getValue());
    }
    config.update(configurationProperties);
}

From source file:org.drools.planner.core.heuristic.selector.entity.cached.DecreasingDifficultyEntitySelector.java

public void constructCache(DefaultSolverScope solverScope) {
    long childSize = childEntitySelector.getSize();
    cachedEntityList = new ArrayList<Object>((int) childSize);
    CollectionUtils.addAll(cachedEntityList, childEntitySelector.iterator());
    planningEntitySorter.sortDifficultyDescending(solverScope.getWorkingSolution(), cachedEntityList);
}