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.liferay.ide.ui.editor.LiferayPropertiesSourceViewerConfiguration.java

@Override
public IContentAssistant getContentAssistant(final ISourceViewer sourceViewer) {
    if (this.propKeys == null) {
        final IEditorInput input = this.getEditor().getEditorInput();

        // first fine runtime location to get properties definitions
        final IPath appServerPortalDir = getAppServerPortalDir(input);
        final String propertiesEntry = getPropertiesEntry(input);

        PropKey[] keys = null;// w  ww  .j  a v a2 s. co  m

        if (appServerPortalDir != null && appServerPortalDir.toFile().exists()) {
            try {
                final JarFile jar = new JarFile(
                        appServerPortalDir.append("WEB-INF/lib/portal-impl.jar").toFile());
                final ZipEntry lang = jar.getEntry(propertiesEntry);

                keys = parseKeys(jar.getInputStream(lang));

                jar.close();
            } catch (Exception e) {
                LiferayUIPlugin.logError("Unable to get portal properties file", e);
            }
        } else {
            return assitant;
        }

        final Object adapter = input.getAdapter(IFile.class);

        if (adapter instanceof IFile && isHookProject(((IFile) adapter).getProject())) {
            final ILiferayProject liferayProject = LiferayCore.create(((IFile) adapter).getProject());
            final ILiferayPortal portal = liferayProject.adapt(ILiferayPortal.class);

            if (portal != null) {
                final Set<String> hookProps = new HashSet<String>();
                Collections.addAll(hookProps, portal.getHookSupportedProperties());

                final List<PropKey> filtered = new ArrayList<PropKey>();

                for (PropKey pk : keys) {
                    if (hookProps.contains(pk.getKey())) {
                        filtered.add(pk);
                    }
                }

                keys = filtered.toArray(new PropKey[0]);
            }
        }

        propKeys = keys;
    }

    if (propKeys != null && assitant == null) {
        final ContentAssistant ca = new ContentAssistant() {
            @Override
            public IContentAssistProcessor getContentAssistProcessor(final String contentType) {
                return new LiferayPropertiesContentAssistProcessor(propKeys, contentType);
            }
        };

        ca.setInformationControlCreator(getInformationControlCreator(sourceViewer));

        assitant = ca;
    }

    return assitant;
}

From source file:edu.ku.brc.dbsupport.MySQLDMBSUserMgr.java

@Override
public List<String> getDatabaseListForUser(final String username) {
    String[] permsArray = new String[] { "SELECT", "DELETE", "UPDATE", "INSERT", "LOCK TABLES", };
    HashSet<String> permsHash = new HashSet<String>();
    Collections.addAll(permsHash, permsArray);

    ArrayList<String> dbNames = new ArrayList<String>();
    try {//from   w  ww .  j  a v  a  2s .  c om
        if (connection != null) {
            String userStr = String.format("'%s'@'%s'", username, hostName);
            String sql = "SHOW GRANTS";
            for (Object obj : BasicSQLUtils.querySingleCol(connection, sql)) {
                boolean isAllDBs = false;
                String data = (String) obj;
                String dbName = null;
                System.out.println("->[" + data + "]");
                if (StringUtils.contains(data, userStr)) {
                    // get database name
                    String[] toks = StringUtils.split(data, '`');
                    if (toks.length > 2) {
                        dbName = toks[1];
                    }
                } else if (StringUtils.contains(data, "ON *.* TO")) {
                    //dbNames.add(obj.toString());   
                    isAllDBs = true;
                }

                // get permissions

                String permsStr = StringUtils.substringBetween(data, "GRANT ", " ON");
                String[] pToks = StringUtils.split(permsStr, ',');

                if (pToks != null) {
                    if (pToks.length == 1 && pToks[0].equalsIgnoreCase("ALL PRIVILEGES") && isAllDBs) {
                        dbNames.addAll(getDatabaseList());

                    } else if (pToks.length >= permsHash.size()) {
                        int cnt = 0;
                        for (String p : pToks) {
                            if (permsHash.contains(p.trim())) {
                                cnt++;
                            }
                        }

                        if (cnt == permsHash.size()) {
                            if (isAllDBs) {
                                dbNames.addAll(getDatabaseList());
                                break;

                            } else if (dbName != null) {
                                dbNames.add(dbName);
                            }
                        }
                    }
                }
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    return dbNames;
}

From source file:interactivespaces.workbench.tasks.WorkbenchTaskContext.java

/**
 * Add a new collection of tasks to the context.
 *
 * @param tasks//from   w w  w  . j av  a  2s  .c  o m
 *          the tasks to add
 *
 * @return this task context
 */
public WorkbenchTaskContext addTasks(WorkbenchTask... tasks) {
    if (tasks != null) {
        Collections.addAll(this.tasks, tasks);
    }

    return this;
}

From source file:edu.cornell.med.icb.goby.modes.SampleQualityScoresMode.java

/**
 * Configure.//from  w ww. j  a va  2s. c om
 *
 * @param args command line arguments
 * @return this object for chaining
 * @throws java.io.IOException   error parsing
 * @throws com.martiansoftware.jsap.JSAPException error parsing
 */
@Override
public AbstractCommandLineMode configure(final String[] args) throws IOException, JSAPException {
    final JSAPResult jsapResult = parseJsapArguments(args);
    inputFilenames.clear();
    Collections.addAll(inputFilenames, jsapResult.getStringArray("input"));
    numberOfReadEntriesToProcess = jsapResult.getInt("number-of-reads");
    return this;
}

From source file:jp.aegif.nemaki.util.impl.PropertyManagerImpl.java

/**
 * Override is not supported for update/*from   w w w. j  a  v a  2  s . c o  m*/
 */
@Override
public void removeValue(String key, String value) {
    String currentVal = config.getProperty(key);
    String[] currentVals = currentVal.split(",");
    List<String> valList = new ArrayList<String>();
    Collections.addAll(valList, currentVals);

    boolean success = valList.remove(value);
    if (success) {
        String newVal = StringUtils.join(valList.toArray(), ",");
        config.setProperty(key, newVal);

        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        URL url = classLoader.getResource(propertiesFile);
        try {
            config.store(new FileOutputStream(new File(url.toURI())), null);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.agileapes.couteau.maven.mojo.AbstractPluginExecutor.java

/**
 * This method will return all project resources
 *
 * @return the project resources/*from w w  w  . j ava  2 s .  c  o  m*/
 */
private Set<Resource> getResources() {
    final Set<Resource> resources = new HashSet<Resource>();
    try {
        Collections.addAll(resources,
                new PathMatchingResourcePatternResolver(getProjectClassLoader()).getResources("classpath*:*"));
    } catch (IOException e) {
        throw new RuntimeException("Could not load project resources", e);
    }
    return resources;
}

From source file:com.greenpepper.html.HtmlExample.java

/** {@inheritDoc} */
@Override
public void setCssClasses(String... classes) {
    Collections.addAll(cssClasses, classes);
}

From source file:com.duroty.application.chat.manager.ChatManager.java

/**
 * DOCUMENT ME!/* w ww .j  av a 2 s .  c  o m*/
 *
 * @param hsession DOCUMENT ME!
 * @param userSender DOCUMENT ME!
 * @param userRecipient DOCUMENT ME!
 */
private void sendMail(Session hsession, javax.mail.Session msession, Users userSender, Users userRecipient,
        String message) {
    try {
        String sender = userSender.getUseUsername();
        String recipient = userRecipient.getUseUsername();

        Identity identitySender = getIdentity(hsession, userSender);
        Identity identityRecipient = getIdentity(hsession, userRecipient);

        HtmlEmail email = new HtmlEmail();
        InternetAddress _from = new InternetAddress(identitySender.getIdeEmail(), identitySender.getIdeName());
        InternetAddress _replyTo = new InternetAddress(identitySender.getIdeReplyTo(),
                identitySender.getIdeName());
        InternetAddress[] _to = MessageUtilities.encodeAddresses(identityRecipient.getIdeEmail(), null);

        if (_from != null) {
            email.setFrom(_from.getAddress(), _from.getPersonal());
        }

        if (_replyTo != null) {
            email.addReplyTo(_replyTo.getAddress(), _replyTo.getPersonal());
        }

        if ((_to != null) && (_to.length > 0)) {
            HashSet aux = new HashSet(_to.length);
            Collections.addAll(aux, _from);
            Collections.addAll(aux, _to);
            email.setTo(aux);
        }

        email.setCharset(charset);
        email.setSubject("Chat " + sender + " >> " + recipient);
        email.setHtmlMsg(message);

        calendar.setTime(new Date());

        String minute = "30";

        if (calendar.get(Calendar.MINUTE) >= 30) {
            minute = "60";
        }

        String value = String.valueOf(calendar.get(Calendar.YEAR))
                + String.valueOf(calendar.get(Calendar.MONTH)) + String.valueOf(calendar.get(Calendar.DATE))
                + String.valueOf(calendar.get(Calendar.HOUR_OF_DAY)) + minute
                + String.valueOf(userSender.getUseIdint() + userRecipient.getUseIdint());
        String reference = "<" + value + ".JavaMail.duroty@duroty" + ">";
        email.addHeader(RFC2822Headers.IN_REPLY_TO, reference);
        email.addHeader(RFC2822Headers.REFERENCES, reference);

        email.addHeader("X-DBox", "CHAT");

        Date now = new Date();
        email.setSentDate(now);

        email.setMailSession(msession);
        email.buildMimeMessage();

        MimeMessage mime = email.getMimeMessage();

        int size = MessageUtilities.getMessageSize(mime);

        if (controlQuota(hsession, userSender, size)) {
            //messageable.saveSentMessage(null, mime, userSender);
            Thread thread = new Thread(new SendMessageThread(email));
            thread.start();
        }
    } catch (UnsupportedEncodingException e) {
    } catch (MessagingException e) {
    } catch (EmailException e) {
    } catch (Exception e) {
    }
}

From source file:org.finra.jtaf.core.parsing.CommandLibraryParser.java

/**
 * for all elements of java.class.path get a Collection of resources under
 * testlibrary//from   ww w.j a  va 2  s. c o  m
 * 
 * @return the resources in the order they are found
 */

private Resource[] getResources() throws IOException, URISyntaxException {
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    ArrayList<Resource> result = new ArrayList<Resource>();

    // We want all commands.xml files in testlibrary folder anywhere in the
    // hierarchy in the classpath
    // There is no single regex to address our requirement. Hence we have
    // two regex.
    // The first one gets all entries where testLibrary is under root.
    // The second gets all
    Resource[] firstResultSet = resolver.getResources("classpath*:/testlibrary/**/*commands.xml");
    if (firstResultSet != null) {
        Collections.addAll(result, firstResultSet);
    }
    // This path does not address testlibrary being directly under the root.
    resolver = new PathMatchingResourcePatternResolver();
    Resource[] secondResultSet = resolver.getResources("classpath*:/**/testlibrary/**/*commands.xml");

    if (secondResultSet != null) {
        if (firstResultSet != null) {
            for (Resource secondResource : secondResultSet) {
                // check to see if it was already found.
                boolean found = false;
                for (Resource firstResource : firstResultSet) {
                    if (firstResource.getDescription().equals(secondResource.getDescription())) {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    result.add(secondResource);
                }
            }
        } else {
            Collections.addAll(result, secondResultSet);
        }
    }

    return result.toArray(new Resource[] {});
}

From source file:org.elasticsearch.client.RestClientMultipleHostsTests.java

public void testRoundRobinNoRetryErrors() throws IOException {
    int numIters = RandomNumbers.randomIntBetween(getRandom(), 1, 5);
    for (int i = 0; i < numIters; i++) {
        Set<HttpHost> hostsSet = new HashSet<>();
        Collections.addAll(hostsSet, httpHosts);
        for (int j = 0; j < httpHosts.length; j++) {
            String method = randomHttpMethod(getRandom());
            int statusCode = randomErrorNoRetryStatusCode(getRandom());
            try {
                Response response = restClient.performRequest(method, "/" + statusCode);
                if (method.equals("HEAD") && statusCode == 404) {
                    //no exception gets thrown although we got a 404
                    assertEquals(404, response.getStatusLine().getStatusCode());
                    assertEquals(statusCode, response.getStatusLine().getStatusCode());
                    assertTrue("host not found: " + response.getHost(), hostsSet.remove(response.getHost()));
                } else {
                    fail("request should have failed");
                }/*from w ww. j av a  2s  .com*/
            } catch (ResponseException e) {
                if (method.equals("HEAD") && statusCode == 404) {
                    throw e;
                }
                Response response = e.getResponse();
                assertEquals(statusCode, response.getStatusLine().getStatusCode());
                assertTrue("host not found: " + response.getHost(), hostsSet.remove(response.getHost()));
                assertEquals(0, e.getSuppressed().length);
            }
        }
        assertEquals("every host should have been used but some weren't: " + hostsSet, 0, hostsSet.size());
    }
    failureListener.assertNotCalled();
}