List of usage examples for java.util ArrayList toArray
@SuppressWarnings("unchecked") public <T> T[] toArray(T[] a)
From source file:Main.java
@SuppressWarnings("unchecked") public static <E> E[] toArray(Collection<?> collection, Class<E> elementType, boolean sort) { if (collection == null || collection.isEmpty()) return null; ArrayList arraylist = new ArrayList(collection); if (sort) {/*from ww w . j a v a2 s .com*/ Collections.sort(arraylist); } E[] array = (E[]) Array.newInstance(elementType, arraylist.size()); arraylist.toArray(array); return array; }
From source file:filterviewplugin.FilterViewSettings.java
private static ProgramFilter[] getAvailableFilters() { ProgramFilter[] allFilters = Plugin.getPluginManager().getFilterManager().getAvailableFilters().clone(); Arrays.sort(allFilters, new Comparator<ProgramFilter>() { public int compare(ProgramFilter f1, ProgramFilter f2) { return f1.getName().compareToIgnoreCase(f2.getName()); }/*from w w w . j av a 2 s. c o m*/ }); ArrayList<ProgramFilter> filters = new ArrayList<ProgramFilter>(Arrays.asList(allFilters)); filters.remove(Plugin.getPluginManager().getFilterManager().getAllFilter()); return filters.toArray(new ProgramFilter[filters.size()]); }
From source file:com.lucidtechnics.blackboard.util.Utility.java
public static Class[] getAllTypes(Class _class) { ArrayList allTypesList = new ArrayList(); ArrayList searchDomainList = new ArrayList(); searchDomainList.add(_class); allTypesList.add(_class); allTypesList = getAllTypes(searchDomainList, allTypesList); return (Class[]) allTypesList.toArray(new Class[allTypesList.size()]); }
From source file:Main.java
/** * Change the type of array of Objects to an array of objects of type * newClass./*from w w w . j a v a 2 s . c o m*/ * */ @SuppressWarnings("unchecked") public static <T> T[] changeArrayType(Object[] array, Class<T> newClass) { ArrayList<T> newArray = new ArrayList<T>(); for (int i = 0; i < array.length; i++) { // Only add those objects that can be cast to the new class if (newClass.isInstance(array[i])) { newArray.add(newClass.cast(array[i])); } } return newArray.toArray((T[]) Array.newInstance(newClass, 0)); }
From source file:ReflectUtils.java
/** * Scans all classes accessible from the context class loader which belong to the given package and subpackages. * * @param packageName The base package//from w w w . j av a 2s. c o m * @return The classes * @throws ClassNotFoundException * @throws IOException */ private static Class[] getClasses(String packageName) throws ClassNotFoundException, IOException { // ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); ClassLoader classLoader = ClassLoader.getSystemClassLoader(); assert classLoader != null; String path = packageName.replace('.', '/'); Enumeration<URL> resources = classLoader.getResources(path); List<File> dirs = new ArrayList<File>(); while (resources.hasMoreElements()) { URL resource = resources.nextElement(); dirs.add(new File(resource.getFile())); } ArrayList<Class> classes = new ArrayList<Class>(); for (File directory : dirs) { classes.addAll(findClasses(directory, packageName)); } return classes.toArray(new Class[classes.size()]); }
From source file:com.milaboratory.core.io.sequence.fastq.RandomAccessFastqReaderTest.java
private static SingleRead[] allReads(File sample) throws IOException { ArrayList<SingleRead> reads = new ArrayList<>(); SingleFastqReader reader = new SingleFastqReader(sample); SingleRead read;//from w w w . j a va 2s . c om while ((read = reader.take()) != null) reads.add(read); return reads.toArray(new SingleRead[reads.size()]); }
From source file:com.feedzai.fos.server.remote.impl.RemoteInterfacesTest.java
/** * Scans all classes accessible from the context class loader which belong to the given package and subpackages. * * @param packageName The base package// w w w .j av a 2 s .c o m * @return The classes * @throws ClassNotFoundException * @throws java.io.IOException */ private static Class[] getClasses(String packageName) throws ClassNotFoundException, IOException { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); assert classLoader != null; String path = packageName.replace('.', '/'); Enumeration<URL> resources = classLoader.getResources(path); List<File> dirs = new ArrayList<>(); while (resources.hasMoreElements()) { URL resource = resources.nextElement(); dirs.add(new File(resource.getFile())); } ArrayList<Class> classes = new ArrayList<>(); for (File directory : dirs) { classes.addAll(findClasses(directory, packageName)); } return classes.toArray(new Class[classes.size()]); }
From source file:Main.java
@SuppressWarnings("unchecked") public static <E> E[] toArray(Enumeration<E> enumeration, Class<E> type) { ArrayList<E> elements = new ArrayList<E>(); while (enumeration.hasMoreElements()) { elements.add(enumeration.nextElement()); }/*from w w w . j a v a 2 s .co m*/ E[] array = (E[]) Array.newInstance(type, elements.size()); elements.toArray(array); return array; }
From source file:Main.java
public static Element[] getChildren(Element parent, String name) { ArrayList<Element> al = new ArrayList<Element>(); NodeList nl = parent.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node n = nl.item(i);//from w w w . j a v a2s . co m if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equals(name)) { al.add((Element) n); } } return al.toArray(new Element[al.size()]); }
From source file:Main.java
/** * returns an arrayList of codes that correspond to the array positions with * true values//w w w . jav a2s .co m * * @return */ public static String[] getSelectedCodes(Context context, boolean[] selectedItems, int codeResourceId) { ArrayList<String> codes = new ArrayList<String>(); Resources res = context.getResources(); String[] allCodes = res.getStringArray(codeResourceId); for (int i = 0; i < selectedItems.length; i++) { if (selectedItems[i]) { codes.add(allCodes[i]); } } return codes.toArray(new String[codes.size()]); }