Example usage for java.util List addAll

List of usage examples for java.util List addAll

Introduction

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

Prototype

boolean addAll(Collection<? extends E> c);

Source Link

Document

Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator (optional operation).

Usage

From source file:cz.muni.fi.mir.mathmlcanonicalization.MathMLCanonicalizerCommandLineTool.java

private static List<File> getFiles(File file) throws IOException {
    assert file != null;
    List<File> result = new ArrayList<File>();
    if (file.isDirectory()) {
        File[] files = file.listFiles();
        if (files != null) {
            for (int i = 0; i < files.length; i++) {
                result.addAll(getFiles(files[i]));
            }//  w w  w  . ja  va  2  s.c  o  m
        }
    } else {
        result.add(file);
    }
    return result;
}

From source file:Main.java

public static <E> List<E> compact(List<E> list) {
    boolean foundAtLeastOneNull = false;
    List<E> compacted = null;
    int i = 0;/*from  ww w .  ja  v a2  s. c  om*/

    for (E element : list) {
        if (element == null) {
            if (!foundAtLeastOneNull) {
                compacted = new ArrayList<E>(list.size());
                if (i > 0) {
                    compacted.addAll(list.subList(0, i));
                }
            }
            foundAtLeastOneNull = true;
        } else if (foundAtLeastOneNull) {
            compacted.add(element);
        }
        ++i;
    }

    return foundAtLeastOneNull ? compacted : list;
}

From source file:com.infinities.skyport.util.JsonUtil.java

public static String toLegendJson(boolean insertResponseCode, Collection<?> objects) {
    ObjectMapper mapper = JsonUtil.getObjectMapper();
    ObjectNode status = getObjectMapper().createObjectNode();
    status.put(JsonConstants.RES, String.valueOf(insertResponseCode).toUpperCase());

    List<Object> objs = new ArrayList<Object>();
    objs.addAll(objects);
    objs.add(0, status);//from w w  w .j a v  a 2 s  .  c  om

    try {
        return mapper.writeValueAsString(objs);
    } catch (Exception e) {
        logger.error("json parsing failed", e);
        throw new RuntimeException(e);
    }
}

From source file:ch.devmine.javaparser.utils.ParserUtils.java

/**
 *
 * @param expression/* ww w .j  ava2 s.  co  m*/
 *      an array initialisation (exemple : {{"a", "b"}, {"c", "d", "e"}}
 * @return
 *      an array of Integers with the representation of the dimensions
 */
public static List<Integer> extractDimensions(List<Expression> expression) {
    List<Integer> result = new ArrayList<>();
    result.add(expression.size());
    for (Expression expr : expression) {
        if (expr instanceof List) {
            List l = (List) expr;
            result.addAll(extractDimensions(l));
        }
    }

    return result;
}

From source file:me.ryanhamshire.griefprevention.migrator.RedProtectMigrator.java

public static void migrate(World world, Path redProtectFilePath, Path gpClaimDataPath)
        throws FileNotFoundException, ClassNotFoundException {
    if (!GriefPreventionPlugin.getGlobalConfig().getConfig().migrator.redProtectMigrator) {
        return;/*  w w  w  . j a v a 2s.co m*/
    }

    int count = 0;
    try {
        GriefPreventionPlugin.instance.getLogger().info("Starting RedProtect region data migration for world "
                + world.getProperties().getWorldName() + "...");
        ConfigurationLoader<CommentedConfigurationNode> regionManager = HoconConfigurationLoader.builder()
                .setPath(redProtectFilePath).build();
        CommentedConfigurationNode region = regionManager.load();
        GriefPreventionPlugin.instance.getLogger()
                .info("Scanning RedProtect regions in world data file '" + redProtectFilePath + "'...");
        for (Object key : region.getChildrenMap().keySet()) {
            String rname = key.toString();
            if (!region.getNode(rname).hasMapChildren()) {
                continue;
            }
            int maxX = region.getNode(rname, "maxX").getInt();
            int maxY = region.getNode(rname, "maxY").getInt(255);
            int maxZ = region.getNode(rname, "maxZ").getInt();
            int minX = region.getNode(rname, "minX").getInt();
            int minY = region.getNode(rname, "minY").getInt(0);
            int minZ = region.getNode(rname, "minZ").getInt();
            List<String> owners = new ArrayList<String>();
            owners.addAll(region.getNode(rname, "owners").getList(TypeToken.of(String.class)));

            List<String> members = new ArrayList<String>();
            members.addAll(region.getNode(rname, "members").getList(TypeToken.of(String.class)));

            String creator = region.getNode(rname, "creator").getString();
            String welcome = region.getNode(rname, "welcome").getString();

            // create GP claim data file
            GriefPreventionPlugin.instance.getLogger()
                    .info("Migrating RedProtect region data '" + rname + "'...");
            UUID ownerUniqueId = null;
            if (validate(creator)) {
                try {
                    // check cache first
                    ownerUniqueId = PlayerUtils.getUUIDByName(creator);
                    if (ownerUniqueId == null) {
                        ownerUniqueId = UUID.fromString(getUUID(creator));
                    }
                } catch (Throwable e) {
                    // assume admin claim
                }
            }

            UUID claimUniqueId = UUID.randomUUID();
            Location<World> lesserBoundaryCorner = new Location<>(world, minX, minY, minZ);
            Location<World> greaterBoundaryCorner = new Location<>(world, maxX, maxY, maxZ);
            Path claimFilePath = gpClaimDataPath.resolve(claimUniqueId.toString());
            if (!Files.exists(claimFilePath)) {
                Files.createFile(claimFilePath);
            }

            ClaimStorageData claimStorage = new ClaimStorageData(claimFilePath);
            ClaimDataConfig claimDataConfig = claimStorage.getConfig();
            claimDataConfig.setName(Text.of(rname));
            claimDataConfig.setWorldUniqueId(world.getUniqueId());
            claimDataConfig.setOwnerUniqueId(ownerUniqueId);
            claimDataConfig.setLesserBoundaryCorner(BlockUtils.positionToString(lesserBoundaryCorner));
            claimDataConfig.setGreaterBoundaryCorner(BlockUtils.positionToString(greaterBoundaryCorner));
            claimDataConfig.setDateLastActive(Instant.now());
            claimDataConfig.setType(ownerUniqueId == null ? ClaimType.ADMIN : ClaimType.BASIC);
            if (!welcome.equals("")) {
                claimDataConfig.setGreeting(Text.of(welcome));
            }
            List<String> rpUsers = new ArrayList<>(owners);
            rpUsers.addAll(members);
            List<UUID> builders = claimDataConfig.getBuilders();
            for (String builder : rpUsers) {
                if (!validate(builder)) {
                    continue;
                }

                UUID builderUniqueId = null;
                try {
                    builderUniqueId = PlayerUtils.getUUIDByName(builder);
                    if (builderUniqueId == null) {
                        builderUniqueId = UUID.fromString(getUUID(builder));
                    }
                } catch (Throwable e) {
                    GriefPreventionPlugin.instance.getLogger().error("Could not locate a valid UUID for user '"
                            + builder + "' in region '" + rname + "'. Skipping...");
                    continue;
                }
                if (!builders.contains(builderUniqueId) && ownerUniqueId != null
                        && !builderUniqueId.equals(ownerUniqueId)) {
                    builders.add(builderUniqueId);
                }
            }

            claimDataConfig.setRequiresSave(true);
            claimStorage.save();
            GriefPreventionPlugin.instance.getLogger().info(
                    "Successfully migrated RedProtect region data '" + rname + "' to '" + claimFilePath + "'");
            count++;
        }
        GriefPreventionPlugin.instance.getLogger().info("Finished RedProtect region data migration for world '"
                + world.getProperties().getWorldName() + "'." + " Migrated a total of " + count + " regions.");
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ObjectMappingException e) {
        e.printStackTrace();
    }
}

From source file:net.sf.zekr.engine.bookmark.ui.BookmarkUtils.java

public static List<Object[]> findReferences(BookmarkSet bms, IQuranLocation loc) {
    List<BookmarkItem> bmItems = bms.getBookmarksItems();
    List<Object[]> foundItems = new ArrayList<Object[]>();
    for (BookmarkItem item : bmItems) {
        foundItems.addAll(_findReferences(new ArrayList<String>(), item, loc));
    }//from   w w w.  j a  v  a 2s  .c om
    return foundItems;
}

From source file:com.infinities.skyport.util.JsonUtil.java

public static String toLegendJson(boolean insertResponseCode, List<?> links, Collection<?> objects) {
    ObjectMapper mapper = JsonUtil.getObjectMapper();
    Map<String, Object> status = new HashMap<String, Object>();
    status.put(JsonConstants.RES, String.valueOf(insertResponseCode).toUpperCase());
    status.put(JsonConstants.LINKS, links);

    List<Object> objs = new ArrayList<Object>();
    objs.addAll(objects);
    objs.add(0, status);/*w  ww  .j  av a 2  s  .c  o m*/

    try {
        return mapper.writeValueAsString(objs);
    } catch (Exception e) {
        logger.error("json parsing failed", e);
        throw new RuntimeException(e);
    }
}

From source file:com.github.terma.m.node.Node.java

public static void run(final NodeConfig nodeConfig) {
    final long millisToRefresh = TimeUnit.SECONDS.toMillis(nodeConfig.secToRefresh);
    final List<Checker> checkers = buildCheckers(nodeConfig);

    while (true) {
        final long cycleStart = System.currentTimeMillis();
        final List<Event> events = new ArrayList<>();
        for (final Checker checker : checkers) {
            final long checkStart = System.currentTimeMillis();
            try {
                events.addAll(checker.get());
                LOGGER.info(/*from   w  w w  . ja  v  a 2s .  c om*/
                        "Check: " + checker + ", done: " + (System.currentTimeMillis() - checkStart) + " msec");
            } catch (Exception e) {
                LOGGER.log(Level.SEVERE,
                        "Check: " + checker + ", fail: " + (System.currentTimeMillis() - checkStart) + " msec",
                        e);
                e.printStackTrace();
            }
        }
        LOGGER.info("Cycle done, checks: " + checkers.size() + ", events: " + events.size() + " in: "
                + (System.currentTimeMillis() - cycleStart) + " msec");

        final long sendStart = System.currentTimeMillis();
        try {
            send(nodeConfig.serverHost, nodeConfig.serverPort, nodeConfig.serverContext, events);
        } catch (final IOException exception) {
            exception.printStackTrace();
        }
        LOGGER.info("Send, events: " + events.size() + " done: " + (System.currentTimeMillis() - sendStart)
                + " msec");

        try {
            Thread.sleep(millisToRefresh);
        } catch (InterruptedException e) {
            return;
        }
    }
}

From source file:Main.java

public static List<Element> getElementsByTagNames(Node node, String... tagName) {
    List<Element> nds = new ArrayList<Element>();
    if (tagName.length == 0)
        tagName = new String[] { "" };
    if (node.getNodeType() == Node.ELEMENT_NODE) {
        Element doc = (Element) node;
        for (String elementName : tagName) {
            nds.addAll(toElementList(doc.getElementsByTagName(elementName)));
        }/*from w ww  .  j a v  a 2s.  co  m*/
    } else if (node instanceof Document) {
        Document doc = ((Document) node);
        for (String elementName : tagName) {
            nds.addAll(toElementList(doc.getElementsByTagName(elementName)));
        }
    } else if (node instanceof DocumentFragment) {
        Document doc = ((DocumentFragment) node).getOwnerDocument();
        for (String elementName : tagName) {
            nds.addAll(toElementList(doc.getElementsByTagName(elementName)));
        }
    } else {
        throw new IllegalArgumentException("a node who doesn't support getElementsByTagName operation.");
    }
    return nds;
}

From source file:com.bluexml.side.form.workflow.utils.WorkflowInitialization.java

public static void headLessInitialize(WorkflowFormCollection fc) {
    Process p = fc.getLinked_process();
    if (p != null) {
        // fix update fc.name
        if (StringUtils.trimToNull(fc.getName()) == null) {
            fc.setName(p.getName());//from   w  w  w .  ja va 2s .co m
        }
        List<State> l = new ArrayList<State>();
        l.add(p.getStartstate());
        l.addAll(p.getTasknode());

        // List of Form
        List<FormWorkflow> lf = new ArrayList<FormWorkflow>();

        // For each task we create a form
        for (State s : l) {
            FormWorkflow fw = createTaskForForm(s);
            fw.setRef(s);
            lf.add(fw);
        }
        fc.getForms().addAll(lf);
    }

}