List of usage examples for java.util ArrayList toArray
@SuppressWarnings("unchecked") public <T> T[] toArray(T[] a)
From source file:au.com.wallaceit.reddinator.SubredditManager.java
public void setAllFilter(ArrayList<String> filter) { prefs.edit().putString("allFilter", StringUtils.join(filter.toArray(new String[filter.size()]), ",")) .apply();/*w w w. j ava2 s . c o m*/ }
From source file:com.ikon.util.MailUtils.java
/** * Conversion from array of Addresses to array of Strings. *//* w w w .java 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(addresses[i].toString()); } } return (String[]) list.toArray(new String[list.size()]); }
From source file:com.kamuda.common.exception.ExceptionUtils.java
/** * <p>Creates a compact stack trace for the root cause of the supplied * <code>Throwable</code>.</p> * //from w w w. j a v a 2s . co m * @param throwable the throwable to examine, may be null * @return an array of stack trace frames, never null * @since 2.0 */ public static String[] getRootCauseStackTrace(Throwable throwable) { if (throwable == null) { return ArrayHelper.EMPTY_STRING_ARRAY; } Throwable throwables[] = getThrowables(throwable); int count = throwables.length; ArrayList frames = new ArrayList(); List nextTrace = getStackFrameList(throwables[count - 1]); for (int i = count; --i >= 0;) { List trace = nextTrace; if (i != 0) { nextTrace = getStackFrameList(throwables[i - 1]); removeCommonFrames(trace, nextTrace); } if (i == count - 1) { frames.add(throwables[i].toString()); } else { frames.add(WRAPPED_MARKER + throwables[i].toString()); } for (int j = 0; j < trace.size(); j++) { frames.add(trace.get(j)); } } return (String[]) frames.toArray(new String[0]); }
From source file:controller.VisLP.java
/** * @param points//ww w . j a v a 2s.c o m * Unordered list of points that can form a * convex polygon, but in the given order * does not necessarily form a convex * polygon if edges are drawn between the * points in the given order. * @return * An ordered list of points that when edges * are drawn in this order is guaranteed to * form a convex polygon. */ static Point2D[] convex(Point2D[] points) { /* * Sort the points first on x-value then * on y-value, both in ascending order. */ Arrays.sort(points, new Comparator<Point2D>() { @Override public int compare(Point2D o1, Point2D o2) { double s = o1.getX() - o2.getX(); if (s > 0) return 1; if (s < 0) return -1; s = o1.getY() - o2.getY(); if (s > 0) return 1; if (s < 0) return -1; return 0; } }); Point2D x_min = points[0]; Point2D x_max = points[points.length - 1]; ArrayList<Point2D> upper = new ArrayList<Point2D>(); ArrayList<Point2D> lower = new ArrayList<Point2D>(); upper.add(x_min); /* Find the slope of the line L connecting x_min and x_max */ double mx = x_max.getX() - x_min.getX(); double my = x_max.getY() - x_min.getY(); double m = my / mx; /* Intersection of y-axis */ double b = x_max.getY() - (m * x_max.getX()); /* Add points above/below L to upper/lower, respectively */ for (int i = 1; i < points.length - 1; i++) { Point2D p2d = points[i]; double y = p2d.getX() * m + b; if (p2d.getY() >= y) upper.add(p2d); else lower.add(p2d); } /* Sort the lower list in descending order */ lower.add(x_max); Collections.reverse(lower); upper.addAll(lower); return upper.toArray(new Point2D[0]); }
From source file:CASUAL.communicationstools.heimdall.odin.Odin.java
public String[] getHeimdallFileParametersFromOdinFile(String tempFolder, File[] files) throws CorruptOdinFileException, FileNotFoundException { //Sorted set allows for only one instance of each file to exist SortedSet<File> set = new java.util.TreeSet<File>(); //decompress Odin files into regular files and track them for (File file : files) { OdinFile o;//from w w w. j a v a2s .co m try { o = new OdinFile(file); o.extractOdinContents(tempFolder); set.addAll(Arrays.asList(o.extractOdinContents(tempFolder))); } catch (IOException ex) { throw new FileNotFoundException(); } catch (NoSuchAlgorithmException ex) { throw new CorruptOdinFileException("This computer cannot handle the file"); } catch (CorruptOdinFileException ex) { throw new CorruptOdinFileException("The Archive is corrupt"); } catch (ArchiveException ex) { throw new CorruptOdinFileException("The Archive is corrupt"); } } //create list of --PARTITION filename for Heimdall ArrayList<String> list = new ArrayList<String>(); for (File f : set) { String partname = pit.findEntryByFilename(f.getName()).getPartitionName(); list.add("--" + partname); list.add(f.getAbsolutePath()); } //return that list. return list.toArray(new String[list.size()]); }
From source file:com.cloudera.sqoop.manager.DirectPostgreSQLExportManualTest.java
@Override protected String[] getArgv(boolean includeHadoopFlags, int rowsPerStatement, int statementsPerTx, String... additionalArgv) { ArrayList<String> args = new ArrayList<String>(Arrays.asList(additionalArgv)); args.add("--username"); args.add(getUserName());//from w w w . ja v a2 s . co m args.add("--direct"); return super.getArgv(includeHadoopFlags, rowsPerStatement, statementsPerTx, args.toArray(new String[0])); }
From source file:edu.ku.brc.ui.StringFormatHelper.java
public boolean createFormatter(final String formatStr, final boolean displayError) { String[] fmts = StringUtils.splitPreserveAllTokens(formatStr, '%'); if (fmts != null && fmts.length > 0) { ArrayList<String> fmtList = new ArrayList<String>(); for (String str : fmts) { if (StringUtils.isNotEmpty(str)) { fmtList.add("%" + str); }/*from ww w .j a v a 2 s .c o m*/ } formats = new String[fmtList.size()]; fmtList.toArray(formats); return true; } return false; }
From source file:es.pode.administracion.presentacion.noticias.noticias.NoticiasControllerImpl.java
public String[] devuelveArraySinIdiomasPrioritarios(String[] idiomas, ArrayList listaIdiomas) throws Exception { ArrayList listaAux = new ArrayList(); listaAux = devuelveArraySinString(idiomas, (String) listaIdiomas.get(0)); for (int i = 1; i < listaIdiomas.size(); i++) { listaAux = devuelveArraySinString((String[]) listaAux.toArray(new String[0]), (String) listaIdiomas.get(i)); }/*from w w w .ja v a 2 s . c o m*/ return (String[]) listaAux.toArray(new String[0]); }
From source file:org.opendatakit.database.queries.BindArgs.java
public BindArgs(String fromJSON) { if (fromJSON == null || fromJSON.isEmpty()) { bindArgs = new Object[0]; return;/*www . j a va2 s.c om*/ } TypeReference<ArrayList<Object>> type = new TypeReference<ArrayList<Object>>() { }; try { ArrayList<Object> values = ODKFileUtils.mapper.readValue(fromJSON, type); if (values == null) { bindArgs = new Object[0]; } else { bindArgs = values.toArray(new Object[values.size()]); } } catch (IOException ignored) { // not expected throw new IllegalStateException("Unable to deserialize bindArgs"); } }
From source file:CacheFilter.java
public void init(FilterConfig config) { Enumeration<?> names = config.getInitParameterNames(); ArrayList<String[]> tmp = new ArrayList<String[]>(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); String value = config.getInitParameter(name); String[] pair = { name, value }; tmp.add(pair);/*from w w w .ja va 2 s . c om*/ } replyHeaders = new String[tmp.size()][2]; tmp.toArray(replyHeaders); }