List of usage examples for java.util ArrayList toArray
@SuppressWarnings("unchecked") public <T> T[] toArray(T[] a)
From source file:com.panduka.weatherforecast.utils.DataResolver.java
/** * Extract Flags details from JSON array object * * @param jsonArray Flags details JSON array object * @return returns a String array of flags data *//*from www .j a v a 2 s . c o m*/ private String[] createStringArray(JSONArray jsonArray) throws JSONException { ArrayList<String> dataArr = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { dataArr.add(jsonArray.getString(i)); } return dataArr.toArray(new String[dataArr.size()]); }
From source file:org.mule.providers.soap.axis.wsdl.wsrf.util.AdviceAdderHelper.java
/** * list Classes inside a given package./*from ww w.j a v a 2s . co m*/ * * @param pckgname String name of a Package, EG "java.lang" * @return Class[] classes inside the root of the given package * @throws ClassNotFoundException if the Package is invalid */ private static Class[] getClasses(String pckgname) throws ClassNotFoundException { ArrayList classes = new ArrayList(); // Get a File object for the package File directory = null; try { URL str = Thread.currentThread().getContextClassLoader().getResource(pckgname.replace('.', '/')); System.out.println("instance advice..." + new File(str.getFile()).getName()); directory = new File(str.getFile()); } catch (NullPointerException x) { throw new ClassNotFoundException(pckgname + " does not appear to be a valid package"); } if (directory.exists()) { // Get the list of the files contained in the package String[] files = directory.list(); for (int i = 0; i < files.length; i++) { // we are only interested in *Advice.class files if (files[i].endsWith("Advice.class")) { // removes the .class extension classes.add(Class.forName( pckgname + '.' + files[i].substring(0, files[i].length() - SUFFIX_CLASS_LENGTH))); } } } else { throw new ClassNotFoundException(pckgname + " does not appear to be a valid package"); } Class[] classesA = new Class[classes.size()]; classes.toArray(classesA); return classesA; }
From source file:bide.core.par.Spot.java
private double[] formatSpot(double[] spot) { int express = 0; ArrayList<Double> expressSpot = new ArrayList<Double>(); for (int i = 0; i < spot.length; i++) { if (!Double.isNaN(spot[i])) { express++;// w w w. ja v a 2s. c o m expressSpot.add(spot[i]); } } double[] expSpot = ArrayUtils.toPrimitive(expressSpot.toArray(new Double[express])); return expSpot; }
From source file:org.jenkinsci.plugins.htpasswd.HtPasswdSecurityRealm.java
/** * Retrieves the array of granted authorities for the given user. * It will always contain at least one entry - "authenticated" * * @param username//from www. j a va2s.c om * @return the array of granted authorities, with at least */ private GrantedAuthority[] getAuthenticatedUserGroups(final String username) { try { HtGroupFile htgroups = getHtGroupFile(); List<String> groups = htgroups.getGroups(username); ArrayList<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(groups.size() + 1); authorities.add(AUTHENTICATED_AUTHORITY); for (String group : groups) { authorities.add(new GrantedAuthorityImpl(group)); } return authorities.toArray(GRANTED_AUTHORITY_TYPE); } catch (Exception ex) { return DEFAULT_AUTHORITY; } }
From source file:com.openkm.util.MailUtils.java
/** * Conversion from array of Addresses to array of Strings. *//*w ww . j a v a 2 s .c om*/ private static String[] addressToString(Address[] addresses) { ArrayList<String> list = new ArrayList<String>(); if (addresses != null) { for (int i = 0; i < addresses.length; i++) { list.add(addressToString(addresses[i])); } } return (String[]) list.toArray(new String[list.size()]); }
From source file:eu.stratosphere.test.util.AbstractTestBase.java
public void compareResultsByLinesInMemoryWithStrictOrder(String expectedResultStr, String resultPath) throws Exception { ArrayList<String> list = new ArrayList<String>(); readAllResultLines(list, resultPath, true); String[] result = (String[]) list.toArray(new String[list.size()]); String[] expected = expectedResultStr.split("\n"); Assert.assertEquals("Different number of lines in expected and obtained result.", expected.length, result.length);//from ww w . ja v a2s . c o m Assert.assertArrayEquals(expected, result); }
From source file:com.cloudera.sqoop.manager.MySQLManager.java
@Override public String[] listDatabases() { // TODO(aaron): Add an automated unit test for this. ResultSet results;/* w w w . j a va2 s . c o m*/ try { results = execute("SHOW DATABASES"); } catch (SQLException sqlE) { LOG.error("Error executing statement: " + sqlE.toString()); release(); return null; } try { ArrayList<String> databases = new ArrayList<String>(); while (results.next()) { String dbName = results.getString(1); databases.add(dbName); } return databases.toArray(new String[0]); } catch (SQLException sqlException) { LOG.error("Error reading from database: " + sqlException.toString()); return null; } finally { try { results.close(); } catch (SQLException sqlE) { LOG.warn("Exception closing ResultSet: " + sqlE.toString()); } release(); } }
From source file:org.cloudfoundry.tools.compiler.CloudFoundryJavaCompiler.java
/** * Adapt any tasks options for use with the eclipse batch compiler. * // w ww.jav a 2s . c o m * @param options the source options (never null) * @param classes the class (never null) * @return a set of options that can be applied to the {@link EclipseBatchCompiler} */ private String[] getArgumentsForBatchCompiler(List<String> options, List<String> classes) { ArrayList<String> arguments = new ArrayList<String>(); arguments.addAll(options); if (!classes.isEmpty()) { arguments.add("-classNames"); arguments.add(StringUtils.collectionToCommaDelimitedString(classes)); } return arguments.toArray(new String[arguments.size()]); }
From source file:eu.stratosphere.test.util.AbstractTestBase.java
public void compareResultsByLinesInMemory(String expectedResultStr, String resultPath) throws Exception { ArrayList<String> list = new ArrayList<String>(); readAllResultLines(list, resultPath, false); String[] result = (String[]) list.toArray(new String[list.size()]); Arrays.sort(result);/*w w w . j a va2 s.co m*/ String[] expected = expectedResultStr.isEmpty() ? new String[0] : expectedResultStr.split("\n"); Arrays.sort(expected); Assert.assertEquals("Different number of lines in expected and obtained result.", expected.length, result.length); Assert.assertArrayEquals(expected, result); }
From source file:com.enonic.esl.xml.XMLTool.java
/** * Get an element's sub-elements as an Element array. Returns an empty array if root element is null or the element does not have any * sub-elements.//from w ww . j a v a 2 s . co m * * @param root Element * @return Element[] */ public static Element[] getElements(Element root) { ArrayList<Element> elements = getElementsAsList(root); if (elements.size() > 0) { return elements.toArray(new Element[elements.size()]); } else { return new Element[0]; } }