List of usage examples for java.util Collections addAll
@SafeVarargs public static <T> boolean addAll(Collection<? super T> c, T... elements)
From source file:com.thinkbiganalytics.security.rest.controller.AccessControlController.java
private Set<Principal> collectPrincipals(PermissionsChange changes) { Set<Principal> set = new HashSet<>(); Collections.addAll(set, this.actionsTransform.asUserPrincipals(changes.getUsers())); Collections.addAll(set, this.actionsTransform.asGroupPrincipals(changes.getGroups())); return set;//from w w w . j a v a2s . com }
From source file:jenkins.plugins.ivyreport.IvyAccess.java
String[] expandConfs(String[] requested) { if (moduleDescriptor == null) { recomputeModuleDescriptor();/*from ww w . jav a2 s. com*/ if (moduleDescriptor == null) { return requested; } } String[] expanded = ConfigurationUtils.replaceWildcards(requested, moduleDescriptor); LinkedHashSet<String> result = new LinkedHashSet<String>(); Collections.addAll(result, expanded); result.retainAll(Arrays.asList(moduleDescriptor.getConfigurationsNames())); return result.toArray(new String[result.size()]); }
From source file:org.elasticsearch.client.RestClientMultipleHostsTests.java
public void testRoundRobinRetryErrors() throws IOException { String retryEndpoint = randomErrorRetryEndpoint(); try {//from ww w .j a va 2 s.com restClient.performRequest(randomHttpMethod(getRandom()), retryEndpoint); fail("request should have failed"); } catch (ResponseException e) { Set<HttpHost> hostsSet = new HashSet<>(); Collections.addAll(hostsSet, httpHosts); //first request causes all the hosts to be blacklisted, the returned exception holds one suppressed exception each failureListener.assertCalled(httpHosts); do { Response response = e.getResponse(); assertEquals(Integer.parseInt(retryEndpoint.substring(1)), response.getStatusLine().getStatusCode()); assertTrue("host [" + response.getHost() + "] not found, most likely used multiple times", hostsSet.remove(response.getHost())); if (e.getSuppressed().length > 0) { assertEquals(1, e.getSuppressed().length); Throwable suppressed = e.getSuppressed()[0]; assertThat(suppressed, instanceOf(ResponseException.class)); e = (ResponseException) suppressed; } else { e = null; } } while (e != null); assertEquals("every host should have been used but some weren't: " + hostsSet, 0, hostsSet.size()); } catch (IOException e) { Set<HttpHost> hostsSet = new HashSet<>(); Collections.addAll(hostsSet, httpHosts); //first request causes all the hosts to be blacklisted, the returned exception holds one suppressed exception each failureListener.assertCalled(httpHosts); do { HttpHost httpHost = HttpHost.create(e.getMessage()); assertTrue("host [" + httpHost + "] not found, most likely used multiple times", hostsSet.remove(httpHost)); if (e.getSuppressed().length > 0) { assertEquals(1, e.getSuppressed().length); Throwable suppressed = e.getSuppressed()[0]; assertThat(suppressed, instanceOf(IOException.class)); e = (IOException) suppressed; } else { e = null; } } while (e != null); assertEquals("every host should have been used but some weren't: " + hostsSet, 0, hostsSet.size()); } int numIters = RandomNumbers.randomIntBetween(getRandom(), 2, 5); for (int i = 1; i <= numIters; i++) { //check that one different host is resurrected at each new attempt Set<HttpHost> hostsSet = new HashSet<>(); Collections.addAll(hostsSet, httpHosts); for (int j = 0; j < httpHosts.length; j++) { retryEndpoint = randomErrorRetryEndpoint(); try { restClient.performRequest(randomHttpMethod(getRandom()), retryEndpoint); fail("request should have failed"); } catch (ResponseException e) { Response response = e.getResponse(); assertThat(response.getStatusLine().getStatusCode(), equalTo(Integer.parseInt(retryEndpoint.substring(1)))); assertTrue("host [" + response.getHost() + "] not found, most likely used multiple times", hostsSet.remove(response.getHost())); //after the first request, all hosts are blacklisted, a single one gets resurrected each time failureListener.assertCalled(response.getHost()); assertEquals(0, e.getSuppressed().length); } catch (IOException e) { HttpHost httpHost = HttpHost.create(e.getMessage()); assertTrue("host [" + httpHost + "] not found, most likely used multiple times", hostsSet.remove(httpHost)); //after the first request, all hosts are blacklisted, a single one gets resurrected each time failureListener.assertCalled(httpHost); assertEquals(0, e.getSuppressed().length); } } assertEquals("every host should have been used but some weren't: " + hostsSet, 0, hostsSet.size()); if (getRandom().nextBoolean()) { //mark one host back alive through a successful request and check that all requests after that are sent to it HttpHost selectedHost = null; int iters = RandomNumbers.randomIntBetween(getRandom(), 2, 10); for (int y = 0; y < iters; y++) { int statusCode = randomErrorNoRetryStatusCode(getRandom()); Response response; try { response = restClient.performRequest(randomHttpMethod(getRandom()), "/" + statusCode); } catch (ResponseException e) { response = e.getResponse(); } assertThat(response.getStatusLine().getStatusCode(), equalTo(statusCode)); if (selectedHost == null) { selectedHost = response.getHost(); } else { assertThat(response.getHost(), equalTo(selectedHost)); } } failureListener.assertNotCalled(); //let the selected host catch up on number of failures, it gets selected a consecutive number of times as it's the one //selected to be retried earlier (due to lower number of failures) till all the hosts have the same number of failures for (int y = 0; y < i + 1; y++) { retryEndpoint = randomErrorRetryEndpoint(); try { restClient.performRequest(randomHttpMethod(getRandom()), retryEndpoint); fail("request should have failed"); } catch (ResponseException e) { Response response = e.getResponse(); assertThat(response.getStatusLine().getStatusCode(), equalTo(Integer.parseInt(retryEndpoint.substring(1)))); assertThat(response.getHost(), equalTo(selectedHost)); failureListener.assertCalled(selectedHost); } catch (IOException e) { HttpHost httpHost = HttpHost.create(e.getMessage()); assertThat(httpHost, equalTo(selectedHost)); failureListener.assertCalled(selectedHost); } } } } }
From source file:com.github.maven_nar.cpptasks.compiler.CommandLineCompiler.java
/** * Compiles a source file./*from w w w . j a v a 2 s . c om*/ * */ public void compile(final CCTask task, final File outputDir, final String[] sourceFiles, String[] args, final String[] endArgs, final boolean relentless, final CommandLineCompilerConfiguration config, final ProgressMonitor monitor) throws BuildException { BuildException exc = null; // // determine length of executable name and args // String command = getCommandWithPath(config); if (config.isUseCcache()) { // Replace the command with "ccache" and push the old compiler // command into the args. final String compilerCommand = command; command = CCACHE_CMD; args = ObjectArrays.concat(compilerCommand, args); } int baseLength = command.length() + args.length + endArgs.length; if (this.libtool) { baseLength += 8; } for (final String arg : args) { baseLength += arg.length(); } for (final String endArg : endArgs) { baseLength += endArg.length(); } if (baseLength > getMaximumCommandLength()) { throw new BuildException("Command line is over maximum length without specifying source file"); } // // typically either 1 or Integer.MAX_VALUE // final int maxInputFilesPerCommand = getMaximumInputFilesPerCommand(); final int argumentCountPerInputFile = getArgumentCountPerInputFile(); for (int sourceIndex = 0; sourceIndex < sourceFiles.length;) { int cmdLength = baseLength; int firstFileNextExec; for (firstFileNextExec = sourceIndex; firstFileNextExec < sourceFiles.length && firstFileNextExec - sourceIndex < maxInputFilesPerCommand; firstFileNextExec++) { cmdLength += getTotalArgumentLengthForInputFile(outputDir, sourceFiles[firstFileNextExec]); if (cmdLength >= getMaximumCommandLength()) { break; } } if (firstFileNextExec == sourceIndex) { throw new BuildException("Extremely long file name, can't fit on command line"); } ArrayList<String> commandlinePrefix = new ArrayList<>(); if (this.libtool) { commandlinePrefix.add("libtool"); } commandlinePrefix.add(command); Collections.addAll(commandlinePrefix, args); int retval = 0; for (int j = sourceIndex; j < firstFileNextExec; j++) { ArrayList<String> commandlineSuffix = new ArrayList<>(); for (int k = 0; k < argumentCountPerInputFile; k++) { commandlineSuffix.add(getInputFileArgument(outputDir, sourceFiles[j], k)); } Collections.addAll(commandlineSuffix, endArgs); ArrayList<String> commandline = new ArrayList<>(commandlinePrefix); commandline.addAll(commandlineSuffix); final int ret = runCommand(task, workDir, commandline.toArray(new String[commandline.size()])); if (ret != 0) { retval = ret; } } if (monitor != null) { final String[] fileNames = new String[firstFileNextExec - sourceIndex]; System.arraycopy(sourceFiles, sourceIndex + 0, fileNames, 0, fileNames.length); monitor.progress(fileNames); } // // if the process returned a failure code and // we aren't holding an exception from an earlier // interation if (retval != 0 && exc == null) { // // construct the exception // exc = new BuildException(getCommandWithPath(config) + " failed with return code " + retval, task.getLocation()); // // and throw it now unless we are relentless // if (!relentless) { throw exc; } } sourceIndex = firstFileNextExec; } // // if the compiler returned a failure value earlier // then throw an exception if (exc != null) { throw exc; } }
From source file:com.asakusafw.directio.hive.serde.DataModelDriver.java
/** * Returns source field references which will be actually mapped into the data model. * @return source field references/*from www . java 2 s . com*/ */ public List<StructField> getSourceFields() { List<StructField> results = new ArrayList<>(); Collections.addAll(results, this.sourceFields); return results; }
From source file:cop.raml.utils.example.JsonExample.java
/** * Returns all ignored fields for given {@code typeElement}. This time support only {@link JsonIgnoreProperties} and {@link JsonIgnore} * annotations. But in the following article <a href="http://www.baeldung.com/jackson-ignore-properties-on-serialization">Jackson Ignore * Properties on Marshalling</a>, more ways to ignore properties can be found, but there're not supported this time. * * @param typeElement type element/*from ww w .j av a 2 s . c o m*/ * @return not {@code null} list of ignored fields */ @NotNull private static Set<String> getIgnoredFields(TypeElement typeElement) { if (typeElement == null) return Collections.emptySet(); Set<String> res = new HashSet<>(); JsonIgnoreProperties annotation = typeElement.getAnnotation(JsonIgnoreProperties.class); if (annotation != null && ArrayUtils.isNotEmpty(annotation.value())) Collections.addAll(res, annotation.value()); JsonIgnore ann; for (Element element : typeElement.getEnclosedElements()) if ((ann = element.getAnnotation(JsonIgnore.class)) != null && ann.value()) res.add(element.toString()); return res; }
From source file:de.openali.odysseus.chart.factory.config.ChartLayerFactory.java
/** * @return IChartLayer from {@link LayersType}.getDerivedLayerArray() *//* ww w .j a va 2 s . c o m*/ private IChartLayer buildDerivedLayerTypes(final DerivedLayerType derivedLayerType, final ParametersType cascading, final ReferencableType... baseTypes) throws CoreException, ConfigurationException { final ChartTypeResolver resovler = ChartTypeResolver.getInstance(); final LayerRefernceType reference = derivedLayerType.getLayerReference(); final LayerType baseLayerType = resovler.findLayerType(reference, getContext()); final LayerType derived = DerivedLayerTypeHelper.buildDerivedLayerType(derivedLayerType, baseLayerType); LayerTypeHelper.appendParameters(derived, cascading); final ReferencableType parentBasePlayerType = LayerTypeHelper.getParentNode(derived); final Set<ReferencableType> types = new LinkedHashSet<>(); types.add(derived); types.add(baseLayerType); types.add(parentBasePlayerType); Collections.addAll(types, baseTypes); final IChartLayer layer = buildLayer(derived, cascading, LayerTypeHelper.getLayerTypeProvider(getLoader(), derived), types.toArray(new ReferencableType[] {})); return layer; }
From source file:com.oneops.sensor.ws.SensorWsController.java
/** * Process open events.//from w ww . ja v a 2s . co m * * @param ciIdsAr the ci ids * @return the list */ @RequestMapping(method = RequestMethod.POST, value = "/ops/events") @ResponseBody public List<Map<Long, Map<String, List<CiOpenEvent>>>> processOpenEvents(@RequestBody Long[] ciIdsAr) { List<Long> ciIds = new ArrayList<>(); Collections.addAll(ciIds, ciIdsAr); return getOpenEventsForList(ciIds); }
From source file:net.sf.jabref.external.RegExpFileSearch.java
/** * The actual work-horse. Will find absolute filepaths starting from the * given directory using the given regular expression string for search. *//*from ww w.j a v a2 s.c om*/ private static List<File> findFile(BibEntry entry, File directory, String file, String extensionRegExp) { List<File> res = new ArrayList<>(); File actualDirectory; if (file.startsWith("/")) { actualDirectory = new File("."); file = file.substring(1); } else { actualDirectory = directory; } // Escape handling... Matcher m = ESCAPE_PATTERN.matcher(file); StringBuffer s = new StringBuffer(); while (m.find()) { m.appendReplacement(s, m.group(1) + '/' + m.group(2)); } m.appendTail(s); file = s.toString(); String[] fileParts = file.split("/"); if (fileParts.length == 0) { return res; } for (int i = 0; i < (fileParts.length - 1); i++) { String dirToProcess = fileParts[i]; dirToProcess = expandBrackets(dirToProcess, entry, null); if (dirToProcess.matches("^.:$")) { // Windows Drive Letter actualDirectory = new File(dirToProcess + '/'); continue; } if (".".equals(dirToProcess)) { // Stay in current directory continue; } if ("..".equals(dirToProcess)) { actualDirectory = new File(actualDirectory.getParent()); continue; } if ("*".equals(dirToProcess)) { // Do for all direct subdirs File[] subDirs = actualDirectory.listFiles(); if (subDirs != null) { String restOfFileString = StringUtil.join(fileParts, "/", i + 1, fileParts.length); for (File subDir : subDirs) { if (subDir.isDirectory()) { res.addAll(findFile(entry, subDir, restOfFileString, extensionRegExp)); } } } } // Do for all direct and indirect subdirs if ("**".equals(dirToProcess)) { List<File> toDo = new LinkedList<>(); toDo.add(actualDirectory); String restOfFileString = StringUtil.join(fileParts, "/", i + 1, fileParts.length); while (!toDo.isEmpty()) { // Get all subdirs of each of the elements found in toDo File[] subDirs = toDo.remove(0).listFiles(); if (subDirs == null) { continue; } toDo.addAll(Arrays.asList(subDirs)); for (File subDir : subDirs) { if (!subDir.isDirectory()) { continue; } res.addAll(findFile(entry, subDir, restOfFileString, extensionRegExp)); } } } // End process directory information } // Last step: check if the given file can be found in this directory String filePart = fileParts[fileParts.length - 1].replace("[extension]", EXT_MARKER); String filenameToLookFor = expandBrackets(filePart, entry, null).replaceAll(EXT_MARKER, extensionRegExp); final Pattern toMatch = Pattern.compile('^' + filenameToLookFor.replaceAll("\\\\\\\\", "\\\\") + '$', Pattern.CASE_INSENSITIVE); File[] matches = actualDirectory.listFiles((arg0, arg1) -> { return toMatch.matcher(arg1).matches(); }); if ((matches != null) && (matches.length > 0)) { Collections.addAll(res, matches); } return res; }
From source file:com.twitter.maple.jdbc.db.DBOutputFormat.java
protected String constructUpdateQuery(String table, String[] fieldNames, String[] updateNames) { if (fieldNames == null) { throw new IllegalArgumentException("field names may not be null"); }/* w ww . j a va2 s . c om*/ Set<String> updateNamesSet = new HashSet<String>(); Collections.addAll(updateNamesSet, updateNames); StringBuilder query = new StringBuilder(); query.append("UPDATE ").append(table); query.append(" SET "); if (fieldNames.length > 0 && fieldNames[0] != null) { int count = 0; for (int i = 0; i < fieldNames.length; i++) { if (updateNamesSet.contains(fieldNames[i])) { continue; } if (count != 0) { query.append(","); } query.append(fieldNames[i]); query.append(" = ?"); count++; } } query.append(" WHERE "); if (updateNames.length > 0 && updateNames[0] != null) { for (int i = 0; i < updateNames.length; i++) { query.append(updateNames[i]); query.append(" = ?"); if (i != updateNames.length - 1) { query.append(" and "); } } } query.append(";"); return query.toString(); }