List of usage examples for java.util ArrayList addAll
public boolean addAll(Collection<? extends E> c)
From source file:org.gephi.ui.utils.ChartsUtils.java
/** * Build a new box-plot from an array of numbers using a default title and yLabel. * String dataName will be used for xLabel. * @param numbers Numbers for building box-plot * @param dataName Name of the numbers data * @return Prepared box-plot//from ww w . j a va 2s. co m */ public static JFreeChart buildBoxPlot(final Number[] numbers, final String dataName) { if (numbers == null || numbers.length == 0) { return null; } DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); final ArrayList<Number> list = new ArrayList<Number>(); list.addAll(Arrays.asList(numbers)); final String valuesString = getMessage("ChartsUtils.report.box-plot.values"); dataset.add(list, valuesString, ""); final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setMeanVisible(false); renderer.setFillBox(false); renderer.setMaximumBarWidth(0.5); final CategoryAxis xAxis = new CategoryAxis(dataName); final NumberAxis yAxis = new NumberAxis(getMessage("ChartsUtils.report.box-plot.values-range")); yAxis.setAutoRangeIncludesZero(false); renderer.setBaseToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); plot.setRenderer(renderer); JFreeChart boxPlot = new JFreeChart(getMessage("ChartsUtils.report.box-plot.title"), plot); return boxPlot; }
From source file:com.shopzilla.api.client.model.CatalogResponseModelAdapter.java
public static CatalogResponse fromCatalogAPI(ProductResponse result) { if (result == null) { return null; }//w w w. j a v a 2 s . c o m CatalogResponse toReturn = new CatalogResponse(); Classification classification = result.getClassification(); if (classification != null) { toReturn.setRelevancyScore(classification.getRelevancyScore()); } /* * attributes */ RelatedAttributes catalogAttributes = result.getRelatedAttributes(); if (catalogAttributes != null && CollectionUtils.isNotEmpty(catalogAttributes.getAttribute())) { ArrayList<Attribute> attributes = new ArrayList<Attribute>(catalogAttributes.getAttribute().size()); for (AttributeType a : catalogAttributes.getAttribute()) { Attribute attr = new Attribute(); attr.setId(a.getId()); attr.setLabel(a.getName()); AttributeValues catalogValues = a.getAttributeValues(); if (catalogValues != null && CollectionUtils.isNotEmpty(catalogValues.getAttributeValue())) { ArrayList<AttributeValue> values = new ArrayList<AttributeValue>( catalogValues.getAttributeValue().size()); for (AttributeValueType t : catalogValues.getAttributeValue()) { AttributeValue v = new AttributeValue(); v.setLabel(t.getId()); v.setValue(t.getName()); values.add(v); } attr.setValues(values); } attributes.add(attr); } toReturn.setRelatedAttributes(attributes); } /* * offers */ final ArrayList<Offer> offers = new ArrayList<Offer>(); if (result.getProducts() != null && CollectionUtils.isNotEmpty(result.getProducts().getProductOrOffer())) { toReturn.setTotalResults(result.getProducts().getTotalResults()); offers.addAll(convertOffers(result.getProducts().getProductOrOffer())); } if (result.getOffers() != null && CollectionUtils.isNotEmpty(result.getOffers().getOffer())) { toReturn.setTotalResults(result.getOffers().getTotalResults()); offers.addAll(convertOffers(result.getOffers().getOffer())); } toReturn.setOffers(offers); final ArrayList<Product> products = new ArrayList<Product>(); if (result.getProducts() != null && CollectionUtils.isNotEmpty(result.getProducts().getProductOrOffer())) { toReturn.setTotalResults(result.getProducts().getTotalResults()); products.addAll(convertProducts(result.getProducts().getProductOrOffer())); } toReturn.setProducts(products); return toReturn; }
From source file:es.uniovi.imovil.fcrtrainer.highscores.HighscoreManager.java
/** * Aade un array de puntuaciones. Est pensado para ser utilizado * inicialmente cuando se rellenan con las puntuaciones iniciales para ser * ms rpido que aadirlas una a una/* ww w . jav a 2 s. c o m*/ * * @param activity * @param highscores * @throws JSONException */ public static void addAllHighscores(Context context, ArrayList<Highscore> newHighscores) throws JSONException { ArrayList<Highscore> highscores = new ArrayList<Highscore>(); try { highscores = loadHighscores(context); } catch (JSONException e) { Log.d(TAG, "Error al leer las puntuaciones para aadir una nueva: " + e.getMessage()); } highscores.addAll(newHighscores); highscores = trim(highscores, MAX_NUMBER_HIGHSCORES); saveHighscores(context, highscores); }
From source file:de.helmholtz_muenchen.ibis.ngs.vcfmerger.VCFMerger.java
/** * Executes vcf-merge /* w w w.j av a 2s .co m*/ * @param Files2Merge * @param Outfolder * @param exec * @param logger */ private static String merge_vcfs(String GATK, String RefGenome, LinkedList<String> Files2Merge, String Outfolder, String GenotypeMergeOption, ExecutionContext exec, NodeLogger logger, String OUTFILETAG) { ArrayList<String> command = new ArrayList<String>(); String OUTFILE = Outfolder + "/AllSamples_vcfmerger" + OUTFILETAG + ".vcf"; String ERRFILE = Outfolder + "/AllSamples_vcfmerger" + OUTFILETAG + ".vcf.err"; command.add("java"); command.add("-jar " + GATK); command.add("-T CombineVariants"); command.add("-R " + RefGenome); command.addAll(Files2Merge); command.add("--genotypemergeoption " + GenotypeMergeOption); command.add("-o " + OUTFILE); try { Executor.executeCommand(new String[] { StringUtils.join(command, " ") }, exec, new String[] {}, logger, OUTFILE, ERRFILE); } catch (CanceledExecutionException | InterruptedException | ExecutionException | UnsuccessfulExecutionException e) { e.printStackTrace(); } return OUTFILE; }
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/* w w w . ja v a2 s . c o m*/ * @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:com.termmed.utils.ResourceUtils.java
/** * Gets the resources.// w ww. j av a2 s.co m * * @param pattern the pattern * @param packageName the package name * @return the resources */ public static Collection<String> getResources(final Pattern pattern, final String packageName) { final ArrayList<String> retval = new ArrayList<String>(); final String classPath = System.getProperty("java.class.path", packageName); final String[] classPathElements = classPath.split(System.getProperty("path.separator")); for (final String element : classPathElements) { retval.addAll(getResources(element, pattern)); } return retval; }
From source file:android.databinding.tool.util.XmlEditor.java
public static String strip(File f, String newTag) throws IOException { ANTLRInputStream inputStream = new ANTLRInputStream(new FileReader(f)); XMLLexer lexer = new XMLLexer(inputStream); CommonTokenStream tokenStream = new CommonTokenStream(lexer); XMLParser parser = new XMLParser(tokenStream); XMLParser.DocumentContext expr = parser.document(); XMLParser.ElementContext root = expr.element(); if (root == null || !"layout".equals(nodeName(root))) { return null; // not a binding layout }//from w ww. ja v a 2s .c om List<? extends ElementContext> childrenOfRoot = elements(root); List<? extends XMLParser.ElementContext> dataNodes = filterNodesByName("data", childrenOfRoot); if (dataNodes.size() > 1) { L.e("Multiple binding data tags in %s. Expecting a maximum of one.", f.getAbsolutePath()); } ArrayList<String> lines = new ArrayList<>(); lines.addAll(FileUtils.readLines(f, "utf-8")); for (android.databinding.parser.XMLParser.ElementContext it : dataNodes) { replace(lines, toPosition(it.getStart()), toEndPosition(it.getStop()), ""); } List<? extends XMLParser.ElementContext> layoutNodes = excludeNodesByName("data", childrenOfRoot); if (layoutNodes.size() != 1) { L.e("Only one layout element and one data element are allowed. %s has %d", f.getAbsolutePath(), layoutNodes.size()); } final XMLParser.ElementContext layoutNode = layoutNodes.get(0); ArrayList<Pair<String, android.databinding.parser.XMLParser.ElementContext>> noTag = new ArrayList<>(); recurseReplace(layoutNode, lines, noTag, newTag, 0); // Remove the <layout> Position rootStartTag = toPosition(root.getStart()); Position rootEndTag = toPosition(root.content().getStart()); replace(lines, rootStartTag, rootEndTag, ""); // Remove the </layout> ImmutablePair<Position, Position> endLayoutPositions = findTerminalPositions(root, lines); replace(lines, endLayoutPositions.left, endLayoutPositions.right, ""); StringBuilder rootAttributes = new StringBuilder(); for (AttributeContext attr : attributes(root)) { rootAttributes.append(' ').append(attr.getText()); } Pair<String, XMLParser.ElementContext> noTagRoot = null; for (Pair<String, XMLParser.ElementContext> pair : noTag) { if (pair.getRight() == layoutNode) { noTagRoot = pair; break; } } if (noTagRoot != null) { ImmutablePair<String, XMLParser.ElementContext> newRootTag = new ImmutablePair<>( noTagRoot.getLeft() + rootAttributes.toString(), layoutNode); int index = noTag.indexOf(noTagRoot); noTag.set(index, newRootTag); } else { ImmutablePair<String, XMLParser.ElementContext> newRootTag = new ImmutablePair<>( rootAttributes.toString(), layoutNode); noTag.add(newRootTag); } //noinspection NullableProblems Collections.sort(noTag, new Comparator<Pair<String, XMLParser.ElementContext>>() { @Override public int compare(Pair<String, XMLParser.ElementContext> o1, Pair<String, XMLParser.ElementContext> o2) { Position start1 = toPosition(o1.getRight().getStart()); Position start2 = toPosition(o2.getRight().getStart()); int lineCmp = Integer.compare(start2.line, start1.line); if (lineCmp != 0) { return lineCmp; } return Integer.compare(start2.charIndex, start1.charIndex); } }); for (Pair<String, android.databinding.parser.XMLParser.ElementContext> it : noTag) { XMLParser.ElementContext element = it.getRight(); String tag = it.getLeft(); Position endTagPosition = endTagPosition(element); fixPosition(lines, endTagPosition); String line = lines.get(endTagPosition.line); String newLine = line.substring(0, endTagPosition.charIndex) + " " + tag + line.substring(endTagPosition.charIndex); lines.set(endTagPosition.line, newLine); } return StringUtils.join(lines, System.getProperty("line.separator")); }
From source file:eu.scape_project.pt.mapred.input.ControlFileInputFormat.java
/** * Recursively collects paths in a directory. * * @param fs Hadoop filesystem handle//from www . jav a 2 s. com * @param path path, a directory * @return list of paths */ private static List<Path> getFilesInDir(FileSystem fs, Path path) throws FileNotFoundException, IOException { ArrayList<Path> inFiles = new ArrayList<Path>(); for (FileStatus s : fs.listStatus(path)) { if (s.isDirectory()) { inFiles.addAll(getFilesInDir(fs, s.getPath())); } else { inFiles.add(s.getPath()); } } return inFiles; }
From source file:de.schaeuffelhut.android.openvpn.Preferences.java
public final static ArrayList<File> configs(File configDir) { ArrayList<File> configFiles = new ArrayList<File>(); if (configDir != null) { ArrayList<File> configDirs = new ArrayList<File>(); configDirs.add(configDir);/*w ww . j av a 2s .c o m*/ configDirs.addAll(Arrays.asList(Util.listFiles(configDir, new Util.IsDirectoryFilter()))); for (File dir : configDirs) configFiles .addAll(Arrays.asList(Util.listFiles(dir, new Util.FileExtensionFilter(".conf", ".ovpn")))); } return configFiles; }
From source file:com.yamin.kk.vlc.Util.java
public static String[] getMediaDirectories() { ArrayList<String> list = new ArrayList<String>(); list.addAll(Arrays.asList(Util.getStorageDirectories())); list.addAll(Arrays.asList(Util.getCustomDirectories())); return list.toArray(new String[list.size()]); }