List of usage examples for java.util ArrayList toArray
@SuppressWarnings("unchecked") public <T> T[] toArray(T[] a)
From source file:annis.CSVHelper.java
public static SortedMap<Integer, SortedSet<String>> exportCSVHeader(Iterator<AnnotatedMatch> matches, PrintWriter w) {// www .j a va2s. c om // figure out what annotations are used at each match position SortedMap<Integer, SortedSet<String>> columnsByNodePos = new TreeMap<>(); while (matches.hasNext()) { AnnotatedMatch match = matches.next(); for (int j = 0; j < match.size(); ++j) { AnnotatedSpan span = match.get(j); if (columnsByNodePos.get(j) == null) { columnsByNodePos.put(j, new TreeSet<String>()); } for (Annotation annotation : span.getAnnotations()) { columnsByNodePos.get(j).add("anno_" + annotation.getQualifiedName()); } for (Annotation meta : span.getMetadata()) { columnsByNodePos.get(j).add("meta_" + meta.getQualifiedName()); } } } CSVWriter csvWriter = new CSVWriter(w, '\t', CSVWriter.NO_QUOTE_CHARACTER, '\\'); // print column names and data types int count = columnsByNodePos.keySet().size(); ArrayList<String> headerLine = new ArrayList<>(); for (int j = 0; j < count; ++j) { headerLine.add(fullColumnName(j + 1, "id")); headerLine.add(fullColumnName(j + 1, "span")); SortedSet<String> annotationNames = columnsByNodePos.get(j); for (String name : annotationNames) { headerLine.add(fullColumnName(j + 1, name)); } } csvWriter.writeNext(headerLine.toArray(new String[headerLine.size()])); return columnsByNodePos; }
From source file:com.galenframework.speclang2.reader.pagespec.ForLoop.java
private static Object[] readSequenceForSimpleLoop(String sequenceStatement) { sequenceStatement = sequenceStatement.replace(" ", ""); sequenceStatement = sequenceStatement.replace("\t", ""); Pattern sequencePattern = Pattern.compile(".*\\-.*"); try {//from w w w . j av a2 s .c o m 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[] {}); } catch (Exception ex) { throw new SyntaxException(UNKNOWN_LINE, "Incorrect sequence syntax: " + sequenceStatement, ex); } }
From source file:net.drgnome.virtualpack.util.Util.java
public static <T extends Cloneable> T[] copy(T... objects) { ArrayList<T> list = new ArrayList<T>(); for (T obj : objects) { list.add(copy(obj));// w w w . j a v a 2s . c o m } return list.toArray(createGenericArray((Class<T>) objects.getClass().getComponentType())); }
From source file:Main.java
/** * gets a tokenizer and returns an arraylist with the separated elements of the tokenizer * /*from w w w . j av a 2s . c o m*/ * @param strt the tokenizer * @param hasToTrim if has to trim every single element of the tokenizer * @return the AL with the elements */ public static String[] getStringArrayFromString(String strValues, String strSeparator, boolean hasToTrim) { // if null if (strValues == null) return new String[0]; // creates the AL ArrayList<String> al = new ArrayList<String>(); StringTokenizer strt = new StringTokenizer(strValues, strSeparator); while (strt.hasMoreElements()) { // gets the next element String strElement = (String) strt.nextElement(); // if is to be trimmed, it does it if (hasToTrim) strElement = strElement.trim(); // and adds it to the AL al.add(strElement); } String[] strArray = new String[al.size()]; // returns the AL return al.toArray(strArray); }
From source file:com.ricemap.spateDB.core.SpatialSite.java
public static GlobalIndex<Partition> getGlobalIndex(FileSystem fs, Path dir) throws IOException { // Retrieve the master file (the only file with the name _master in it) FileStatus[] masterFiles = fs.listStatus(dir, new PathFilter() { @Override//w w w .jav a2s . c o m public boolean accept(Path path) { return path.getName().contains("_master"); } }); // Check if the given file is indexed if (masterFiles.length == 0) return null; if (masterFiles.length > 1) throw new RuntimeException("Found more than one master file in " + dir); Path masterFile = masterFiles[0].getPath(); ShapeRecordReader<Partition> reader = new ShapeRecordReader<Partition>(fs.open(masterFile), 0, fs.getFileStatus(masterFile).getLen()); CellInfo dummy = new CellInfo(); Partition partition = new Partition(); ArrayList<Partition> partitions = new ArrayList<Partition>(); while (reader.next(dummy, partition)) { partitions.add(partition.clone()); } GlobalIndex<Partition> globalIndex = new GlobalIndex<Partition>(); globalIndex.bulkLoad(partitions.toArray(new Partition[partitions.size()])); globalIndex.setCompact(masterFile.getName().endsWith("rtree") || masterFile.getName().endsWith("r+tree")); globalIndex.setReplicated(masterFile.getName().endsWith("r+tree") || masterFile.getName().endsWith("grid")); return globalIndex; }
From source file:com.mycsense.carbondb.domain.SourceRelation.java
public static String getHashKey(Dimension dimension, Dimension commonKeywords, Integer alpha) { if (alpha == 0) { return "#emptyHashKey#"; }/* w w w. j a va 2 s . c om*/ ArrayList<String> keywordInKey = new ArrayList<>(); for (Keyword keyword : dimension.keywords) { if (commonKeywords.contains(keyword)) { keywordInKey.add(keyword.toString()); } } if (keywordInKey.size() != alpha) { return "#nullHashKey#"; } Collections.sort(keywordInKey); return implode(",", keywordInKey.toArray(new String[keywordInKey.size()])); }
From source file:UtilFunctions.java
public static String[] parseFileTypes(String inputString) { //ArrayList to store each parsed filetype ArrayList<String> fileTypes = new ArrayList<>(); //Scanner to iterate over the string filetype by filetype Scanner in = new Scanner(inputString); in.useDelimiter("[,] | [, ]"); //Iterate over the string while (in.hasNext()) { fileTypes.add(in.next());//from w ww .j a va2s. com } if (fileTypes.size() > 0) { //Generate an array from the ArrayList String[] returnArray = new String[fileTypes.size()]; returnArray = fileTypes.toArray(returnArray); //Return that magnificent array return returnArray; } else { return null; } }
From source file:lineage.LineageEngine.java
/** * The main pipeline for reconstructing the cell lineage trees *///from www. j a v a2s .c om public static void buildLineage(Args args) { // 1. load SNV data SNVDataStore db = new SNVDataStore(args.inputFileName, args.clustersFileName, args.normalSampleId); // 2. get the SNVs partitioned by group tag and create the appropriate SNV group objects HashMap<String, ArrayList<SNVEntry>> snvsByTag = db.getSomaticGroups(); ArrayList<SNVGroup> groups = new ArrayList<SNVGroup>(); for (String groupTag : snvsByTag.keySet()) { groups.add(new SNVGroup(groupTag, snvsByTag.get(groupTag), db.isRobustGroup(groupTag))); } if (groups.size() == 0) { logger.warning("All SNV groups have been filtered out."); return; } // 3. cluster SNVs in each group AAFClusterer clusterer = new AAFClusterer(); for (SNVGroup group : groups) { if (args.clustersFileName == null) { Cluster[] clusters = clusterer.clusterSubPopulations(group, ClusteringAlgorithms.EM, 1); logger.fine("Clustering results for group: " + group.getTag()); for (Cluster c : clusters) { logger.fine(c.toString()); } group.setSubPopulations(clusters); } else { ArrayList<Cluster> groupClusters = db.getClusters().get(group.getTag()); group.subPopulations = new Cluster[groupClusters.size()]; group.subPopulations = groupClusters.toArray(group.subPopulations); } } // 4. construct the constraint network PHYNetwork constrNetwork = new PHYNetwork(groups, db.getNumSamples()); logger.fine(constrNetwork.toString()); // 5. find all the lineage trees that pass the VAF constraints ArrayList<PHYTree> spanningTrees = constrNetwork.getLineageTrees(); logger.info("Found " + spanningTrees.size() + " valid tree(s)"); if (spanningTrees.size() == 0) { logger.info("Adjusting the network..."); // if no valid trees were found, fix the network // remove group nodes that are not robust, complete edges int delta = 0; do { int numNodes = constrNetwork.numNodes; constrNetwork = constrNetwork.fixNetwork(); spanningTrees = constrNetwork.getLineageTrees(); delta = numNodes - constrNetwork.numNodes; } while ((delta != 0) && (spanningTrees.size() <= 0)); if (spanningTrees.size() <= 0) { Parameters.ALL_EDGES = true; constrNetwork = new PHYNetwork(groups, db.getNumSamples()); spanningTrees = constrNetwork.getLineageTrees(); } logger.info("Found " + spanningTrees.size() + " valid trees after network adjustments"); } // 6. evaluate/rank the trees if (spanningTrees.size() > 0) { constrNetwork.evaluateLineageTrees(); logger.fine("Top tree\nError score: " + spanningTrees.get(0).getErrorScore()); logger.fine(spanningTrees.get(0).toString()); } // 7. result visualization if (args.showNetwork) { constrNetwork.displayNetwork(); } if (spanningTrees.size() > 0) { for (int i = 0; i < args.numShow; i++) { if (spanningTrees.size() > i) { constrNetwork.displayTree(spanningTrees.get(i), db.getSampleNames(), null, null); } else { break; } } // 8. persistent storage if (args.numSave > 0) { writeTreesToTxtFile(constrNetwork, spanningTrees, db.getSampleNames(), args); } } }
From source file:Main.java
public static String[] split(String s, String sep) { if (s == null) { return null; }//from www . j a v a2 s.c om ArrayList<String> list = new ArrayList<String>(); while (s.length() != 0) { int pos = s.indexOf(sep); if (pos >= 0) { list.add(s.substring(0, pos)); s = s.substring(pos + sep.length(), s.length()); if (s.length() == 0) { list.add(""); // letztes (leeres) Element hinter letztem Trennzeichen } } else if (s.length() > 0) { list.add(s); s = ""; } } return list.toArray(new String[0]); }
From source file:com.amalto.workbench.compare.Utilities.java
public static IFile[] getFiles(ISelection selection) { ArrayList tmp = internalGetResources(selection, IFile.class); return (IFile[]) tmp.toArray(new IFile[tmp.size()]); }