List of usage examples for java.lang String join
public static String join(CharSequence delimiter, Iterable<? extends CharSequence> elements)
From source file:org.apache.sling.tooling.lc.jira.IssueFinder.java
public List<Issue> findIssues(List<String> issueKeys) throws IOException { HttpClient client = new DefaultHttpClient(); HttpGet get;// w ww. ja v a 2 s . c o m try { URIBuilder builder = new URIBuilder("https://issues.apache.org/jira/rest/api/2/search") .addParameter("jql", "key in (" + String.join(",", issueKeys) + ")") .addParameter("fields", "key,summary"); get = new HttpGet(builder.build()); } catch (URISyntaxException e) { // never happens throw new RuntimeException(e); } HttpResponse response = client.execute(get); try { if (response.getStatusLine().getStatusCode() != 200) { throw new IOException("Search call returned status " + response.getStatusLine().getStatusCode()); } try (Reader reader = new InputStreamReader(response.getEntity().getContent(), "UTF-8")) { Response apiResponse = new Gson().fromJson(reader, Response.class); List<Issue> issues = apiResponse.getIssues(); Collections.sort(issues); return issues; } } finally { HttpClientUtils.closeQuietly(client); } }
From source file:local.laer.app.knapsack.SimpleKnapsackTest.java
@Test @Ignore/*from w w w .jav a2 s . c o m*/ public void testKnappsack() throws JsonProcessingException { // CD // AA // BB // BB Shape s11 = new Shape(1, 1, 1); Shape s22 = new Shape(2, 2, 1); Shape s12 = new Shape(1, 2, 1); KnapsackProblem p = new KnapsackProblem(); p.setArea(new Area(4, 2, 1)); p.addShapes(s11, "a1", "a2"); p.addShapes(s12, "a3"); p.addShapes(s22, "a4"); SimpleKnapsack.Runtime rt = new SimpleKnapsack.Runtime(p); KnapsackSolution solution = rt.process(); OffsetIntMatrix m = solution.asIntMatrix(); LOG.info("\n" + IntFunctions.toString(m)); CharRepresentationMatrix charMatrix = new CharRepresentationMatrix(m); LOG.info("\n" + String.join("\n", charMatrix.toLines())); assertThat(m.getInt(0, 0), is(4)); assertThat(m.getInt(0, 1), is(3)); assertThat(m.getInt(1, 0), is(1)); assertThat(m.getInt(1, 1), is(1)); assertThat(m.getInt(2, 0), is(2)); assertThat(m.getInt(2, 1), is(2)); assertThat(m.getInt(3, 0), is(2)); assertThat(m.getInt(3, 1), is(2)); }
From source file:io.gravitee.gateway.policy.impl.processor.spring.SpringPolicyContextProviderFactory.java
public PolicyContextProvider create(PolicyContext policyContext) { Import importAnnotation = policyContext.getClass().getAnnotation(Import.class); List<Class<?>> importClasses = Arrays.asList(importAnnotation.value()); LOGGER.info("Initializing a Spring context provider from @Import annotation: {}", String.join(",", importClasses.stream().map(Class::getName).collect(Collectors.toSet()))); AnnotationConfigApplicationContext policyApplicationContext = new AnnotationConfigApplicationContext(); policyApplicationContext.setClassLoader(policyContext.getClass().getClassLoader()); importClasses.forEach(policyApplicationContext::register); // TODO: set the parent application context ? // pluginContext.setEnvironment(applicationContextParent.getEnvironment()); // pluginContext.setParent(applicationContextParent); policyApplicationContext.refresh();//from w w w .j ava 2 s.c o m return new SpringPolicyContextProvider(policyApplicationContext); }
From source file:io.stallion.utils.ProcessHelper.java
public CommandResult run() { String cmdString = String.join(" ", args); System.out.printf("----- Execute command: %s ----\n", cmdString); ProcessBuilder pb = new ProcessBuilder(args); if (!empty(directory)) { pb.directory(new File(directory)); }//w ww .ja v a 2s.c o m Map<String, String> env = pb.environment(); CommandResult commandResult = new CommandResult(); Process p = null; try { if (showDotsWhileWaiting == null) { showDotsWhileWaiting = !inheritIO; } if (inheritIO) { p = pb.inheritIO().start(); } else { p = pb.start(); } BufferedReader err = new BufferedReader(new InputStreamReader(p.getErrorStream())); BufferedReader out = new BufferedReader(new InputStreamReader(p.getInputStream())); if (!empty(input)) { Log.info("Writing input to pipe {0}", input); IOUtils.write(input, p.getOutputStream(), UTF8); p.getOutputStream().flush(); } while (p.isAlive()) { p.waitFor(1000, TimeUnit.MILLISECONDS); if (showDotsWhileWaiting == true) { System.out.printf("."); } } commandResult.setErr(IOUtils.toString(err)); commandResult.setOut(IOUtils.toString(out)); commandResult.setCode(p.exitValue()); if (commandResult.succeeded()) { info("\n---- Command execution completed ----\n"); } else { Log.warn("Command failed with error code: " + commandResult.getCode()); } } catch (IOException e) { Log.exception(e, "Error running command: " + cmdString); commandResult.setCode(999); commandResult.setEx(e); } catch (InterruptedException e) { Log.exception(e, "Error running command: " + cmdString); commandResult.setCode(998); commandResult.setEx(e); } Log.fine( "\n\n----Start shell command result----:\nCommand: {0}\nexitCode: {1}\n----------STDOUT---------\n{2}\n\n----------STDERR--------\n{3}\n\n----end shell command result----\n", cmdString, commandResult.getCode(), commandResult.getOut(), commandResult.getErr()); return commandResult; }
From source file:eu.over9000.cathode.data.parameters.EmoteSets.java
@Override public List<NameValuePair> buildParamPairs() { if (emoteSets.isEmpty()) { return Collections.emptyList(); }//ww w. j a v a2 s.c o m return Collections.singletonList(new BasicNameValuePair("emotesets", String.join(",", emoteSets))); }
From source file:com.orange.spring.cloud.connector.s3.core.service.S3ServiceInfo.java
public String getS3Host() { String host = this.getHost(); if (this.isVirtualHostBuckets()) { List<String> splittedHost = new ArrayList<String>(Arrays.asList(host.split("\\."))); splittedHost.remove(0);// www. j av a2 s. com host = String.join(".", splittedHost); } String port = ""; if (this.getPort() != -1) { port += ":" + this.getPort(); } String protocol = this.getProtocol(); return protocol + "://" + host + port; }
From source file:io.github.retz.web.feign.ErrorResponseDecoder.java
@Override public Exception decode(String methodKey, Response response) { Exception ex = delegate.decode(methodKey, response); String server = String.join(", ", response.headers().get("Server")); new ProtocolTester(server, Client.VERSION_STRING).test(); if (ex instanceof ErrorResponseException) { return ex; } else if (ex instanceof FeignException) { FeignException fex = (FeignException) ex; return extractor.apply(fex.getMessage()).map(value -> { try { return new ErrorResponseException(fex.status(), fex.getMessage(), mapper.readValue(value, ErrorResponse.class)); } catch (IOException e) { return new ErrorResponseException(fex.status(), fex.getMessage(), new ErrorResponse(value)); }// w ww . ja v a 2 s . c o m }).orElseGet(() -> new ErrorResponseException(fex.status(), fex.getMessage(), new ErrorResponse(fex.toString()))); } else { return ex; } }
From source file:com.netflix.spinnaker.clouddriver.kubernetes.v2.security.KubernetesSelector.java
@Override public String toString() { switch (kind) { case ANY:/*from w w w. j a v a 2 s. c o m*/ return ""; case EQUALS: return String.format("%s = %s", key, values.get(0)); case NOT_EQUALS: return String.format("%s != %s", key, values.get(0)); case CONTAINS: return String.format("%s in (%s)", key, String.join(", ", values)); case NOT_CONTAINS: return String.format("%s notin (%s)", key, String.join(", ", values)); case EXISTS: return String.format("%s", key); case NOT_EXISTS: return String.format("!%s", key); default: throw new IllegalStateException("Unknown kind " + kind); } }
From source file:org.wildfly.swarm.plugin.FractionMetadata.java
@JsonProperty("tags") public String getTagsString() { if (this.tags.isEmpty()) { return ""; }/*from ww w. ja va2s . c o m*/ return String.join(",", this.tags); }
From source file:mtsar.api.csv.WorkerCSV.java
public static void write(Collection<Worker> workers, OutputStream output) throws IOException { try (final Writer writer = new OutputStreamWriter(output, StandardCharsets.UTF_8)) { final Iterable<String[]> iterable = () -> workers.stream().sorted(ORDER) .map(worker -> new String[] { Integer.toString(worker.getId()), // id worker.getStage(), // stage Long.toString(worker.getDateTime().toInstant().getEpochSecond()), // datetime String.join("|", worker.getTags()), // tags }).iterator();/*from ww w . j a v a 2 s. c o m*/ FORMAT.withHeader(HEADER).print(writer).printRecords(iterable); } }