List of usage examples for java.util Collection toArray
default <T> T[] toArray(IntFunction<T[]> generator)
From source file:jofc2.OFC.java
/** * Convenience method for converting Collections to Arrays. You can use this * where the API has limited support for collections: * getLabels().addLabels(OFC.toArray(stringList, String.class)); * //from ww w . ja va 2s . co m * @param collection * The collection to use * @param type * The supertype for the collection. This will commonly be * Integer, Number, etc. * @return the array of the collection */ @SuppressWarnings("unchecked") public static <T> T[] toArray(Collection<T> collection, Class<? extends T> type) { return collection.toArray((T[]) Array.newInstance(type, collection.size())); }
From source file:com.jaeksoft.searchlib.snippet.SnippetVectors.java
private static final Collection<SnippetVector> removeIncludes( final Collection<SnippetVector> vectorCollection) { SnippetVector[] vectors = vectorCollection.toArray(new SnippetVector[vectorCollection.size()]); new SnippetVectorSort(vectors); SnippetVector last = null;// w w w.j a v a 2 s. c o m for (SnippetVector current : vectors) { if (last != null && current.start == last.start && current.end >= last.end) last.remove = true; last = current; } List<SnippetVector> vectorList = new ArrayList<SnippetVector>(vectors.length); for (SnippetVector vector : vectors) if (!vector.remove) vectorList.add(vector); return vectorList; }
From source file:com.aionlightning.commons.utils.PropertiesUtils.java
/** * Loads all .property files form directory * /*w ww . j av a 2s . c om*/ * @param dir * directory * @param recursive * parse subdirectories or not * @return array of loaded properties * @throws IOException * if was unable to read properties */ public static Properties[] loadAllFromDirectory(File dir, boolean recursive) throws IOException { Collection<File> files = FileUtils.listFiles(dir, new String[] { "properties" }, recursive); return load(files.toArray(new File[files.size()])); }
From source file:com.tesora.dve.common.PEStringUtils.java
public static String[] toArray(Collection<String> values) { return values.toArray(EMPTY_ARRAY); }
From source file:org.jasig.jpa.CacheKey.java
public static CacheKey build(String source, Collection<? extends Serializable> key) { return new CacheKey(source, key.toArray(new Serializable[key.size()])); }
From source file:com.baasbox.service.dbmanager.DbManagerService.java
public static List<String> getExports() { java.io.File dir = new java.io.File(backupDir); if (!dir.exists()) { dir.mkdirs();//from ww w . j ava2 s. com } Collection<java.io.File> files = FileUtils.listFiles(dir, new String[] { "zip" }, false); File[] fileArr = files.toArray(new File[files.size()]); Arrays.sort(fileArr, LastModifiedFileComparator.LASTMODIFIED_REVERSE); List<String> fileNames = new ArrayList<String>(); for (java.io.File file : fileArr) { fileNames.add(file.getName()); } return fileNames; }
From source file:org.springframework.core.util.StringUtils.java
/** * Copy the given Collection into a String array. * The Collection must contain String elements only. * * @param collection the Collection to copy * @return the String array (<code>null</code> if the passed-in * Collection was <code>null</code>) *//* w w w . jav a 2 s. c om*/ public static String[] toStringArray(final Collection<String> collection) { if (collection == null) { return null; } return collection.toArray(new String[collection.size()]); }
From source file:com.google.u2f.TestUtils.java
public static X509Certificate[] parseCertificateChainBase64(String encodedDerCertificates) { try {//from w ww . j a v a 2s . c om Collection<? extends Certificate> certCollection = CertificateFactory.getInstance("X.509") .generateCertificates(new ByteArrayInputStream(parseBase64(encodedDerCertificates))); return certCollection.toArray(new X509Certificate[0]); } catch (CertificateException e) { throw new RuntimeException(e); } }
From source file:com.tealcube.minecraft.bukkit.mythicdrops.utils.TierUtil.java
public static Tier randomTier(Collection<Tier> collection) { Validate.notNull(collection, "Collection<Tier> cannot be null"); Tier[] array = collection.toArray(new Tier[collection.size()]); return array[RandomUtils.nextInt(array.length)]; }
From source file:io.fabric8.maven.core.util.MavenUtil.java
private static URLClassLoader createURLClassLoader(Collection<URL> jars) { return new URLClassLoader(jars.toArray(new URL[jars.size()])); }