Example usage for java.util Collections addAll

List of usage examples for java.util Collections addAll

Introduction

In this page you can find the example usage for java.util Collections addAll.

Prototype

@SafeVarargs
public static <T> boolean addAll(Collection<? super T> c, T... elements) 

Source Link

Document

Adds all of the specified elements to the specified collection.

Usage

From source file:de.tor.tribes.util.bb.TroopListFormatter.java

@Override
public String[] getTemplateVariables() {
    List<String> vars = new LinkedList<>();
    Collections.addAll(vars, VARIABLES);
    Collections.addAll(vars, new VillageTroopsHolder().getBBVariables());
    return vars.toArray(new String[vars.size()]);
}

From source file:lt.geostream.security.GoogleAccessTokenConverter.java

@SuppressWarnings("unchecked")
private Set<String> parseScopes(Map<String, ?> map) {
    // Parsing of scopes coming back from Google are slightly different from the default implementation
    // Instead of it being a collection it is a String where multiple scopes are separated by a space.
    Object scopeAsObject = map.containsKey(SCOPE) ? map.get(SCOPE) : EMPTY;
    Set<String> scope = new LinkedHashSet<String>();
    if (String.class.isAssignableFrom(scopeAsObject.getClass())) {
        String scopeAsString = (String) scopeAsObject;
        Collections.addAll(scope, scopeAsString.split(" "));
    } else if (Collection.class.isAssignableFrom(scopeAsObject.getClass())) {
        Collection<String> scopes = (Collection<String>) scopeAsObject;
        scope.addAll(scopes);//ww  w  .ja  va2  s .  c  om
    }
    return scope;
}

From source file:net.femtoparsec.jwhois.impl.AbstractProvider.java

/**
 * Create a provider//from  w w w.  j  a va2s  . c o m
 * @param name the name of the provider
 * @param resultFormat the format of the WhoIs results return by this provider
 * @param handleProxy true if the provider can handle proxy
 * @param providedSources the list of sources this provider can provide
 */
public AbstractProvider(String name, Format resultFormat, boolean handleProxy, Source... providedSources) {
    Validate.noNullElements(providedSources, "providedSources");

    Set<Source> set = new HashSet<Source>();
    Collections.addAll(set, providedSources);

    this.handleProxy = handleProxy;
    this.providedSources = set;
    this.resultFormat = resultFormat;
    this.name = name;
}

From source file:de.kaiserpfalzEdv.commons.jee.persistence.impl.PageRequestImpl.java

@Override
public PageRequestImpl orderBy(CRUDOrder[] order) {
    Collections.addAll(this.order, order);

    return this;
}

From source file:controllers.ModuleController.java

private static List<ModuleModel> getNextModules(String input) {
    // get all the supplied view models.
    List<ViewModel> suppliedViewModels = Lists.newArrayList();
    JsonNode inputJson = Json.parse(input);

    // convert json nodes to view models.
    if (inputJson != null && inputJson.isArray()) {
        suppliedViewModels = Lists//  www  .  j  av  a2 s  . com
                .newArrayList(Iterators.transform(inputJson.getElements(), new Function<JsonNode, ViewModel>() {
                    @Override
                    @Nullable
                    public ViewModel apply(@Nullable JsonNode input) {
                        if (!input.isTextual()) {
                            return null;
                        }
                        return createViewModelQuietly(
                                fetchResource(UuidUtils.create(input.asText()), PersistentObject.class), null);

                    }
                }));
    } else if (inputJson != null && inputJson.isObject()) {
        suppliedViewModels.add(createViewModelQuietly(inputJson, null));
    }

    suppliedViewModels = Lists.newArrayList(Iterables.filter(suppliedViewModels, Predicates.notNull()));

    // get all the modules that can use these inputs.
    Map<Module, Double> nullModulesMap = Maps.newHashMap();
    Map<Module, Double> modulesMap = Maps.newHashMap();
    Reflections reflections = new Reflections("controllers.modules", Play.application().classloader());
    for (Class<? extends Module> moduleClass : reflections.getSubTypesOf(Module.class)) {
        // we're not interested in abstract classes.
        if (Modifier.isAbstract(moduleClass.getModifiers())) {
            continue;
        }

        // get the Module.Requires/Requireses annotation for each module class.
        // the requirements within each Module.Require are ANDed.
        // the requirements across multiple Module.Require annotations are ORed.
        List<Module.Requires> requireds = Lists.newArrayList();
        if (moduleClass.isAnnotationPresent(Module.Requires.class)) {
            requireds.add(moduleClass.getAnnotation(Module.Requires.class));
        }
        if (moduleClass.isAnnotationPresent(Module.Requireses.class)) {
            Collections.addAll(requireds, moduleClass.getAnnotation(Module.Requireses.class).value());
        }

        if (requireds.size() == 0) {
            requireds.add(null);
        }

        for (Module.Requires required : requireds) {
            final Set<Class<? extends ViewModel>> requiredViewModelClasses = Sets.newHashSet();
            if (required != null) {
                Collections.addAll(requiredViewModelClasses, required.value());
            }

            // get all the supplied view modules that are relevant to this module.
            List<ViewModel> usefulViewModels = Lists
                    .newArrayList(Iterables.filter(suppliedViewModels, new Predicate<ViewModel>() {
                        @Override
                        public boolean apply(@Nullable ViewModel input) {
                            // if this class is required, then return true.
                            if (requiredViewModelClasses.contains(input.getClass())) {
                                return true;
                            }

                            // if any of its super classes are required, that also works.
                            for (Class<?> superClass : ClassUtils.getAllSuperclasses(input.getClass())) {
                                if (requiredViewModelClasses.contains(superClass)) {
                                    return true;
                                }
                            }

                            return false;
                        }
                    }));

            // if all the requirements were satisfied.
            if (usefulViewModels.size() >= requiredViewModelClasses.size()) {
                // try to create an instance of the module.
                Module module = null;
                try {
                    module = moduleClass.newInstance();
                    module.setViewModels(usefulViewModels);
                } catch (InstantiationException | IllegalAccessException | IllegalArgumentException e) {
                    module = null;
                } finally {
                    // if no module was created, just ignore.
                    if (module == null) {
                        continue;
                    }
                }

                // let's not divide by zero!
                double relevancyScore = suppliedViewModels.size() != 0
                        ? usefulViewModels.size() / (double) suppliedViewModels.size()
                        : 1.0;

                // keep null modules separate.
                Map<Module, Double> targetModulesMap = null;
                if (requiredViewModelClasses.size() > 0) {
                    // if a module of this type does not exist, add it.
                    if (Maps.filterKeys(modulesMap, Predicates.instanceOf(moduleClass)).size() == 0) {
                        targetModulesMap = modulesMap;
                    }
                } else {
                    targetModulesMap = nullModulesMap;
                }
                if (targetModulesMap != null) {
                    targetModulesMap.put(module, relevancyScore);
                }
            }
        }
    }

    // use null modules only if there are no regular ones.
    if (modulesMap.size() == 0) {
        modulesMap = nullModulesMap;
    }

    // convert to view models.
    Set<ModuleModel> moduleViewModels = Sets.newHashSet(
            Iterables.transform(modulesMap.entrySet(), new Function<Entry<Module, Double>, ModuleModel>() {
                @Override
                @Nullable
                public ModuleModel apply(@Nullable Entry<Module, Double> input) {
                    return new ModuleModel(input.getKey()).setRelevancyScore(input.getValue());
                }
            }));

    // order first by relevance and then by name.
    return Ordering.from(new Comparator<ModuleModel>() {
        @Override
        public int compare(ModuleModel o1, ModuleModel o2) {
            int relDiff = (int) Math.round((o2.relevancyScore - o1.relevancyScore) * 1000);
            if (relDiff == 0) {
                return o1.name.compareTo(o2.name);
            }

            return relDiff;
        }
    }).sortedCopy(moduleViewModels);
}

From source file:com.digitalpebble.storm.crawler.ConfigurableTopology.java

private String[] parse(String args[]) {

    List<String> newArgs = new ArrayList<>();
    Collections.addAll(newArgs, args);

    Iterator<String> iter = newArgs.iterator();
    while (iter.hasNext()) {
        String param = iter.next();
        if (param.equals("-conf")) {
            if (!iter.hasNext()) {
                throw new RuntimeException("Conf file not specified");
            }//ww  w .  j  av a  2  s  .c o  m
            iter.remove();
            String resource = iter.next();
            try {
                ConfUtils.loadConf(resource, conf);
            } catch (FileNotFoundException e) {
                throw new RuntimeException("File not found : " + resource);
            }
            iter.remove();
        } else if (param.equals("-local")) {
            isLocal = true;
            iter.remove();
        } else if (param.equals("-ttl")) {
            if (!iter.hasNext()) {
                throw new RuntimeException("ttl value not specified");
            }
            iter.remove();
            String ttlValue = iter.next();
            try {
                ttl = Integer.parseInt(ttlValue);
            } catch (NumberFormatException nfe) {
                throw new RuntimeException("ttl value incorrect");
            }
            iter.remove();
        }
    }

    return newArgs.toArray(new String[newArgs.size()]);
}

From source file:com.golonzovsky.oauth2.google.security.GoogleAccessTokenConverter.java

private Set<String> parseScopes(Map<String, ?> map) {
    // Parsing of scopes coming back from Google are slightly different from the default implementation
    // Instead of it being a collection it is a String where multiple scopes are separated by a space.
    Object scopeAsObject = map.containsKey(SCOPE) ? map.get(SCOPE) : EMPTY;
    Set<String> scope = new LinkedHashSet<>();
    if (String.class.isAssignableFrom(scopeAsObject.getClass())) {
        String scopeAsString = (String) scopeAsObject;
        Collections.addAll(scope, scopeAsString.split(" "));
    } else if (Collection.class.isAssignableFrom(scopeAsObject.getClass())) {
        Collection<String> scopes = (Collection<String>) scopeAsObject;
        scope.addAll(scopes);/*w  w  w  .j  av  a 2  s . c  o  m*/
    }
    return scope;
}

From source file:com.intellectualcrafters.plot.util.StringComparison.java

/**
 * Create an ArrayList containing pairs of letters
 *
 * @param s string to split/*ww  w.  ja va2  s. c om*/
 *
 * @return ArrayList
 */
public static ArrayList<String> wLetterPair(final String s) {
    final ArrayList<String> aPairs = new ArrayList<>();
    final String[] wo = s.split("\\s");
    for (final String aWo : wo) {
        final String[] po = sLetterPair(aWo);
        Collections.addAll(aPairs, po);
    }
    return aPairs;
}

From source file:de.tor.tribes.util.bb.FormListFormatter.java

@Override
public String[] getTemplateVariables() {
    List<String> vars = new LinkedList<>();
    Collections.addAll(vars, VARIABLES);
    Collections.addAll(vars, new Circle().getBBVariables());
    return vars.toArray(new String[vars.size()]);
}

From source file:com.ggk.hrms.authentication.CustomAccessTokenConverter.java

private Set<String> parseScopes(Map<String, ?> map) {
    // Parsing of scopes coming back from Google are slightly different from
    // the default implementation
    // Instead of it being a collection it is a String where multiple scopes
    // are separated by a space.
    Object scopeAsObject = map.containsKey(SCOPE) ? map.get(SCOPE) : EMPTY;
    Set<String> scope = new LinkedHashSet<String>();
    if (String.class.isAssignableFrom(scopeAsObject.getClass())) {
        String scopeAsString = (String) scopeAsObject;
        Collections.addAll(scope, scopeAsString.split(" "));
    } else if (Collection.class.isAssignableFrom(scopeAsObject.getClass())) {
        Collection<String> scopes = (Collection<String>) scopeAsObject;
        scope.addAll(scopes);/*from w w  w . java 2  s  .  c  o m*/
    }
    return scope;
}