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:com.puppycrawl.tools.checkstyle.checks.javadoc.WriteTagCheckTest.java

@Override
protected void verify(Checker checker, File[] processedFiles, String messageFileName, String... expected)
        throws Exception {
    stream.flush();/*from w w w  . ja  v  a 2s . c  om*/
    final List<File> theFiles = Lists.newArrayList();
    Collections.addAll(theFiles, processedFiles);
    final int errs = checker.process(theFiles);

    // process each of the lines
    final ByteArrayInputStream localStream = new ByteArrayInputStream(stream.toByteArray());
    try (final LineNumberReader lnr = new LineNumberReader(
            new InputStreamReader(localStream, StandardCharsets.UTF_8))) {

        for (int i = 0; i < expected.length; i++) {
            final String expectedResult = messageFileName + ":" + expected[i];
            final String actual = lnr.readLine();
            assertEquals("error message " + i, expectedResult, actual);
        }

        assertTrue("unexpected output: " + lnr.readLine(), expected.length >= errs);
    }
    checker.destroy();
}

From source file:com.graphiq.kettle.steps.uniquelist.UniqueListStep.java

public String dedupe(String source, String sourceDelim, String outputDelim, boolean removeBlanks) {
    if (source == null) {
        return null;
    }//from w ww . j a  va  2s. c  o  m
    String[] items = source.split(Pattern.quote(sourceDelim));
    LinkedHashSet<String> uniques = new LinkedHashSet<String>();
    Collections.addAll(uniques, items);
    if (removeBlanks) {
        uniques.remove("");
    }
    return StringUtils.join(uniques, outputDelim);
}

From source file:com.android.server.MigratorService.java

/**
 * Set File paths for migrate//w  w  w  .  j a v a2  s .c om
 * @hide
 * @param paths absolute file paths for migration
 */
public void setFileNames(String[] paths) {
    targetFiles = new ArrayList<String>();
    Collections.addAll(targetFiles, paths);
}

From source file:org.transdroid.daemon.Ttorrent.TtorrentAdapter.java

private String makeRequest(Log log, String path, NameValuePair... params) throws DaemonException {

    try {/*from  ww  w .j a va 2 s .  c  o  m*/

        // Setup request using POST
        HttpPost httppost = new HttpPost(buildWebUIUrl(path));
        List<NameValuePair> nvps = new ArrayList<>();
        Collections.addAll(nvps, params);
        httppost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
        return makeWebRequest(httppost, log);

    } catch (UnsupportedEncodingException e) {
        throw new DaemonException(ExceptionType.ConnectionError, e.toString());
    }

}

From source file:net.itransformers.utils.graphmlmerge.GraphmlMergeTestCase.java

@Test
public void testMerge4() throws IOException, URISyntaxException {

    File f1 = new File(getClass().getResource("/graphmlmerge/1.graphml").toURI());
    File f2 = new File(getClass().getResource("/graphmlmerge/2.graphml").toURI());
    File f3 = new File(getClass().getResource("/graphmlmerge/5.graphml").toURI());
    File f3Actual = File.createTempFile("graphml_merge", ".xml");

    Map<String, MergeConflictResolver> edgeConflictResolver = new HashMap<String, MergeConflictResolver>();
    Map<String, MergeConflictResolver> vertexConflictResolver = new HashMap<String, MergeConflictResolver>();
    vertexConflictResolver.put("name", new MergeConflictResolver() {
        @Override/*  www. j  av  a  2  s.  c  o  m*/
        public Object resolveConflict(Object srcValue, Object targetValue) {
            return srcValue + "-" + targetValue;
        }
    });

    edgeConflictResolver.put("method", new MergeConflictResolver() {
        @Override
        public Object resolveConflict(Object srcValue, Object targetValue) {
            // if (srcValue instanceof String && targetValue instanceof String) {
            String[] srcArray = ((String) srcValue).split(",");
            String[] targetArray = ((String) targetValue).split(",");

            String[] both = (String[]) ArrayUtils.addAll(srcArray, targetArray);
            Arrays.sort(both);
            LinkedHashSet<String> m = new LinkedHashSet<String>();
            Collections.addAll(m, both);

            return StringUtils.join(m, ',');

        }
    });

    Map<String, String> edgesTypes = null;
    Map<String, String> vertexTypes = null;
    new GrahmlMerge(edgeConflictResolver, vertexConflictResolver).merge(new File[] { f1, f2 }, f3Actual,
            vertexTypes, edgesTypes, "undirected");
    String xml3 = FileUtils.readFileToString(f3).replaceAll("\r", "");
    String xml3Actual = FileUtils.readFileToString(f3Actual).replaceAll("&#xd;", "");
    xml3Actual = xml3Actual.replaceAll("\r", "");
    Assert.assertEquals(xml3, xml3Actual);
}

From source file:com.mmnaseri.dragonfly.runtime.session.impl.AbstractSessionPreparator.java

private void registerExtensions(Collection<SessionInitializationEventHandler> eventHandlers) {
    log.info("Finding extensions to the data access ...");
    final ExtensionMetadataResolver<Class<?>> metadataResolver = getExtensionMetadataResolver();
    final List<Class> extensionClasses = new ArrayList<Class>();
    for (LookupSource source : extensionDefinitionSources) {
        Collections.addAll(extensionClasses, source.getClasses(basePackages));
    }/*from ww w.ja v a  2  s .  co m*/
    for (SessionInitializationEventHandler eventHandler : eventHandlers) {
        eventHandler.beforeRegisteringExtensions(extensionManager, extensionClasses);
    }
    for (Class extensionDefinitionClass : extensionClasses) {
        log.debug("Registering extension " + extensionDefinitionClass.getCanonicalName());
        final ExtensionMetadata extensionMetadata = metadataResolver.resolve(extensionDefinitionClass);
        for (SessionInitializationEventHandler eventHandler : eventHandlers) {
            eventHandler.beforeRegisteringExtension(extensionManager, extensionMetadata);
        }
        extensionManager.addExtension(extensionMetadata);
        for (SessionInitializationEventHandler eventHandler : eventHandlers) {
            eventHandler.afterRegisteringExtension(extensionManager, extensionMetadata);
        }
    }
    for (SessionInitializationEventHandler eventHandler : eventHandlers) {
        eventHandler.beforeRegisteringExtensions(extensionManager, extensionClasses);
    }
}

From source file:cascading.jdbc.db.DBOutputFormat.java

protected String constructUpdateQuery(String table, String[] fieldNames, String[] updateNames) {
    if (fieldNames == null)
        throw new IllegalArgumentException("field names may not be null");

    Set<String> updateNamesSet = new HashSet<String>();
    Collections.addAll(updateNamesSet, updateNames);

    StringBuilder query = new StringBuilder();

    query.append("UPDATE ").append(table);

    query.append(" SET ");

    if (fieldNames.length > 0 && fieldNames[0] != null) {
        int count = 0;

        for (int i = 0; i < fieldNames.length; i++) {
            if (updateNamesSet.contains(fieldNames[i]))
                continue;

            if (count != 0)
                query.append(",");

            query.append(fieldNames[i]);
            query.append(" = ?");

            count++;/*from  w ww .jav  a 2 s .c  o m*/
        }
    }

    query.append(" WHERE ");

    if (updateNames.length > 0 && updateNames[0] != null) {
        for (int i = 0; i < updateNames.length; i++) {
            query.append(updateNames[i]);
            query.append(" = ?");

            if (i != updateNames.length - 1)
                query.append(" and ");
        }
    }

    query.append(";");

    return query.toString();
}

From source file:net.firejack.platform.core.config.meta.construct.ConfigElementFactory.java

/**
 * @param packageEntity/*from   ww w  .  ja  v  a 2 s  . c om*/
 * @param field
 * @return
 */
public boolean enhanceEntity(IEntityElement packageEntity, IFieldElement field) {
    if (packageEntity == null || field == null) {
        throw new IllegalArgumentException("Parameters should not be null.");
    }
    EntityConfigElement entityConfigElement = (EntityConfigElement) packageEntity;
    IFieldElement[] fields = entityConfigElement.getFields();
    if (DiffUtils.findNamedElement(fields, field.getName()) != null) {
        return false;
    }
    List<IFieldElement> fieldList = new ArrayList<IFieldElement>();
    Collections.addAll(fieldList, fields);
    fieldList.add(field);
    entityConfigElement.setFields(fieldList);
    return true;
}

From source file:com.google.dart.engine.internal.index.file.SplitIndexStoreImpl.java

@Override
public Location[] getRelationships(Element element, Relationship relationship) {
    // special support for UniverseElement
    if (element == UniverseElement.INSTANCE) {
        return getRelationshipsUniverse(relationship);
    }/*from w w w  .jav  a  2s.c o m*/
    // prepare node names
    int elementId = elementCodec.encodeHash(element);
    int[] nodeNameIds = elementToNodeNames.get(elementId);
    // check each node
    List<Location> locations = Lists.newArrayList();
    for (int i = 0; i < nodeNameIds.length; i++) {
        int nodeNameId = nodeNameIds[i];
        String nodeName = stringCodec.decode(nodeNameId);
        IndexNode node = nodeManager.getNode(nodeName);
        if (node != null) {
            Collections.addAll(locations, node.getRelationships(element, relationship));
        } else {
            nodeNameIds = ArrayUtils.removeElement(nodeNameIds, nodeNameId);
            i--;
        }
    }
    // done
    return locations.toArray(new Location[locations.size()]);
}

From source file:com.duroty.application.open.manager.OpenManager.java

/**
 * DOCUMENT ME!// w w w  . j  a va  2  s  . co  m
 *
 * @param msession DOCUMENT ME!
 * @param from DOCUMENT ME!
 * @param to DOCUMENT ME!
 * @param username DOCUMENT ME!
 * @param password DOCUMENT ME!
 * @param signature DOCUMENT ME!
 *
 * @throws Exception DOCUMENT ME!
 */
private void notifyToAdmins(Session msession, InternetAddress from, InternetAddress[] to, String user)
        throws Exception {
    try {
        HtmlEmail email = new HtmlEmail();
        email.setMailSession(msession);

        email.setFrom(from.getAddress(), from.getPersonal());

        HashSet aux = new HashSet(to.length);
        Collections.addAll(aux, to);
        email.setTo(aux);

        email.setSubject("User register in Duroty System");
        email.setHtmlMsg(
                "<p>The user solicits register into the system</p><p>The user is: <b>" + user + "</b></p>");

        email.setCharset(MimeUtility.javaCharset(Charset.defaultCharset().displayName()));

        email.send();
    } finally {
    }
}