List of usage examples for java.util Arrays stream
public static DoubleStream stream(double[] array)
From source file:com.hurence.logisland.plugin.PluginManager.java
private static void installPlugin(String artifact, String logislandHome) { Optional<ModuleInfo> moduleInfo = findPluginMeta().entrySet().stream() .filter(e -> artifact.equals(e.getKey().getArtifact())).map(Map.Entry::getKey).findFirst(); if (moduleInfo.isPresent()) { System.err/* ww w . j a v a 2 s . co m*/ .println("A component already matches the artifact " + artifact + ". Please remove it first."); System.exit(-1); } try { IvySettings settings = new IvySettings(); settings.load(new File(logislandHome, "conf/ivy.xml")); Ivy ivy = Ivy.newInstance(settings); ivy.bind(); System.out.println("\nDownloading dependencies. Please hold on...\n"); String parts[] = Arrays.stream(artifact.split(":")).map(String::trim).toArray(a -> new String[a]); if (parts.length != 3) { throw new IllegalArgumentException( "Unrecognized artifact format. It should be groupId:artifactId:version"); } ModuleRevisionId revisionId = new ModuleRevisionId(new ModuleId(parts[0], parts[1]), parts[2]); Set<ArtifactDownloadReport> toBePackaged = downloadArtifacts(ivy, revisionId, new String[] { "default", "compile", "runtime" }); ArtifactDownloadReport artifactJar = toBePackaged.stream() .filter(a -> a.getArtifact().getModuleRevisionId().equals(revisionId)).findFirst() .orElseThrow(() -> new IllegalStateException("Unable to find artifact " + artifact + ". Please check the name is correct and the repositories on ivy.xml are correctly configured")); Manifest manifest = new JarFile(artifactJar.getLocalFile()).getManifest(); File libDir = new File(logislandHome, "lib"); if (manifest.getMainAttributes().containsKey(ManifestAttributes.MODULE_ARTIFACT)) { org.apache.commons.io.FileUtils.copyFileToDirectory(artifactJar.getLocalFile(), libDir); //we have a logisland plugin. Just copy it System.out.println(String.format("Found logisland plugin %s version %s\n" + "It will provide:", manifest.getMainAttributes().getValue(ManifestAttributes.MODULE_NAME), manifest.getMainAttributes().getValue(ManifestAttributes.MODULE_VERSION))); Arrays.stream(manifest.getMainAttributes().getValue(ManifestAttributes.MODULE_EXPORTS).split(",")) .map(String::trim).forEach(s -> System.out.println("\t" + s)); } else { System.out.println("Repackaging artifact and its dependencies"); Set<ArtifactDownloadReport> environment = downloadArtifacts(ivy, revisionId, new String[] { "provided" }); Set<ArtifactDownloadReport> excluded = toBePackaged.stream() .filter(adr -> excludeGroupIds.stream() .anyMatch(s -> s.matches(adr.getArtifact().getModuleRevisionId().getOrganisation())) || excludedArtifactsId.stream().anyMatch( s -> s.matches(adr.getArtifact().getModuleRevisionId().getName()))) .collect(Collectors.toSet()); toBePackaged.removeAll(excluded); environment.addAll(excluded); Repackager rep = new Repackager(artifactJar.getLocalFile(), new LogislandPluginLayoutFactory()); rep.setMainClass(""); File destFile = new File(libDir, "logisland-component-" + artifactJar.getLocalFile().getName()); rep.repackage(destFile, callback -> toBePackaged.stream().filter(adr -> adr.getLocalFile() != null) .filter(adr -> !adr.getArtifact().getModuleRevisionId().equals(revisionId)) .map(adr -> new Library(adr.getLocalFile(), LibraryScope.COMPILE)).forEach(library -> { try { callback.library(library); } catch (IOException e) { throw new UncheckedIOException(e); } })); Thread.currentThread().setContextClassLoader(new URLClassLoader( environment.stream().filter(adr -> adr.getLocalFile() != null).map(adr -> { try { return adr.getLocalFile().toURI().toURL(); } catch (Exception e) { throw new RuntimeException(e); } }).toArray(a -> new URL[a]), Thread.currentThread().getContextClassLoader())); //now clean up package and write the manifest String newArtifact = "com.hurence.logisland.repackaged:" + parts[1] + ":" + parts[2]; LogislandRepackager.execute(destFile.getAbsolutePath(), "BOOT-INF/lib-provided", parts[2], newArtifact, "Logisland Component for " + artifact, "Logisland Component for " + artifact, new String[] { "org.apache.kafka.*" }, new String[0], "org.apache.kafka.connect.connector.Connector"); } System.out.println("Install done!"); } catch (Exception e) { System.err.println("Unable to install artifact " + artifact); e.printStackTrace(); System.exit(-1); } }
From source file:com.ikanow.aleph2.logging.utils.LoggingUtils.java
/** * Merges the BMB message with an existing old entry (if it exists) otherwise merges with null. If * an entry did not exist, creates new default Map in the tuple for storing merge info. * @param basicMessageBean/*from w ww .j ava 2s .c o m*/ * @param merge_key * @return */ public static Tuple2<BasicMessageBean, Map<String, Object>> getOrCreateMergeInfo( final Map<String, Tuple2<BasicMessageBean, Map<String, Object>>> merge_logs, final BasicMessageBean message, final String merge_key, final BiFunction<BasicMessageBean, BasicMessageBean, BasicMessageBean>[] merge_operations) { return merge_logs.compute(merge_key, (k, v) -> { if (v == null) { //final BasicMessageBean bmb = merge_operations.apply(message, null); final BasicMessageBean bmb = Arrays.stream(merge_operations).reduce(null, (bmb_a, fn) -> fn.apply(message, bmb_a), (bmb_a, bmb_b) -> bmb_a); Map<String, Object> info = new HashMap<String, Object>(); info.put(LOG_COUNT_FIELD, 0L); info.put(LAST_LOG_TIMESTAMP_FIELD, 0L); return new Tuple2<BasicMessageBean, Map<String, Object>>(bmb, info); } else { //merge with old entry //final BasicMessageBean bmb = merge_operations.apply(message, merge_logs.get(merge_key)._1); final BasicMessageBean bmb = Arrays.stream(merge_operations).reduce(merge_logs.get(merge_key)._1, (bmb_a, fn) -> fn.apply(message, bmb_a), (bmb_a, bmb_b) -> bmb_a); return new Tuple2<BasicMessageBean, Map<String, Object>>(bmb, v._2); } }); }
From source file:edu.cmu.lti.oaqa.bioqa.providers.kb.TmToolConceptProvider.java
protected List<String> requestConcepts(List<String> normalizedTexts, String trigger) throws AnalysisEngineProcessException { PubAnnotation[] inputs = PubAnnotationConvertUtil.convertTextsToPubAnnotations(normalizedTexts); String request = gson.toJson(inputs, PubAnnotation[].class); String response;// w w w . j a va2 s.c om try { response = submitText(trigger, request); } catch (IOException e) { throw new AnalysisEngineProcessException(e); } PubAnnotation[] outputs = gson.fromJson("[" + response + "]", PubAnnotation[].class); List<PubAnnotation> sortedOutputs = Arrays.stream(outputs) .sorted(Comparator.comparing(pa -> Integer.parseInt(pa.getSourceid()))).collect(toList()); List<String> denotationStrings = sortedOutputs.stream().map(PubAnnotation::getDenotations).map(gson::toJson) .collect(toList()); if (denotationStrings.size() != normalizedTexts.size()) { throw TmToolConceptProviderException.unequalVolume(trigger, normalizedTexts.size(), denotationStrings.size()); } for (int i = 0; i < normalizedTexts.size(); i++) { String sentText = normalizedTexts.get(i); String recvText = PubAnnotationConvertUtil.normalizeText(sortedOutputs.get(i).getText()); if (sentText.length() != recvText.length()) { throw TmToolConceptProviderException.unequalTextLength(trigger, sentText, recvText); } // if (sentText.equals(recvText)) { // throw TmToolConceptProviderException.textChanged(trigger, sentText, recvText); // } } return denotationStrings; }
From source file:com.vmware.admiral.compute.container.volume.VolumeUtil.java
private static void addAffinity(String affinityTo, ContainerDescription cd) { if (cd.affinity != null) { boolean alreadyIn = Arrays.stream(cd.affinity).anyMatch(af -> affinityTo.equals(af)); if (!alreadyIn) { int newSize = cd.affinity.length + 1; cd.affinity = Arrays.copyOf(cd.affinity, newSize); cd.affinity[newSize - 1] = affinityTo; }// w ww .jav a 2s.c o m } else { cd.affinity = new String[] { affinityTo }; } }
From source file:com.hortonworks.registries.schemaregistry.avro.ConfluentRegistryCompatibleResourceTest.java
@Test public void testConfluentApis() throws Exception { List<String> schemas = Arrays .stream(new String[] { "/device.avsc", "/device-compat.avsc", "/device-incompat.avsc" }).map(x -> { try { return fetchSchema(x); } catch (IOException e) { throw new RuntimeException(e); }/* w ww. j ava 2s . c om*/ }).collect(Collectors.toList()); ObjectMapper objectMapper = new ObjectMapper(); List<String> subjects = new ArrayList<>(); for (String schemaText : schemas) { String subjectName = UUID.randomUUID().toString(); subjects.add(subjectName); // check post schema version Long schemaId = objectMapper .readValue(postSubjectSchema(subjectName, schemaText).readEntity(String.class), Id.class) .getId(); // check get version api Schema schemaVersionEntry = getVersion(subjectName, "latest"); Assert.assertEquals(subjectName, schemaVersionEntry.getSubject()); Assert.assertEquals(schemaId.intValue(), schemaVersionEntry.getId().intValue()); org.apache.avro.Schema recvdSchema = new org.apache.avro.Schema.Parser() .parse(schemaVersionEntry.getSchema()); org.apache.avro.Schema regdSchema = new org.apache.avro.Schema.Parser().parse(schemaText); Assert.assertEquals(regdSchema, recvdSchema); } // check all registered subjects List<String> recvdSubjects = getAllSubjects(); Assert.assertEquals(new HashSet<>(subjects), new HashSet<>(recvdSubjects)); }