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:org.exem.flamingo.web.filesystem.hdfs.HdfsBrowserController.java

/**
 * ?? ./*from w  w w .  j av  a  2 s .com*/
 *
 * @param fileMap ? ?  
 * @return  ? ?
 */
@RequestMapping(value = "copyFiles", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.OK)
public Response copyFiles(@RequestBody Map<String, String> fileMap) {
    String username = getSessionUsername();
    String currentPath = getPathFilter(fileMap.get("currentPath"));
    String files = fileMap.get("files");
    String dstPath = getPathFilter(fileMap.get("dstPath"));
    String[] fromItems = files.split(",");
    List<String> srcFileList = new ArrayList<>();
    Collections.addAll(srcFileList, fromItems);

    //TODO HDFS  ? ? 
    /*List<String> paths = hdfsBrowserAuthService.getHdfsBrowserPatternAll(username);
    String hdfsPathPattern = hdfsBrowserAuthService.validateHdfsPathPattern(currentPath, paths);
            
    fileMap.put("username", username);
    fileMap.put("hdfsPathPattern", hdfsPathPattern);
    fileMap.put("condition", "copyFile");
            
    hdfsBrowserAuthService.getHdfsBrowserUserFileAuth(fileMap);*/
    List<String> copiedFiles = fileSystemService.copyFiles(srcFileList, dstPath, username);

    Response response = new Response();
    response.getList().addAll(copiedFiles);
    response.setSuccess(true);
    return response;
}

From source file:de.tu_dortmund.ub.data.dswarm.Transform.java

private Collection<String> determineProjectIDs() {

    final List<String> projectIDs = new ArrayList<>();

    final String projectIDsString = config.getProperty(TPUStatics.PROTOTYPE_PROJECT_IDS_INDENTIFIER, null);

    if (projectIDsString != null && !projectIDsString.trim().isEmpty()) {

        if (projectIDsString.contains(",")) {

            // multiple project ids

            final String[] projectIDsArray = projectIDsString.split(",");

            Collections.addAll(projectIDs, projectIDsArray);
        } else {//  w w  w .j  av  a 2s  . c o  m

            // only one project id

            projectIDs.add(projectIDsString);
        }
    } else {

        final String projectID = config.getProperty(TPUStatics.PROTOTYPE_PROJECT_ID_INDENTIFIER);

        projectIDs.add(projectID);
    }

    return projectIDs;
}

From source file:edu.ku.brc.helpers.EMailHelper.java

/**
 * Retrieves all the message from the INBOX.
 * @param store the store to retrieve them from
 * @param msgList the list to add them to
 * @return true if successful, false if their was an exception
 *//*www  .  j ava 2 s  .  co m*/
public static boolean getMessagesFromInbox(final Store store,
        final java.util.List<javax.mail.Message> msgList) {
    try {
        Folder inbox = store.getDefaultFolder().getFolder("Inbox"); //$NON-NLS-1$
        inbox.open(Folder.READ_ONLY);

        javax.mail.Message[] messages = inbox.getMessages();

        Collections.addAll(msgList, messages);

        MailBoxInfo mbx = instance.new MailBoxInfo(store, inbox);

        instance.mailBoxCache.add(mbx);

        return true;

    } catch (MessagingException mex) {
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(EMailHelper.class, mex);
        instance.lastErrorMsg = mex.toString();
    }
    return false;
}

From source file:edu.ku.brc.specify.dbsupport.cleanuptools.GeographyAssignISOs.java

/**
 * @return/*from  w  w w.j a  va 2s.co m*/
 */
@SuppressWarnings("rawtypes")
public boolean buildAsyncOrig(final int earthId) {
    String sql = adjustSQL(
            "SELECT COUNT(*) FROM geography WHERE GeographyCode IS NOT NULL AND RankID = 100 AND GeographyTreeDefID = GEOTREEDEFID");
    int numContinentsWithNames = BasicSQLUtils.getCountAsInt(sql);

    continentsCBX = createCheckBox("All Continents"); // I18N

    CellConstraints cc = new CellConstraints();
    PanelBuilder pb1 = new PanelBuilder(new FormLayout("f:p:g", "p,4px,p,4px,p,8px"));
    countriesCBX = createCheckBox("All Countries");
    stateCBX = createCheckBox("All States");
    countiesCBX = createCheckBox("All Counties");
    pb1.add(countriesCBX, cc.xy(1, 1));
    pb1.add(stateCBX, cc.xy(1, 3));
    //pb1.add(countiesCBX,   cc.xy(1, 5));

    allCountriesRB = new JRadioButton("Choose the Geography level to be processed"); //L18N
    singleCountryRB = new JRadioButton("Choose an individual Country");
    btnGroup = new ButtonGroup();
    btnGroup.add(this.allCountriesRB);
    btnGroup.add(this.singleCountryRB);

    if (numContinentsWithNames == 0) {
        continentsCBX.setEnabled(false);
        continentsCBX.setSelected(true);
    }

    countriesCBX.setEnabled(true);
    stateCBX.setEnabled(false);
    countiesCBX.setEnabled(false);

    countryIds.clear();
    sql = "SELECT g.GeographyID, g.Name, g2.Name FROM geography g LEFT JOIN geography g2 ON g.ParentID = g2.GeographyID "
            + "WHERE g.Name IS NOT NULL && LENGTH(g.Name) > 0 AND g.RankID = 200 AND g.GeographyTreeDefID = GEOTREEDEFID ORDER BY g.Name";
    sql = adjustSQL(sql);

    Vector<Object[]> rows = query(sql);
    Object[] titles = new Object[rows.size() + 1];
    int i = 0;
    titles[i++] = "None"; // I18N
    countryIds.add(-1);
    for (Object[] r : rows) {
        countryIds.add((Integer) r[0]);
        String countryStr = (String) r[1];
        String contStr = (String) r[2];
        titles[i++] = countryStr != null ? (countryStr + " (" + contStr + ")") : countryStr;
    }

    PanelBuilder pb2 = new PanelBuilder(new FormLayout("8px,p,2px,f:p:g", "p,4px,p,8px"));
    spCountriesLbl = createFormLabel("Country"); // I18N
    spCountriesCmbx = createComboBox(titles);
    spStatesCBX = createCheckBox("States (Required)"); // I18N
    spCountiesCBX = createCheckBox("Counties"); // I18N

    pb2.add(spCountriesLbl, cc.xy(2, 1));
    pb2.add(spCountriesCmbx, cc.xy(4, 1));
    pb2.add(spStatesCBX, cc.xyw(1, 3, 4));
    //pb2.add(spCountiesCBX,   cc.xyw(1, 5, 4));

    spCountriesCmbx.setSelectedIndex(0);

    spStatesCBX.setSelected(true);
    spStatesCBX.setEnabled(false);
    spCountiesCBX.setEnabled(false);

    String rowDef = createDuplicateJGoodiesDef("p", "4px", 8);
    PanelBuilder pb = new PanelBuilder(new FormLayout("16px,f:p:g", rowDef));

    pb.addSeparator("Continents to be processed", cc.xyw(1, 1, 2));
    pb.add(continentsCBX, cc.xyw(1, 3, 2));

    pb.addSeparator("Countries to be processed", cc.xyw(1, 5, 2));
    pb.add(allCountriesRB, cc.xyw(1, 7, 2));
    pb.add(pb1.getPanel(), cc.xyw(2, 9, 1));

    pb.add(singleCountryRB, cc.xyw(1, 11, 2));
    pb.add(pb2.getPanel(), cc.xyw(2, 13, 1));

    pb.add(createGeoStatsPanel(), cc.xyw(1, 15, 2));

    pb.setDefaultDialogBorder();
    final CustomDialog dlg = new CustomDialog((Frame) getTopWindow(), "ISO Code Processing", true,
            CustomDialog.OKCANCELHELP, pb.getPanel()); // I18N
    dlg.setHelpContext("GeoCleanUpLevelChooser");

    // Setup actions
    ChangeListener rbChangeListener = new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            radioSelected(dlg);
        }
    };
    allCountriesRB.addChangeListener(rbChangeListener);
    singleCountryRB.addChangeListener(null);

    countriesCBX.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            boolean isSel = countriesCBX.isSelected();
            stateCBX.setEnabled(isSel);
            countiesCBX.setEnabled(false);
            if (!isSel) {
                stateCBX.setSelected(false);
                countiesCBX.setSelected(false);
            }
            calcGeoStats();
            dlg.getOkBtn().setEnabled(isSel || spCountriesCmbx.getSelectedIndex() > 0);
        }
    });

    stateCBX.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            countiesCBX.setEnabled(stateCBX.isSelected());
            if (!stateCBX.isSelected()) {
                countiesCBX.setSelected(false);
            }
            calcGeoStats();
        }
    });

    // Special
    spCountriesCmbx.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            boolean isSel = spCountriesCmbx.getSelectedIndex() > 0;
            spStatesCBX.setSelected(isSel);
            spCountiesCBX.setEnabled(isSel);
            if (!isSel) {
                spStatesCBX.setSelected(false);
                spCountiesCBX.setSelected(false);
            }
            calcGeoStats();
            dlg.getOkBtn().setEnabled(isSel || countriesCBX.isSelected());

        }
    });

    spStatesCBX.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            spCountiesCBX.setEnabled(stateCBX.isSelected());
            calcGeoStats();
        }
    });

    allCountriesRB.setSelected(true);

    dlg.createUI();
    dlg.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); // Must be called after 'createUI'
    dlg.getOkBtn().setEnabled(false);

    // AUTO Don't show Dialog because it is automatically setting what to do 
    centerAndShow(dlg);

    if (dlg.isCancelled()) {
        return false;
    }

    connectToDB();

    if (true) // AUTO 
    {
        doAllCountries = new boolean[] { countriesCBX.isSelected(), stateCBX.isSelected(),
                countiesCBX.isSelected(), false };
        doInvCountry = new boolean[] { spCountriesCmbx.getSelectedIndex() > 0, spStatesCBX.isSelected(),
                spCountiesCBX.isSelected(), false };
        doIndvCountryId = doInvCountry[0] ? countryIds.get(spCountriesCmbx.getSelectedIndex()) : null;
    } else {
        int indexOfUSA = getUnitedStatesIndex(titles);
        if (indexOfUSA == -1) {
            Vector<Object> nameList = new Vector<Object>();
            Collections.addAll(nameList, titles);
            JList list = createList(nameList);

            JScrollPane sp = createScrollPane(list);
            pb = new PanelBuilder(new FormLayout("f:p:g", "p,8px,f:p:g"));
            pb.add(createLabel("Select the United States"), cc.xy(1, 1));
            pb.add(sp, cc.xy(1, 3));
            pb.setDefaultDialogBorder();
            final CustomDialog askDlg = new CustomDialog((Frame) getTopWindow(), "Choose", true,
                    CustomDialog.OKCANCELHELP, pb.getPanel()); // I18N
            dlg.setHelpContext("GeoCleanUpLevelChooser");
            centerAndShow(askDlg);
            if (!askDlg.isCancelled()) {
                indexOfUSA = list.getSelectedIndex();
            }
        }

        doAllCountries = new boolean[] { true, false, false, false };
        doInvCountry = new boolean[] { indexOfUSA > -1, true, false, false };
        doIndvCountryId = doInvCountry[0] ? countryIds.get(indexOfUSA) : null;
    }

    // Check to see if it needs indexing.
    boolean shouldIndex = luceneSearch.shouldIndex();

    if (shouldIndex) {
        frame = new ProgressFrame("Building Geography Authority..."); // I18N
        frame.getCloseBtn().setVisible(false);
        frame.turnOffOverAll();
        frame.setDesc("Loading Geonames data..."); // I18N
        frame.pack();
        frame.setSize(450, frame.getBounds().height + 10);
        UIHelper.centerAndShow(frame, 450, frame.getBounds().height + 10);

        luceneSearch.startIndexingProcessAsync(earthId, frame, new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                frame.setVisible(false);
                frame = null;
                if (((Boolean) e.getSource())) {
                    GeographyAssignISOs.this.startTraversal();
                }
            }
        });

    } else {
        sql = "SELECT Name, geonameId, iso_alpha2 FROM countryinfo";
        for (Object[] row : query(sql)) {
            countryInfo.add(new GeoSearchResultsItem((String) row[0], (Integer) row[1], (String) row[2]));
        }
        startTraversal();
    }

    return true;
}

From source file:org.dasein.cloud.skeleton.RESTMethod.java

private @Nonnull String getEndpoint(@Nonnull String resource, @Nullable String id,
        @Nullable NameValuePair... parameters) throws ConfigurationException, InternalException {
    // TODO: implement this to provide a canonical URI based on the resource and ID being references
    ProviderContext ctx = provider.getContext();

    if (ctx == null) {
        throw new NoContextException();
    }//from www . j  a v  a  2 s.  c  o  m
    String endpoint = ctx.getEndpoint();

    if (endpoint == null) {
        logger.error("Null endpoint for the MyCloud cloud");
        throw new ConfigurationException("Null endpoint for MyCloud cloud");
    }
    while (endpoint.endsWith("/") && !endpoint.equals("/")) {
        endpoint = endpoint.substring(0, endpoint.length() - 1);
    }
    if (resource.startsWith("/")) {
        endpoint = endpoint + resource;
    } else {
        endpoint = endpoint + "/" + resource;
    }
    if (id != null) {
        if (endpoint.endsWith("/")) {
            endpoint = endpoint + id;
        } else {
            endpoint = endpoint + "/" + id;
        }
    }
    if (parameters != null && parameters.length > 0) {
        while (endpoint.endsWith("/")) {
            endpoint = endpoint.substring(0, endpoint.length() - 1);
        }
        endpoint = endpoint + "?";
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

        Collections.addAll(params, parameters);
        endpoint = endpoint + URLEncodedUtils.format(params, "utf-8");
    }
    return endpoint;
}

From source file:gov.nih.nci.integration.catissue.client.CaTissueParticipantClient.java

/**
 * This method is used to update the Race collection. It will replace the existing Race with the current Race and
 * then if the current race is MORE, then it will add remaining new race inside the collection. If the new Race is
 * LESSER than existing then it will set the remaining existing(after replacing with current race) to null. This
 * logic is implemented to avoid unnecessary null records in the database.
 * //  w  w  w  .  j a  v  a2  s. c  om
 * @return
 */
private Participant updateParticipantRaceCollection(Participant existingParticipant, Participant participant) {
    final Race[] existRaceArray = (Race[]) existingParticipant.getRaceCollection()
            .toArray(new Race[existingParticipant.getRaceCollection().size()]);
    final Race[] newRaceArray = (Race[]) participant.getRaceCollection()
            .toArray(new Race[participant.getRaceCollection().size()]);

    final int existRaceCount = existRaceArray.length;
    final int newRaceCount = newRaceArray.length;

    // if the existing Race are more than the new/incoming Race
    if (existRaceCount >= newRaceCount) {
        int i = 0;
        for (; i < newRaceCount; i++) {
            // Iterate(till newRaceCount) & Replace the existing Race with the new/incoming Race
            existRaceArray[i].setRaceName(newRaceArray[i].getRaceName());
            existRaceArray[i].setParticipant(newRaceArray[i].getParticipant());
        }
        for (; i < existRaceCount; i++) {
            // set the remaining(more) existing Race to NULL
            existRaceArray[i].setRaceName(null);
            existRaceArray[i].setParticipant(null);
        }
        final Set<Race> mySet = new HashSet<Race>();
        Collections.addAll(mySet, existRaceArray);
        participant.setRaceCollection(mySet);
    } else {
        // if the existing Race are LESS than the new/incoming Race
        int i = 0;
        for (; i < existRaceCount; i++) {
            // Iterate(till existRaceCount) & Replace the existing Race with the new/incoming Race
            existRaceArray[i].setRaceName(newRaceArray[i].getRaceName());
            existRaceArray[i].setParticipant(newRaceArray[i].getParticipant());
        }
        final Set<Race> mySet = new HashSet<Race>();
        Collections.addAll(mySet, existRaceArray);
        participant.setRaceCollection(mySet);
        for (; i < newRaceCount; i++) {
            // add the remaining left new/incoming Race in the collection
            participant.getRaceCollection().add(newRaceArray[i]);
        }
    }
    return participant;
}

From source file:org.exem.flamingo.web.filesystem.hdfs.HdfsBrowserController.java

/**
 * ?? ??.//from  ww  w  .  ja  va  2s  .  c  o  m
 *
 * @param fileMap ? ???  
 * @return ??? ? ?
 */
@RequestMapping(value = "moveFiles", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.OK)
public Response moveFiles(@RequestBody Map<String, String> fileMap) {
    String username = getSessionUsername();
    String currentPath = getPathFilter(fileMap.get("currentPath"));
    String files = fileMap.get("files");
    String dstPath = getPathFilter(fileMap.get("dstPath"));
    String[] fromItems = files.split(",");
    List<String> srcFileList = new ArrayList<>();
    Collections.addAll(srcFileList, fromItems);

    //TODO HDFS  ? ? 
    /*List<String> paths = hdfsBrowserAuthService.getHdfsBrowserPatternAll(username);
    String hdfsPathPattern = hdfsBrowserAuthService.validateHdfsPathPattern(currentPath, paths);
            
    fileMap.put("username", username);
    fileMap.put("hdfsPathPattern", hdfsPathPattern);
    fileMap.put("condition", "moveFile");
            
    hdfsBrowserAuthService.getHdfsBrowserUserFileAuth(fileMap);*/
    List<String> movedFiles = fileSystemService.moveFiles(srcFileList, dstPath, username);
    Response response = new Response();
    response.getList().addAll(movedFiles);
    response.setSuccess(true);
    return response;
}

From source file:MathUtils.java

/**
 * TODO 1 : work on this ; Use StringTokenizer
 * <p>Splits the provided text into an array ,* separators specified.</p>
 *
 * <p>The separator is not included in the returned String array.
 * Adjacent separators are treated as one separator.</p>
 *
 * <pre>     //from   ww w  .j  a va  2s.co  m
 * StringUtils.split("ab de fg", " ")   = ["ab", "de", "fg"]
 * StringUtils.split("ab   de fg", " ") = ["ab", "cd", "ef"]
 * StringUtils.split("ab:cd:ef", ":")    = ["ab", "cd", "ef"]
 * </pre>
 *
 * @param string  the String to parse, may be null
 * @param separatorChars  the characters used as the delimiters
 * @return an array of parsed Strings
 * @throws IllegalArgumentException if string or separatorChars is null, or if separatorChars is empty
 */
public static String[] split(String string, String separatorChars) {
    if (string == null) {
        throw new IllegalArgumentException("string argument is null");
    }
    if (separatorChars == null || separatorChars.length() == 0) {
        throw new IllegalArgumentException("separators is null or empty");
    }

    List<String> resultList = new ArrayList<String>();
    String worker = new String(string);
    String firstSeparator = separatorChars.substring(0, 1);
    assert firstSeparator.length() == 1;

    char[] charArray = separatorChars.toCharArray();
    //We replace multiple instance of other separator by only one firstSeparator
    for (int i = 1; i < charArray.length; i++) {
        String pattern = "(" + charArray[i] + ")+";
        worker = worker.replaceAll(pattern, firstSeparator);
    }

    //One more pass for the first separator
    String pattern = "(" + firstSeparator + ")+";
    worker = worker.replaceAll(pattern, firstSeparator);

    System.out.println("separator : " + firstSeparator + " ; worker : " + worker);
    Collections.addAll(resultList, worker.split(firstSeparator));
    return (String[]) resultList.toArray(new String[resultList.size()]);
}

From source file:com.m4rc310.cb.builders.ComponentBuilder.java

@Override
public void update(Object... targetsA) {
    if (targetsA.length == 0) {
        Collections.addAll(targets, targetsA);
    }/*from  w ww.  j  av  a  2  s  .co  m*/

    for (Object tar : targetsA) {
        adapters.entrySet().stream().forEach((entrySet) -> {
            Field field = entrySet.getKey();
            AbstractComponetAdapter adapter = entrySet.getValue();
            if (getTargetForField(field) == tar) {
                try {
                    Object value = field.get(tar);
                    adapter.update(field, value);
                } catch (IllegalArgumentException | IllegalAccessException e) {
                    infoError(e);
                }
            }
        });
    }
}