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:io.smartspaces.util.process.BaseNativeApplicationRunner.java

@Override
public NativeApplicationRunner addCommandArguments(String... arguments) {
    if (arguments != null) {
        Collections.addAll(commandArguments, arguments);
    }//from w w  w. java 2  s  .c  om

    return this;
}

From source file:de.tor.tribes.util.VillageUtils.java

public static Village[] getVillagesByAlly(Ally[] pAllies, Comparator<Village> pComparator) {
    List<Village> villages = new LinkedList<>();

    for (Ally a : pAllies) {
        Tribe[] tribes = AllyUtils.getTribes(a, null);
        for (Tribe t : tribes) {
            if (t != null && t.getVillageList() != null) {
                Collections.addAll(villages, t.getVillageList());
            }// w w  w . j  av  a  2 s .  c  o  m
        }
    }

    if (pComparator != null) {
        Collections.sort(villages, pComparator);
    }
    return villages.toArray(new Village[villages.size()]);
}

From source file:com.marketcloud.marketcloud.Json.java

/**
 * Parses a JSONObject, looking for the given structure. <br />
 * <br />//  ww w.ja v  a2  s  .co  m
 * It differs from the other parseData because the user should provide a pre-prepared Hashmap that will be
 * filled by the method. The keys of the map will be used as the string array of the other parseData.
 * <br />
 * In order to avoid override of data that you need to keep, and to use the method without getting an
 * exception, you could pass an "ignore" list containing the keys that you want the method to ignore,
 * simply adding all the keys you want to ignore to the method call. <br />
 * Example: parseData(map, jsonObject, "price", "source"); <br />
 * If the map contains the keys "price" and "source", then the method will ignore them. <br />
 * The normal method call remains: parseData(map, jsonObject) .
 * <br />
 * Note: if the structure is not correct, the method will throw an exception and fail. If the JSONObject
 * contains a JSONArray, only the first argument of the array (the first object) will be parsed.
 *
 * @param map pre-prepared Hashmap
 * @return an Hashmap with the parsed data
 */
@SuppressWarnings("unused")
public HashMap<String, Object> parseData(HashMap<String, Object> map, JSONObject jsonObject, String... ignore)
        throws JSONException {
    if (jsonObject.has("data"))
        jsonObject = getData(jsonObject)[0];

    ArrayList<String> ignorelist = new ArrayList<>();

    Collections.addAll(ignorelist, ignore);

    for (String key : map.keySet()) {
        if (!ignorelist.contains(key))
            map.put(key, jsonObject.get(key));
    }

    return map;
}

From source file:com.expressui.core.util.BeanPropertyType.java

private void initPropertyAnnotations() {
    PropertyDescriptor descriptor = BeanUtils.getPropertyDescriptor(containerType, id);
    if (descriptor != null) {
        Method method = descriptor.getReadMethod();
        if (method != null) {
            Annotation[] readMethodAnnotations = method.getAnnotations();
            Collections.addAll(annotations, readMethodAnnotations);
        }/*from   w ww.j a va  2s  .  com*/
    }
}

From source file:edu.kit.dama.staging.adapters.DefaultDownloadInformationServiceAdapter.java

@Override
public List<DownloadInformation> getDownloadsByStatus(DOWNLOAD_STATUS pStatus, IAuthorizationContext pContext)
        throws ServiceAdapterException {
    LOGGER.debug("Getting all downloads by status {}", pStatus);
    List<DownloadInformation> result = new LinkedList<>();
    List<DownloadInformation> queryResult = DownloadInformationServiceLocal.getSingleton()
            .getDownloadInformationByStatus(pStatus.getId(), 0, Integer.MAX_VALUE, pContext);
    if (queryResult != null && !queryResult.isEmpty()) {
        LOGGER.debug("Query for downloads by status returned '{}' results", queryResult.size());
        Collections.addAll(result, queryResult.toArray(new DownloadInformation[queryResult.size()]));
    } else {//from ww  w  .j  a  v a 2  s. c  o  m
        LOGGER.info("Query to DownloadInformationService returned no result");
    }
    return result;
}

From source file:com.haulmont.cuba.gui.ControllerDependencyInjector.java

protected List<Field> getAllFields(List<Class> classes) {
    List<Field> list = new ArrayList<>();

    for (Class c : classes) {
        if (c != Object.class) {
            Collections.addAll(list, c.getDeclaredFields());
        }//  w  ww.  j  a  va 2 s  .  c om
    }
    return list;
}

From source file:com.kantenkugel.discordbot.modules.AutoRespond.java

private String intConfig(String cfgString, ServerConfig cfg, MessageEvent event) {
    if (cfgString == null) {
        return getUsage();
    }/*from  w w w.  j  av a2  s .  c om*/
    String[] split = cfgString.split("\\s+", 2);
    if (split.length < 2) {
        return getUsage();
    }
    switch (split[0].toLowerCase()) {
    case "add":
        Matcher matcher = addPattern.matcher(split[1]);
        if (matcher.matches() && matcher.group(2).trim().length() > 0) {
            Set<String> keys = new HashSet<>();
            Collections.addAll(keys, matcher.group(2).toLowerCase().split("\\s+"));
            responses.put(matcher.group(1).toLowerCase(), new ImmutablePair<>(keys, matcher.group(3)));
            cfg.save();
            return "Response " + matcher.group(1).toLowerCase() + " added.";
        }
        break;
    case "remove":
    case "del":
        if (responses.containsKey(split[1].toLowerCase())) {
            responses.remove(split[1].toLowerCase());
            cfg.save();
            return "Response " + split[1].toLowerCase() + " removed.";
        } else {
            return "Response " + split[1].toLowerCase() + " not found!";
        }
    case "channels":
        String[] split2 = split[1].split("\\s+", 2);
        if (split2.length == 2) {
            switch (split2[0].toLowerCase()) {
            case "add":
                if (event.getMessage().getMentionedChannels().size() > 0) {
                    event.getMessage().getMentionedChannels().forEach(c -> channels.add(c.getId()));
                    cfg.save();
                    return "Channel(s) added.";
                }
                Optional<TextChannel> any = event.getGuild().getTextChannels().parallelStream()
                        .filter(tc -> tc.getName().equals(split2[1])).findAny();
                if (any.isPresent()) {
                    channels.add(any.get().getId());
                    cfg.save();
                    return "Channel " + split2[1] + " added.";
                } else {
                    return "Channel " + split2[1] + " not found!";
                }
            case "del":
            case "remove":
                if (event.getMessage().getMentionedChannels().size() > 0) {
                    event.getMessage().getMentionedChannels().forEach(c -> channels.remove(c.getId()));
                    cfg.save();
                    return "Channel(s) removed.";
                }
                Optional<TextChannel> any2 = event.getGuild().getTextChannels().parallelStream()
                        .filter(tc -> tc.getName().equals(split2[1])).findAny();
                if (any2.isPresent()) {
                    if (channels.contains(any2.get().getId())) {
                        channels.remove(any2.get().getId());
                        cfg.save();
                        return "Channel " + split2[1] + " removed.";
                    } else {
                        return "Channel " + split2[1] + " was not added!";
                    }
                } else {
                    return "Channel " + split2[1] + " not found!";
                }
            }
        }
        break;
    }
    return getUsage();
}

From source file:cognition.common.model.Individual.java

public List<String> getSeparatedSurnames() {
    if (getSurnames() == null) {
        return new ArrayList<>();
    }//from   w w w  .  j  av  a2s .  c o  m
    List<String> names = new ArrayList<>();
    for (String name : getSurnames()) {
        if (StringUtils.isBlank(name)) {
            continue;
        }
        String[] nameSplit = name.split(" ");
        Collections.addAll(names, nameSplit);

    }
    return names;
}

From source file:buildcraftAdditions.client.gui.GuiBase.java

@Override
public void drawScreen(int x, int y, float f) {
    super.drawScreen(x, y, f);
    List<String> tooltips = new ArrayList<String>();

    for (WidgetBase widget : widgets)
        if (widget.getBounds().contains(x, y))
            widget.addTooltip(x, y, tooltips, isShiftKeyDown());

    if (!tooltips.isEmpty()) {
        List<String> finalLines = new ArrayList<String>();
        for (String line : tooltips) {
            String[] lines = WordUtils.wrap(line, 30).split(System.getProperty("line.separator"));
            Collections.addAll(finalLines, lines);
        }/* w  w  w  . j av  a2 s  .com*/
        drawHoveringText(finalLines, x, y, fontRendererObj);
    }
}

From source file:org.jberet.support.io.MongoItemReaderTest.java

static void validate(final int size, final String expect, final String forbid) {
    final DBCollection collection = db.getCollection(movieOutCollection);
    final DBCursor cursor = collection.find();

    try {//from w ww . ja v  a2s .c om
        //if size is negative number, it means the size is unknown and so skip the size check.
        if (size >= 0) {
            Assert.assertEquals(size, cursor.size());
        }
        final List<String> expects = new ArrayList<String>();
        String[] forbids = CellProcessorConfig.EMPTY_STRING_ARRAY;
        if (expect != null && !expect.isEmpty()) {
            Collections.addAll(expects, expect.split(","));
        }
        if (forbid != null && !forbid.isEmpty()) {
            forbids = forbid.split(",");
        }
        if (expects.size() == 0 && forbids.length == 0) {
            return;
        }
        while (cursor.hasNext()) {
            final DBObject next = cursor.next();
            final String stringValue = next.toString();
            for (final String s : forbids) {
                if (stringValue.contains(s.trim())) {
                    throw new IllegalStateException("Forbidden string found: " + s);
                }
            }
            for (final Iterator<String> it = expects.iterator(); it.hasNext();) {
                final String s = it.next();
                if (stringValue.contains(s.trim())) {
                    System.out.printf("Found expected string: %s%n", s);
                    it.remove();
                }
            }
        }
        if (expects.size() > 0) {
            throw new IllegalStateException("Some expected strings are still not found: " + expects);
        }
    } finally {
        cursor.close();
    }
}