List of usage examples for java.util Collections addAll
@SafeVarargs public static <T> boolean addAll(Collection<? super T> c, T... elements)
From source file:de.cismet.lagis.cidsmigtest.CustomBeanToStringTester.java
/** * DOCUMENT ME!//w w w . j a va 2 s.c om * * @param object DOCUMENT ME! * * @return DOCUMENT ME! */ public static String getStringOf(final MetaObject[] object) { final StringBuilder sb = new StringBuilder("\n" + tab() + "[Collection |"); if (object != null) { final List<MetaObject> sortedList = new ArrayList<MetaObject>(); Collections.addAll(sortedList, object); Collections.sort(sortedList, new Comparator<MetaObject>() { @Override public int compare(final MetaObject o1, final MetaObject o2) { return o1.getId() - o2.getId(); } }); for (final MetaObject item : sortedList) { sb.append(getStringOf(item.getBean())).append("\n"); } } sb.append("\n").append(untab()).append("]"); return sb.toString(); }
From source file:com.unboundid.scim2.common.filters.Filter.java
/** * Create a new {@code and} filter./* ww w.j ava 2 s. c om*/ * * @param filter1 The first filter. * @param filter2 The second filter. * @param filters Additional filter components. * @return A new {@code and} filter. */ public static Filter and(final Filter filter1, final Filter filter2, final Filter... filters) { ArrayList<Filter> components = new ArrayList<Filter>(filters != null ? 2 + filters.length : 2); components.add(filter1); components.add(filter2); if (filters != null) { Collections.addAll(components, filters); } return new AndFilter(components); }
From source file:com.google.example.eightbitartist.DrawingActivity.java
/** * Pick a random set of words from the master word list. * @param numWords the number of words to choose. * @return a list of randomly chosen words. *///w w w . ja v a 2 s .com private List<String> getRandomWordSubset(int numWords) { List<String> result = new ArrayList<>(); Collections.addAll(result, mAllWords); Collections.shuffle(result); result = result.subList(0, numWords); return result; }
From source file:com.unboundid.scim2.common.filters.Filter.java
/** * Create a new {@code or} filter./*from w w w . java2 s . c om*/ * * @param filter1 The first filter. * @param filter2 The second filter. * @param filters Additional filter components. * @return A new {@code or} filter. */ public static Filter or(final Filter filter1, final Filter filter2, final Filter... filters) { ArrayList<Filter> components = new ArrayList<Filter>(filters != null ? 2 + filters.length : 2); components.add(filter1); components.add(filter2); if (filters != null) { Collections.addAll(components, filters); } return new OrFilter(components); }
From source file:org.apache.solr.handler.IndexFetcher.java
private StringBuilder readToStringBuilder(long replicationTime, String str) { StringBuilder sb = new StringBuilder(); List<String> l = new ArrayList<>(); if (str != null && str.length() != 0) { String[] ss = str.split(","); Collections.addAll(l, ss); }//from w w w .j a va 2s.c o m sb.append(replicationTime); if (!l.isEmpty()) { for (int i = 0; i < l.size() || i < 9; i++) { if (i == l.size() || i == 9) break; String s = l.get(i); sb.append(",").append(s); } } return sb; }
From source file:edu.kit.dama.staging.util.DataOrganizationUtils.java
/** * Merge pNodeList into pNode. All nodes in pNodeList are placed under the * path provided by pPath./* ww w . j ava2 s. c om*/ * * @param pNode The node to which the merge should be applied. * @param pPath The path of pTheNode under pNode. * @param pTheNodeList The list of nodes which are finally added. */ public static void merge(ICollectionNode pNode, List<ICollectionNode> pPath, final IDataOrganizationNode... pTheNodeList) { List<ICollectionNode> newParents = new ArrayList<>(); ICollectionNode currentNode = pNode; for (ICollectionNode node : pPath) {//check all parents and create them if needed boolean needCreation = true; for (IDataOrganizationNode child : currentNode.getChildren()) {//check all current children for beeing parents if (child instanceof ICollectionNode && child.getName().equals(node.getName())) {//parent found, don't create needCreation = false; //set new parent currentNode = (ICollectionNode) child; newParents.add(currentNode); break; } } if (needCreation) {//parent does not exist, create it ICollectionNode newNode = new CollectionNodeImpl(); newNode.setName(node.getName()); newParents.add(newNode); currentNode.addChild(newNode); //set new parent currentNode = newNode; } } //put new parents into list to expand them later pPath.clear(); Collections.addAll(pPath, newParents.toArray(new ICollectionNode[newParents.size()])); //try to add the new node and overwrite an existing node if needed for (IDataOrganizationNode node : pTheNodeList) { addNode(currentNode, node); } }
From source file:edu.ku.brc.specify.utilapps.sp5utils.Sp5Forms.java
/** * /* ww w . jav a 2s .c o m*/ */ private void createIndex() { String dirName = "conversions" + File.separator + namePair.second + "_6" + File.separator + "forms"; String fName = dirName + File.separator + "index.html"; try { File dir = new File(dirName); PrintWriter pw = new PrintWriter(new File(fName)); pw.println("<html><body><h2>Forms For " + namePair.second + "</h2><table border='0'>"); Vector<String> fileList = new Vector<String>(); Collections.addAll(fileList, dir.list()); Collections.sort(fileList); for (String fileName : fileList) { if (fileName.endsWith("png")) { String name = FilenameUtils.getBaseName(fileName); pw.print("<tr><td>"); pw.print("<a href='"); pw.print(fileName); pw.print("'>"); pw.print(name); pw.println("</a></td></tr>"); } } pw.println("</body></html>"); pw.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.google.gwt.dev.shell.CompilingClassLoader.java
public CompilingClassLoader(TreeLogger logger, CompilationState compilationState, ShellJavaScriptHost javaScriptHost) throws UnableToCompleteException { super(null);/*from ww w . j a v a 2 s .co m*/ this.logger = logger; this.compilationState = compilationState; this.shellJavaScriptHost = javaScriptHost; this.typeOracle = compilationState.getTypeOracle(); // Assertions are always on in hosted mode. setDefaultAssertionStatus(true); ensureJavaScriptHostBytes(logger); // Create a class rewriter based on all the subtypes of the JSO class. JClassType jsoType = typeOracle.findType(JsValueGlue.JSO_CLASS); if (jsoType != null) { // Create a set of binary names. Set<JClassType> jsoTypes = new HashSet<JClassType>(); JClassType[] jsoSubtypes = jsoType.getSubtypes(); Collections.addAll(jsoTypes, jsoSubtypes); jsoTypes.add(jsoType); Set<String> jsoTypeNames = new HashSet<String>(); Map<String, List<String>> jsoSuperTypes = new HashMap<String, List<String>>(); for (JClassType type : jsoTypes) { List<String> types = new ArrayList<String>(); types.add(getBinaryName(type.getSuperclass())); for (JClassType impl : type.getImplementedInterfaces()) { types.add(getBinaryName(impl)); } String binaryName = getBinaryName(type); jsoTypeNames.add(binaryName); jsoSuperTypes.put(binaryName, types); } SingleJsoImplData singleJsoImplData = new MySingleJsoImplData(); MyInstanceMethodOracle mapper = new MyInstanceMethodOracle(jsoTypes, typeOracle.getJavaLangObject(), singleJsoImplData); classRewriter = new HostedModeClassRewriter(jsoTypeNames, jsoSuperTypes, singleJsoImplData, mapper); } else { // If we couldn't find the JSO class, we don't need to do any rewrites. classRewriter = null; } }
From source file:com.facebook.infrastructure.service.StorageService.java
public void forceHandoff(String directories, String host) throws IOException { List<File> filesList = new ArrayList<File>(); String[] sources = directories.split(":"); for (String source : sources) { File directory = new File(source); Collections.addAll(filesList, directory.listFiles()); }/* ww w .ja va 2s . c o m*/ File[] files = filesList.toArray(new File[0]); StreamContextManager.StreamContext[] streamContexts = new StreamContextManager.StreamContext[files.length]; int i = 0; for (File file : files) { streamContexts[i] = new StreamContextManager.StreamContext(file.getAbsolutePath(), file.length()); logger_.debug("Stream context metadata " + streamContexts[i]); ++i; } if (files.length > 0) { EndPoint target = new EndPoint(host, DatabaseDescriptor.getStoragePort()); /* Set up the stream manager with the files that need to streamed */ StreamManager.instance(target).addFilesToStream(streamContexts); /* Send the bootstrap initiate message */ BootstrapInitiateMessage biMessage = new BootstrapInitiateMessage(streamContexts); Message message = BootstrapInitiateMessage.makeBootstrapInitiateMessage(biMessage); logger_.debug("Sending a bootstrap initiate message to " + target + " ..."); MessagingService.getMessagingInstance().sendOneWay(message, target); logger_.debug("Waiting for transfer to " + target + " to complete"); StreamManager.instance(target).waitForStreamCompletion(); logger_.debug("Done with transfer to " + target); } }
From source file:com.izforge.izpack.compiler.CompilerConfig.java
private void processFileChildren(File baseDir, IXMLElement packElement, PackInfo pack) throws CompilerException { for (IXMLElement fileNode : packElement.getChildrenNamed("file")) { String src = xmlCompilerHelper.requireAttribute(fileNode, "src"); boolean unpack = Boolean.parseBoolean(fileNode.getAttribute("unpack")); TargetFileSet fs = new TargetFileSet(); try {/*from w ww . jav a 2 s. co m*/ File relsrcfile = new File(src); File abssrcfile = FileUtil.getAbsoluteFile(src, compilerData.getBasedir()); if (!abssrcfile.exists()) { throw new FileNotFoundException("Source file " + relsrcfile + " not found"); } if (relsrcfile.isDirectory()) { fs.setDir(abssrcfile.getParentFile()); fs.createInclude().setName(relsrcfile.getName() + "/**"); } else { fs.setFile(abssrcfile); } fs.setTargetDir(xmlCompilerHelper.requireAttribute(fileNode, "targetdir")); List<OsModel> osList = OsConstraintHelper.getOsList(fileNode); // TODO: unverified fs.setOsList(osList); fs.setOverride(getOverrideValue(fileNode)); fs.setOverrideRenameTo(getOverrideRenameToValue(fileNode)); fs.setBlockable(getBlockableValue(fileNode, osList)); fs.setAdditionals(getAdditionals(fileNode)); fs.setCondition(fileNode.getAttribute("condition")); String boolval = fileNode.getAttribute("casesensitive"); if (boolval != null) { fs.setCaseSensitive(Boolean.parseBoolean(boolval)); } boolval = fileNode.getAttribute("defaultexcludes"); if (boolval != null) { fs.setDefaultexcludes(Boolean.parseBoolean(boolval)); } boolval = fileNode.getAttribute("followsymlinks"); if (boolval != null) { fs.setFollowSymlinks(Boolean.parseBoolean(boolval)); } LinkedList<String> srcfiles = new LinkedList<String>(); Collections.addAll(srcfiles, fs.getDirectoryScanner().getIncludedDirectories()); Collections.addAll(srcfiles, fs.getDirectoryScanner().getIncludedFiles()); for (String filePath : srcfiles) { if (!filePath.isEmpty()) { abssrcfile = new File(fs.getDir(), filePath); if (unpack) { logger.info("Adding content from archive: " + abssrcfile); addArchiveContent(baseDir, abssrcfile, fs.getTargetDir(), fs.getOsList(), fs.getOverride(), fs.getOverrideRenameTo(), fs.getBlockable(), pack, fs.getAdditionals(), fs.getCondition()); } else { String target = fs.getTargetDir() + "/" + filePath; logger.info("Adding file: " + abssrcfile + ", as target file=" + target); pack.addFile(baseDir, abssrcfile, target, fs.getOsList(), fs.getOverride(), fs.getOverrideRenameTo(), fs.getBlockable(), fs.getAdditionals(), fs.getCondition()); } } } } catch (Exception e) { throw new CompilerException(e.getMessage(), e); } } }