List of usage examples for java.util ArrayList toArray
@SuppressWarnings("unchecked") public <T> T[] toArray(T[] a)
From source file:com.fmguler.ven.support.LiquibaseConverter.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 ww. j a v a2s. c om * @return The classes * @throws ClassNotFoundException * @throws IOException */ private static Class[] getClasses(String packageName) throws ClassNotFoundException, IOException { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); assert classLoader != null; String path = packageName.replace('.', '/'); Enumeration resources = classLoader.getResources(path); List dirs = new ArrayList(); while (resources.hasMoreElements()) { URL resource = (URL) resources.nextElement(); dirs.add(new File(resource.getFile())); } ArrayList classes = new ArrayList(); Iterator it = dirs.iterator(); while (it.hasNext()) { File directory = (File) it.next(); classes.addAll(findClasses(directory, packageName)); } return (Class[]) classes.toArray(new Class[classes.size()]); }
From source file:jfs.sync.vfs.JFSVFSFileProducer.java
/** * @return Returns the available schemes. *//*ww w .ja v a2 s.c o m*/ static public String[] getSchemes() { ArrayList<String> schemes = new ArrayList<String>(); String[] schemesArray = new String[0]; try { for (String s : VFS.getManager().getSchemes()) { if (!s.equals(JFSConst.SCHEME_LOCAL) && !s.equals(JFSConst.SCHEME_EXTERNAL)) { schemes.add(s); } } } catch (FileSystemException e) { JFSLog.getErr().getStream().println(e.getLocalizedMessage()); } return schemes.toArray(schemesArray); }
From source file:com.frostwire.gui.updates.PortableUpdater.java
private static String[] createWSHScriptCommand(File source, File dest) { ArrayList<String> command = new ArrayList<String>(); command.add("wscript"); command.add("//B"); command.add("//NoLogo"); command.add(new File(CommonUtils.getUserSettingsDir(), PORTABLE_UPDATER_SCRIPT_WINDOWS).getAbsolutePath()); command.add(source.getAbsolutePath()); command.add(dest.getAbsolutePath()); return command.toArray(new String[0]); }
From source file:Main.java
/** Genera una lista de cadenas compuesta por los fragmentos de texto * separados por la cadena de separación indicada. No soporta * expresiones regulares. Por ejemplo:<br> * <ul>/*from ww w.j av a2s . c o m*/ * <li><b>Texto:</b> foo$bar$foo$$bar$</li> * <li><b>Separado:</b> $</li> * <li><b>Resultado:</b> "foo", "bar", "foo", "", "bar", ""</li> * </ul> * @param text * Texto que deseamos dividir. * @param sp * Separador entre los fragmentos de texto. * @return Listado de fragmentos de texto entre separadores. * @throws NullPointerException * Cuando alguno de los parámetros de entrada es {@code null}. */ public static String[] split(final String text, final String sp) { final ArrayList<String> parts = new ArrayList<String>(); int i = 0; int j = 0; while (i != text.length() && (j = text.indexOf(sp, i)) != -1) { if (i == j) { parts.add(""); //$NON-NLS-1$ } else { parts.add(text.substring(i, j)); } i = j + sp.length(); } if (i == text.length()) { parts.add(""); //$NON-NLS-1$ } else { parts.add(text.substring(i)); } return parts.toArray(new String[0]); }
From source file:Main.java
/** * Access all immediate child elements inside the given Element * * @param element the starting element, cannot be null. * @param namespaceURI name space of the child element to look for, * cannot be null. Use "*" to match all namespaces * @param elemName the name of the child element to look for, * cannot be null.//from w ww .j a v a 2 s.c o m * @return array of all immediate child element inside element, or * an array of size zero if no child elements are found. */ public static Element[] getChildElements(Element element, String namespaceURI, String elemName) { NodeList list = element.getChildNodes(); int len = list.getLength(); ArrayList<Node> array = new ArrayList<Node>(len); for (int i = 0; i < len; i++) { Node n = list.item(i); if (n.getNodeType() == Node.ELEMENT_NODE) { if (elemName.equals(n.getLocalName()) && ("*".equals(namespaceURI) || namespaceURI.equals(n.getNamespaceURI()))) { array.add(n); } } } Element[] elems = new Element[array.size()]; return (Element[]) array.toArray(elems); }
From source file:com.example.igorklimov.popularmoviesdemo.helpers.Utility.java
public static void addDetails(ContentValues details, ArrayList<ContentValues> allReviews, Context context) { ContentResolver resolver = context.getContentResolver(); ContentValues[] a = new ContentValues[allReviews.size()]; allReviews.toArray(a); Log.v(TAG, "addDetails: " + resolver.insert(MovieContract.Details.CONTENT_URI, details)); Log.v(TAG, "addDetails: " + resolver.bulkInsert(MovieContract.Review.CONTENT_URI, a)); }
From source file:eu.morfeoproject.fast.catalogue.util.Util.java
/** * Transform a string of tags into an array. The tags are * separated by +. Example: amazon+shopping * @param tagsStr//w w w . j a v a 2s. c o m * @return an array of tags */ public static String[] splitTags(String tagsStr) { String[] tags = null; if (tagsStr == null) return new String[0]; else if (tagsStr.contains("+")) { //tags = tagsStr.split("+"); throws an exception!! ArrayList<String> tmp = new ArrayList<String>(); int from = 0; int to = tagsStr.indexOf("+"); while (to != -1) { tmp.add(tagsStr.substring(from, to)); from = to + 1; to = tagsStr.indexOf("+", from); } tmp.add(tagsStr.substring(from, tagsStr.length())); tags = new String[tmp.size()]; tags = tmp.toArray(tags); } else { tags = new String[1]; tags[0] = tagsStr; } return tags; }
From source file:net.sf.spindle.core.util.eclipse.JarEntryFileUtil.java
public static IPackageFragment[] getPackageFragments(IWorkspaceRoot root, JarEntryFile entry) throws CoreException { ArrayList result = new ArrayList(); IProject[] projects = root.getProjects(); for (int i = 0; i < projects.length; i++) { if (!projects[i].isOpen() || !projects[i].hasNature(JavaCore.NATURE_ID)) continue; IPackageFragment frag = getPackageFragment(JavaCore.create(projects[i]), entry, false); if (frag != null) result.add(frag);// w w w. j ava 2 s. c o m } return (IPackageFragment[]) result.toArray(new IPackageFragment[result.size()]); }
From source file:com.galenframework.speclang2.pagespec.ForLoop.java
private static Object[] readSequenceForSimpleLoop(String sequenceStatement, Place place) { sequenceStatement = sequenceStatement.replace(" ", ""); sequenceStatement = sequenceStatement.replace("\t", ""); Pattern sequencePattern = Pattern.compile(".*\\-.*"); try {//from w w w. ja v a 2 s . c om String[] values = sequenceStatement.split(","); ArrayList<Object> sequence = new ArrayList<>(); for (String stringValue : values) { if (sequencePattern.matcher(stringValue).matches()) { sequence.addAll(createSequence(stringValue)); } else { sequence.add(convertValueToIndex(stringValue)); } } return sequence.toArray(new Object[sequence.size()]); } catch (Exception ex) { throw new SyntaxException(place, "Incorrect sequence syntax: " + sequenceStatement, ex); } }
From source file:grails.plugin.searchable.internal.lucene.LuceneUtils.java
/** * Returns a list of terms by analysing the given text * * @param text the text to analyse//from w w w .j a va2 s. c o m * @param analyzer the Analyzer instance to use, may be null in which case Lucene's StandardAnalyzer is used * @return a list of text terms */ public static String[] termsForText(String text, Analyzer analyzer) { try { if (analyzer == null) { analyzer = new StandardAnalyzer(); } TokenStream stream = analyzer.tokenStream("contents", new StringReader(text)); ArrayList terms = new ArrayList(); Token token = new Token(); while (true) { token = stream.next(token); if (token == null) break; terms.add(new String(token.termBuffer(), 0, token.termLength())); } return (String[]) terms.toArray(new String[terms.size()]); } catch (IOException ex) { // Convert to unchecked LOG.error("Unable to analyze the given text: " + ex, ex); throw new IllegalArgumentException("Unable to analyze the given text: " + ex); } }