Example usage for java.util Collection toArray

List of usage examples for java.util Collection toArray

Introduction

In this page you can find the example usage for java.util Collection toArray.

Prototype

default <T> T[] toArray(IntFunction<T[]> generator) 

Source Link

Document

Returns an array containing all of the elements in this collection, using the provided generator function to allocate the returned array.

Usage

From source file:com.jdom.get.stuff.done.android.AndroidApplicationContextFactory.java

public void displayCollectionOfItemsAsCheckBoxes(final Collection<String> collection,
        final Collection<String> initialSelections, final RunnableWithResults<Collection<String>> callback) {

    final String[] array = collection.toArray(new String[collection.size()]);
    boolean[] checked = new boolean[collection.size()];
    for (int i = 0; i < array.length; i++) {
        String value = array[i];//from ww  w.ja va2 s  .  c  om
        checked[i] = initialSelections.contains(value);
    }

    final List<String> selectedItems = new ArrayList<String>();
    for (String initialSelection : initialSelections) {
        selectedItems.add(initialSelection);
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setCancelable(false).setPositiveButton(OK_BUTTON_TEXT, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            callback.callback(selectedItems);
        }
    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
        }
    }).setMultiChoiceItems(array, checked, new DialogInterface.OnMultiChoiceClickListener() {
        public void onClick(DialogInterface dialog, int which, boolean isChecked) {
            String value = array[which];

            if (isChecked && !selectedItems.contains(value)) {
                selectedItems.add(value);
            } else {
                selectedItems.remove(value);
            }
        }
    });
    builder.show();
}

From source file:org.kuali.coeus.s2sgen.impl.generate.support.PHS398ChecklistV1_1Generator.java

private void setProjectIncome(PHS398Checklist phsChecklist, BudgetContract budget) {
    Map<Integer, IncomeBudgetPeriod> incomeBudgetPeriodMap = new TreeMap<>();
    BigDecimal anticipatedAmount;
    for (BudgetProjectIncomeContract projectIncome : budget.getBudgetProjectIncomes()) {
        Integer budgetPeriodNumber = projectIncome.getBudgetPeriodNumber();
        IncomeBudgetPeriod incomeBudgPeriod = incomeBudgetPeriodMap.get(budgetPeriodNumber);
        if (incomeBudgPeriod == null) {
            incomeBudgPeriod = IncomeBudgetPeriod.Factory.newInstance();
            incomeBudgPeriod.setBudgetPeriod(budgetPeriodNumber);
            anticipatedAmount = BigDecimal.ZERO;
        } else {/* ww  w.  j a v  a 2 s.  c  o m*/
            anticipatedAmount = incomeBudgPeriod.getAnticipatedAmount();
        }
        anticipatedAmount = anticipatedAmount.add(projectIncome.getProjectIncome().bigDecimalValue());
        incomeBudgPeriod.setAnticipatedAmount(anticipatedAmount);
        String description = getProjectIncomeDescription(projectIncome);
        if (description != null) {
            if (incomeBudgPeriod.getSource() != null) {
                incomeBudgPeriod.setSource(incomeBudgPeriod.getSource() + ";" + description);
            } else {
                incomeBudgPeriod.setSource(description);
            }
        }
        incomeBudgetPeriodMap.put(budgetPeriodNumber, incomeBudgPeriod);
    }
    Collection<IncomeBudgetPeriod> incomeBudgetPeriodCollection = incomeBudgetPeriodMap.values();
    phsChecklist.setIncomeBudgetPeriodArray(incomeBudgetPeriodCollection.toArray(new IncomeBudgetPeriod[0]));
}

From source file:com.ecyrd.jspwiki.auth.authorize.XMLGroupDatabase.java

/**
 * Returns all wiki groups that are stored in the GroupDatabase as an array
 * of Group objects. If the database does not contain any groups, this
 * method will return a zero-length array. This method causes back-end
 * storage to load the entire set of group; thus, it should be called
 * infrequently (e.g., at initialization time).
 * @return the wiki groups/*from w ww  .j  a  va  2 s  .  c  o  m*/
 * @throws WikiSecurityException if the groups cannot be returned by the back-end
 */
public Group[] groups() throws WikiSecurityException {
    buildDOM();
    Collection<Group> groups = m_groups.values();
    return groups.toArray(new Group[groups.size()]);
}

From source file:com.qualogy.qafe.core.application.ApplicationCluster.java

public ApplicationContext[] clear() {
    Collection<ApplicationContext> values = contexts.values();
    ApplicationContext[] retValue = (ApplicationContext[]) values
            .toArray(new ApplicationContext[values.size()]);
    contexts.clear();/*from  www.  j a  v a 2s. co  m*/
    readOrderList.clear();
    return retValue;
}

From source file:com.krawler.portal.util.StringUtil.java

public static String merge(Collection<?> col, String delimiter) {
    if (col == null) {
        return null;
    }/*from ww w . j  av a  2  s  . c om*/

    return merge(col.toArray(new Object[col.size()]), delimiter);
}

From source file:com.thoughtworks.studios.shine.cruise.stage.details.JobResourceImporter.java

File[] getArtifactFilesOfType(String artifactsPathFromRoot, String jobArtifactPath,
        final String fileExtension) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("getArtifactFilesOfType(" + artifactsPathFromRoot + ", " + jobArtifactPath + ", "
                + fileExtension + ")");
    }/*from  w w  w .j a  v  a2s . c  om*/

    File jobArtifactFile = new File(artifactBaseDir, artifactsPathFromRoot + File.separator + jobArtifactPath);
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Artifact directory calculated to be " + jobArtifactFile.getAbsolutePath());
    }

    if (!jobArtifactFile.exists() || !jobArtifactFile.isDirectory()) {
        return new File[0];
    }

    Collection collection = FileUtils.listFiles(jobArtifactFile,
            new SuffixFileFilter(fileExtension, IOCase.INSENSITIVE), TrueFileFilter.INSTANCE);
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("" + collection.size() + " artifact files found.");
    }
    return (File[]) collection.toArray(new File[0]);
}

From source file:org.kuali.coeus.s2sgen.impl.generate.support.PHS398ChecklistV1_0Generator.java

private void setProjectIncome(PHS398Checklist phsChecklist, BudgetContract budget) {
    phsChecklist.setProgramIncome(YesNoDataType.YES);

    //TreeMap Used to maintain the order of the Budget periods.
    Map<Integer, IncomeBudgetPeriod> incomeBudgetPeriodMap = new TreeMap<>();
    BigDecimal anticipatedAmount;
    for (BudgetProjectIncomeContract projectIncome : budget.getBudgetProjectIncomes()) {
        Integer budgetPeriodNumber = projectIncome.getBudgetPeriodNumber();
        IncomeBudgetPeriod incomeBudgPeriod = incomeBudgetPeriodMap.get(budgetPeriodNumber);
        if (incomeBudgPeriod == null) {
            incomeBudgPeriod = IncomeBudgetPeriod.Factory.newInstance();
            incomeBudgPeriod.setBudgetPeriod(budgetPeriodNumber);
            anticipatedAmount = BigDecimal.ZERO;
        } else {/*from   ww w. j  av a  2 s. com*/
            anticipatedAmount = incomeBudgPeriod.getAnticipatedAmount();
        }
        anticipatedAmount = anticipatedAmount.add(projectIncome.getProjectIncome().bigDecimalValue());
        incomeBudgPeriod.setAnticipatedAmount(anticipatedAmount);
        String description = getProjectIncomeDescription(projectIncome);
        if (description != null) {
            if (incomeBudgPeriod.getSource() != null) {
                incomeBudgPeriod.setSource(incomeBudgPeriod.getSource() + ";" + description);
            } else {
                incomeBudgPeriod.setSource(description);
            }
        }
        incomeBudgetPeriodMap.put(budgetPeriodNumber, incomeBudgPeriod);
    }
    Collection<IncomeBudgetPeriod> incomeBudgetPeriodCollection = incomeBudgetPeriodMap.values();
    phsChecklist.setIncomeBudgetPeriodArray(incomeBudgetPeriodCollection.toArray(new IncomeBudgetPeriod[0]));
}

From source file:com.jkoolcloud.tnt4j.streams.format.FactPathValueFormatter.java

/**
 * Makes string representation of snapshot and appends it to provided string builder.
 * <p>//from   w ww.j  a  v  a 2  s.  c o  m
 * In case snapshot properties have same key for "branch" and "leaf" nodes at same path level, than "leaf" node
 * property key value is appended by configuration defined (cfg. key {@code "DuplicateKeySuffix"}, default value
 * {@value #UNIQUE_SUFFIX}) suffix.
 *
 * @param nvString
 *            string builder instance to append
 * @param snap
 *            snapshot instance to represent as string
 * @return appended string builder reference
 *
 * @see #getUniquePropertyKey(String, com.jkoolcloud.tnt4j.core.Property[], int)
 */
@Override
protected StringBuilder toString(StringBuilder nvString, Trackable t, Snapshot snap) {
    Collection<Property> list = getProperties(snap);
    Property[] pArray = new Property[list.size()];
    pArray = list.toArray(pArray);
    String sName = getTrackableKey(t, getSnapName(snap));
    for (int i = 0; i < pArray.length; i++) {
        Property p = pArray[i];
        if (p.isTransient()) {
            continue;
        }

        String pKey = getUniquePropertyKey(p.getKey(), pArray, i);
        Object value = p.getValue();

        nvString.append(getKeyStr(sName, pKey));
        nvString.append(EQ).append(getValueStr(value)).append(FIELD_SEP);
    }
    return nvString;
}

From source file:com.qmetry.qaf.automation.step.client.AbstractScenarioFileParser.java

@Override
public void parse(String scenarioFile, List<Scenario> scenarios) {
    Collection<Object[]> statements = parseFile(scenarioFile);
    String reference = FileUtil.getRelativePath(scenarioFile, "./");
    processStatements(statements.toArray(new Object[0][0]), reference, scenarios);
}

From source file:com.hp.autonomy.frontend.find.hod.beanconfiguration.HodSecurity.java

@SuppressWarnings("ProhibitedExceptionDeclared")
@Override/*from w ww  .j a  v a  2s.  com*/
protected void configure(final AuthenticationManagerBuilder auth) throws Exception {
    final Collection<String> roles = new LinkedList<>();
    roles.add(FindRole.USER.toString());

    // TODO: Remove when we can get group information from HOD (HOD-2420)
    if (enableBi) {
        roles.add(FindRole.BI.toString());
    }

    auth.authenticationProvider(new HodAuthenticationProvider(tokenRepository,
            new ConstantAuthoritiesResolver(roles.toArray(new String[roles.size()])), authenticationService,
            unboundTokenService, userStoreUsersService, HavenSearchUserMetadata.METADATA_TYPES,
            usernameResolver(), null));
}