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:io.fabric8.kubernetes.pipeline.BuildImageStepExecution.java

private static List<String> apply(FilePath path, Collection<String> patterns) {
    return apply(path, patterns.toArray(new String[patterns.size()]));
}

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

private static IncomeBudgetPeriod[] getIncomeBudgetPeriod(
        final List<? extends BudgetProjectIncomeContract> projectIncomes) {
    //TreeMap Used to maintain the order of the Budget periods.
    Map<Integer, IncomeBudgetPeriod> incomeBudgetPeriodMap = new TreeMap<>();
    BigDecimal anticipatedAmount;
    for (BudgetProjectIncomeContract projectIncome : projectIncomes) {

        Integer budgetPeriodNumber = projectIncome.getBudgetPeriodNumber();
        IncomeBudgetPeriod incomeBudgPeriod = incomeBudgetPeriodMap.get(budgetPeriodNumber);
        if (incomeBudgPeriod == null) {
            incomeBudgPeriod = IncomeBudgetPeriod.Factory.newInstance();
            incomeBudgPeriod.setBudgetPeriod(budgetPeriodNumber);
            anticipatedAmount = BigDecimal.ZERO;
        } else {/*from   w  ww .  ja  v  a2s  .c  om*/
            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();
    return incomeBudgetPeriodCollection.toArray(new IncomeBudgetPeriod[0]);
}

From source file:de.ingrid.portal.security.util.SecurityHelper.java

/**
 * Get merged permissions from user and his roles.
 * /*from   www  . j  a va2 s .  com*/
 * @param p
 * @param roles
 * @param permissionManager
 * @return
 */
public static Permissions getMergedPermissions(Principal p, Collection<Role> roles,
        PermissionManager permissionManager) {

    Permissions result = null;
    Collection<Principal> principals = new ArrayList<Principal>();
    principals.add(p);
    Iterator<Role> roleIterator = roles.iterator();
    while (roleIterator.hasNext()) {
        // check for role based permission to show the user
        Role role = roleIterator.next();
        principals.add(role);
    }
    result = permissionManager.getPermissions(principals.toArray(new Principal[principals.size()]));
    return result;
}

From source file:jenkins.plugins.coverity.CoverityUtils.java

public static File[] listFilesAsArray(File directory, FilenameFilter filter, boolean recurse) {
    Collection<File> files = listFiles(directory, filter, recurse);

    File[] arr = new File[files.size()];
    return files.toArray(arr);
}

From source file:com.gc.iotools.fmt.base.TestUtils.java

/**
 * @deprecated//from w  ww.  j a  va 2  s  .c o m
 * @see FileUtils#iterate();
 * @param allowed
 * @return
 * @throws IOException
 */
@Deprecated
public static String[] listFilesIncludingExtension(final String[] allowed) throws IOException {
    final URL fileURL = TestUtils.class.getResource("/testFiles");
    String filePath = URLDecoder.decode(fileURL.getPath(), "UTF-8");
    final File dir = new File(filePath);
    final String[] files = dir.list();
    final Collection<String> goodFiles = new Vector<String>();
    if (!filePath.endsWith(File.separator)) {
        filePath = filePath + File.separator;
    }
    for (final String file : files) {
        for (final String element : allowed) {
            if (file.endsWith(element)) {
                goodFiles.add(filePath + file);
            }
        }
    }
    return goodFiles.toArray(new String[goodFiles.size()]);
}

From source file:jenkins.plugins.mailer.tasks.MimeMessageBuilder.java

private static Address[] toAddressArray(Collection<InternetAddress> c) {
    if (c == null || c.isEmpty()) {
        return new Address[0];
    }//  www  .ja  v a2  s. co  m
    final Address[] addresses = new Address[c.size()];
    c.toArray(addresses);
    return addresses;
}

From source file:com.turbospaces.core.SpaceUtility.java

/**
 * wrap given kryo configuration with space defaults and register all user supplied classes(with some sugar).</p>
 * //w  w  w .ja va  2  s  . co  m
 * @param configuration
 *            space configuration
 * @param kryo
 *            user custom kryo serializer
 * @throws ClassNotFoundException
 *             re-throw class registration exceptions
 * @throws NoSuchMethodException
 *             re-throw cglib exceptions
 * @throws SecurityException
 *             re-throw cglib exceptions
 * @throws IntrospectionException
 *             re-throw introspection results
 */
@SuppressWarnings("rawtypes")
public static void registerSpaceClasses(final AbstractSpaceConfiguration configuration,
        final DecoratedKryo kryo)
        throws ClassNotFoundException, SecurityException, NoSuchMethodException, IntrospectionException {
    kryo.register(SpaceOperation.class, new EnumSerializer(SpaceOperation.class));
    kryo.register(SpaceTopology.class, new EnumSerializer(SpaceTopology.class));

    kryo.register(MethodCall.class, new FieldsSerializer(kryo, new BasicBO(MethodCall.class)));
    kryo.register(WriteMethodCall.class, new FieldsSerializer(kryo, new BasicBO(WriteMethodCall.class)));
    kryo.register(FetchMethodCall.class, new FieldsSerializer(kryo, new BasicBO(FetchMethodCall.class)));
    kryo.register(BeginTransactionMethodCall.class,
            new FieldsSerializer(kryo, new BasicBO(BeginTransactionMethodCall.class)));
    kryo.register(CommitRollbackMethodCall.class,
            new FieldsSerializer(kryo, new BasicBO(CommitRollbackMethodCall.class)));
    kryo.register(GetSpaceTopologyMethodCall.class,
            new FieldsSerializer(kryo, new BasicBO(GetSpaceTopologyMethodCall.class)));
    kryo.register(GetMbUsedMethodCall.class,
            new FieldsSerializer(kryo, new BasicBO(GetMbUsedMethodCall.class)));
    kryo.register(GetSizeMethodCall.class, new FieldsSerializer(kryo, new BasicBO(GetSizeMethodCall.class)));
    kryo.register(NotifyListenerMethodCall.class,
            new FieldsSerializer(kryo, new BasicBO(NotifyListenerMethodCall.class)));
    kryo.register(EvictAllMethodCall.class, new FieldsSerializer(kryo, new BasicBO(EvictAllMethodCall.class)));
    kryo.register(EvictPercentageMethodCall.class,
            new FieldsSerializer(kryo, new BasicBO(EvictPercentageMethodCall.class)));
    kryo.register(EvictElementsMethodCall.class,
            new FieldsSerializer(kryo, new BasicBO(EvictElementsMethodCall.class)));

    Collection persistentEntities = configuration.getMappingContext().getPersistentEntities();
    BasicPersistentEntity[] persistentEntitiesAsArray = (BasicPersistentEntity[]) persistentEntities
            .toArray(new BasicPersistentEntity[persistentEntities.size()]);
    BO.registerPersistentClasses(kryo, persistentEntitiesAsArray);
}

From source file:com.tealcube.minecraft.bukkit.mythicdrops.utils.ItemUtil.java

public static Material getRandomMaterialFromCollection(Collection<Material> collection) {
    if (collection == null) {
        return Material.AIR;
    }/*  w ww .j a v a2 s .co  m*/
    Material[] array = collection.toArray(new Material[collection.size()]);
    return array[RandomUtils.nextInt(array.length)];
}

From source file:com.l2jfree.gameserver.util.Util.java

/**
 * Returns a delimited string for an given collection of string elements.<BR>
 * (Based on implode() in PHP)/*from w w  w . j  a v  a  2  s.  c  om*/
 * 
 * @param Collection&lt;String&gt; strCollection
 * @param String strDelim
 * @return String implodedString
 */
public static String implodeString(Collection<String> strCollection, String strDelim) {
    return implodeString(strCollection.toArray(new String[strCollection.size()]), strDelim);
}

From source file:com.tealcube.minecraft.bukkit.mythicdrops.utils.ItemUtil.java

public static MaterialData getRandomMaterialDataFromCollection(Collection<MaterialData> collection) {
    if (collection == null) {
        return new MaterialData(Material.AIR);
    }//from  ww  w .  j a  v a  2 s  . c  o m
    MaterialData[] array = collection.toArray(new MaterialData[collection.size()]);
    return array[RandomUtils.nextInt(array.length)];
}