List of usage examples for com.google.common.collect Iterables addAll
public static <T> boolean addAll(Collection<T> addTo, Iterable<? extends T> elementsToAdd)
From source file:com.zimbra.soap.admin.message.AdminWaitSetResponse.java
public void setSignalledAccounts(Iterable<Id> signalledAccounts) { this.signalledAccounts.clear(); if (signalledAccounts != null) { Iterables.addAll(this.signalledAccounts, signalledAccounts); }// ww w. ja va 2 s . c o m }
From source file:org.terasology.workstation.system.ProcessPartWorkstationProcess.java
ProcessPartWorkstationProcess(Prefab prefab) throws InvalidProcessPartException { id = "Prefab:" + prefab.getURI().toSimpleString(); ProcessDefinitionComponent processDefinitionComponent = prefab .getComponent(ProcessDefinitionComponent.class); processType = processDefinitionComponent.processType; List<ProcessPart> allProcessParts = Lists .newArrayList(Iterables.filter(prefab.iterateComponents(), ProcessPart.class)); // get any process parts from the process type prefab Prefab processTypePrefab = Assets.getPrefab(processType); if (processTypePrefab != null) { Iterables.addAll(allProcessParts, Iterables.filter(processTypePrefab.iterateComponents(), ProcessPart.class)); }//from ww w .java 2s . co m // order the process parts Collections.sort(allProcessParts, new Comparator<ProcessPart>() { @Override public int compare(ProcessPart o1, ProcessPart o2) { int order1 = 0; int order2 = 0; if (o1 instanceof ProcessPartOrdering) { order1 = ((ProcessPartOrdering) o1).getSortOrder(); } if (o2 instanceof ProcessPartOrdering) { order2 = ((ProcessPartOrdering) o2).getSortOrder(); } return Integer.compare(order1, order2); } }); // only add process parts that pass error checking for (ProcessPart component : allProcessParts) { if (component instanceof ErrorCheckingProcessPart) { ErrorCheckingProcessPart errorChecking = (ErrorCheckingProcessPart) component; errorChecking.checkForErrors(); } processParts.add(component); } }
From source file:com.zimbra.soap.admin.type.BackupQueryAccounts.java
public void setAccounts(Iterable<BackupQueryAccountStatus> accounts) { this.accounts.clear(); if (accounts != null) { Iterables.addAll(this.accounts, accounts); }/*from ww w . j ava2 s. co m*/ }
From source file:com.zimbra.soap.mail.message.GetMiniCalRequest.java
public void setFolders(Iterable<Id> folders) { this.folders.clear(); if (folders != null) { Iterables.addAll(this.folders, folders); }/* ww w . ja v a2 s .c o m*/ }
From source file:org.jclouds.virtualbox.functions.RetrieveActiveBridgedInterfaces.java
@Override public List<BridgedIf> apply(NodeMetadata host) { // Bridged Network Statement command = Statements.exec("VBoxManage list bridgedifs"); String bridgedIfBlocks = runScriptOnNodeFactory .create(host, command, runAsRoot(false).wrapInInitScript(false)).init().call().getOutput(); List<BridgedIf> bridgedInterfaces = retrieveBridgedInterfaceNames(bridgedIfBlocks); checkNotNull(bridgedInterfaces);/*from w w w . ja v a 2 s . c o m*/ // union of bridgedNetwork with inet up and !loopback List<BridgedIf> activeNetworkInterfaces = Lists.newArrayList(); try { Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces(); for (NetworkInterface inet : Collections.list(nets)) { Iterable<BridgedIf> filteredBridgedInterface = filter(bridgedInterfaces, new IsActiveBridgedInterface(inet)); Iterables.addAll(activeNetworkInterfaces, filteredBridgedInterface); } } catch (SocketException e) { logger.error(e, "Problem in listing network interfaces."); throw Throwables.propagate(e); } return activeNetworkInterfaces; }
From source file:org.apache.streams.data.util.PropertyUtil.java
public static ObjectNode unflattenObjectNode(ObjectNode flatObject, char seperator) { ObjectNode root = mapper.createObjectNode(); Iterator<Map.Entry<String, JsonNode>> iter = flatObject.fields(); while (iter.hasNext()) { Map.Entry<String, JsonNode> item = iter.next(); String fullKey = item.getKey(); if (!fullKey.contains(Character.valueOf(seperator).toString())) { root.put(item.getKey(), item.getValue()); } else {//from ww w .j a v a 2 s .co m ObjectNode currentNode = root; List<String> keyParts = new ArrayList<>(); Iterables.addAll(keyParts, Splitter.on(seperator).split(item.getKey())); for (String part : Iterables.limit(Splitter.on(seperator).split(item.getKey()), keyParts.size() - 1)) { if (currentNode.has(part) && currentNode.get(part).isObject()) { currentNode = (ObjectNode) currentNode.get(part); } else { ObjectNode newNode = mapper.createObjectNode(); currentNode.put(part, newNode); currentNode = newNode; } } currentNode.put(keyParts.get(keyParts.size() - 1), item.getValue()); } } return root; }
From source file:org.atteo.moonshine.directories.DefaultFileAccessor.java
@Override public FileAccessor getFileAccessor() throws IOException { final Path configHome; final Path dataHome; final Path cacheHome; final Path logHome; final List<Path> configDirs = new ArrayList<>(); final List<Path> dataDirs = new ArrayList<>(); WriteableDirectoryLayout layout = writeableLayout; if (parameters.getHomeDirectory() != null) { layout = new SubdirectoryLayout(Paths.get(parameters.getHomeDirectory())); }/*from w w w. ja va 2 s . co m*/ if (layout == null) { layout = new SubdirectoryLayout((Paths.get(""))); } if (parameters.getConfigHome() != null) { configHome = Paths.get(parameters.getConfigHome()); } else { configHome = layout.getConfigHome(); } if (parameters.getDataHome() != null) { dataHome = Paths.get(parameters.getDataHome()); } else { dataHome = layout.getDataHome(); } if (parameters.getCacheHome() != null) { cacheHome = Paths.get(parameters.getCacheHome()); } else { cacheHome = layout.getCacheHome(); } if (parameters.getLogHome() != null) { logHome = Paths.get(parameters.getLogHome()); } else { logHome = layout.getLogHome(); } Iterables.addAll(configDirs, layout.getConfigDirs()); Iterables.addAll(dataDirs, layout.getDataDirs()); Iterables.addAll(configDirs, extraConfigDirs); Iterables.addAll(dataDirs, extraDataDirs); for (ReadOnlyDirectoryLayout readOnlyLayout : readOnlyLayouts) { Iterables.addAll(configDirs, readOnlyLayout.getConfigDirs()); Iterables.addAll(dataDirs, readOnlyLayout.getDataDirs()); } Files.createDirectories(configHome); Files.createDirectories(dataHome); Files.createDirectories(cacheHome); Files.createDirectories(logHome); return new FileAccessor() { private Path getFile(Path home, Iterable<Path> dirs, String fileName) { Path filePath = home.resolve(fileName); if (Files.exists(filePath)) { return filePath; } for (Path path : dirs) { filePath = path.resolve(fileName); if (Files.exists(filePath)) { return filePath; } } return null; } private Iterable<Path> getFiles(Path home, Iterable<Path> dirs, String fileName) { List<Path> files = new ArrayList<>(); Path filePath = home.resolve(fileName); if (Files.exists(filePath)) { files.add(filePath); } for (Path path : dirs) { filePath = path.resolve(fileName); if (Files.exists(filePath)) { files.add(filePath); } } return files; } @Override public Path getConfigFile(String fileName) { return getFile(configHome, configDirs, fileName); } @Override public Iterable<Path> getConfigFiles(String fileName) { return getFiles(configHome, configDirs, fileName); } @Override public Path getWritableConfigFile(String fileName) { return configHome.resolve(fileName); } @Override public Path getDataFile(String fileName) { return getFile(dataHome, dataDirs, fileName); } @Override public Iterable<Path> getDataFiles(String fileName) { return getFiles(configHome, configDirs, fileName); } @Override public Path getWriteableDataFile(String fileName) { return dataHome.resolve(fileName); } @Override public Path getWriteableCacheFile(String fileName) { return cacheHome.resolve(fileName); } @Override public Path getWriteableLogfile(String fileName) { return logHome.resolve(fileName); } @Override public Properties getProperties() { Properties properties = new Properties(); properties.setProperty("configHome", configHome.toAbsolutePath().toString()); properties.setProperty("dataHome", dataHome.toAbsolutePath().toString()); properties.setProperty("cacheHome", cacheHome.toAbsolutePath().toString()); properties.setProperty("logHome", logHome.toAbsolutePath().toString()); return properties; } }; }
From source file:com.google.devtools.build.lib.rules.java.JavaLibraryHelper.java
/** * Adds the given source jars. Any .java files in these jars will be compiled. *//*from w ww . j a v a2 s. c o m*/ public JavaLibraryHelper addSourceJars(Iterable<Artifact> sourceJars) { Iterables.addAll(this.sourceJars, sourceJars); return this; }
From source file:org.openengsb.connector.userprojects.jira.internal.jira.async.OesbAsynchronousUserRestClient.java
@SuppressWarnings("unchecked") public Promise<Iterable<User>> getAssignableUsers(Iterable<BasicProject> projects) { List<BasicProject> validProjects = new ArrayList<>(); if (projects != null) { for (BasicProject project : projects) { if (project == null) { continue; }// w ww .j a va 2 s .co m if (StringUtils.isNotBlank(project.getKey())) { validProjects.add(project); } } } Set<User> allAssignableUsers = new HashSet<>(); for (BasicProject project : validProjects) { Promise<Iterable<User>> userPromise = getAssignableUsers(project); Iterable<User> users = null; try { users = userPromise.claim(); } catch (Exception e) { // statuscode 401: missing user or wrong pass. 403: forbidden (e.g.captcha required) LOG.info("No access to project with key {}.", project.getKey()); } if (users != null) { Iterables.addAll(allAssignableUsers, users); } } return Promises.promise(Iterables.concat(allAssignableUsers)); }
From source file:com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder.java
/** * Adds a sequence of direct members to the set to be built. Equivalent to invoking {@link #add} * for each item in {@code elements}, in order. * * <p>The relative left-to-right order of direct members is preserved from the sequence of calls * to {@link #add} and {@link #addAll}. Since the traversal {@link Order} controls whether direct * members appear before or after transitive ones, the interleaving of * {@link #add}/{@link #addAll} with {@link #addTransitive} does not matter. * * @param elements the sequence of items to add; must not be null * @return the builder//from w ww. j a va 2 s . com */ public NestedSetBuilder<E> addAll(Iterable<? extends E> elements) { Preconditions.checkNotNull(elements); Iterables.addAll(items, elements); return this; }