List of usage examples for java.util Arrays stream
public static DoubleStream stream(double[] array)
From source file:org.apache.geode.tools.pulse.PulseDataExportTest.java
public void getAuthenticatedJSESSIONID() throws Throwable { HttpResponse loginResponse = httpClient.execute(buildLoginPOST()); assertThat(loginResponse.getStatusLine().getStatusCode()).describedAs(loginResponse.toString()) .isEqualTo(302);/*from w w w .jav a2 s .c o m*/ String JSESSIONIDFromSetCookieHeader = Arrays.stream(loginResponse.getHeaders("SET-COOKIE")) .map(Header::getValue).filter(setCookie -> setCookie.contains("JSESSIONID")).findAny() .orElseThrow(() -> new AssertionError( "No JSESSIONID cookie was set in the login response: " + loginResponse.toString())); Cookie JESSIONIDFromCookieStore = cookieStore.getCookies().stream() .filter(cookie -> cookie.getName().equalsIgnoreCase("JSESSIONID")).findFirst() .orElseThrow(() -> new AssertionError("No JSESSIONID cookie was set in the cookie store")); assertThat(JSESSIONIDFromSetCookieHeader).contains(JESSIONIDFromCookieStore.getValue()); }
From source file:com.oneops.cms.dj.domain.CmsDeployment.java
public void setAutoPauseExecOrdersVal(String autoPauseExecOrdersVal, boolean updateCollection) { this.autoPauseExecOrdersVal = autoPauseExecOrdersVal; if (updateCollection) { if (StringUtils.isNotBlank(autoPauseExecOrdersVal)) { autoPauseExecOrders = Arrays.stream(autoPauseExecOrdersVal.split(",")) .map(val -> Integer.parseInt(val.trim())).collect(Collectors.toSet()); }// ww w .j av a 2s. c o m } }
From source file:com.asakusafw.testdriver.DirectIoUtil.java
private static <T> DataModelSourceFactory load0(DataModelDefinition<T> definition, HadoopFileFormat<? super T> format, URL source) throws IOException, InterruptedException { List<String> segments = Arrays.stream(source.getPath().split("/")) //$NON-NLS-1$ .map(String::trim).filter(s -> s.isEmpty() == false).collect(Collectors.toList()); String name;//from w w w.j a va 2 s . co m if (segments.isEmpty()) { name = "testing.file"; //$NON-NLS-1$ } else { name = segments.get(segments.size() - 1); } Path tmpdir = Files.createTempDirectory("asakusa-"); //$NON-NLS-1$ try (InputStream in = source.openStream()) { Path target = tmpdir.resolve(name); Files.copy(in, target); return load0(definition, format, target.toFile()); } finally { File dir = tmpdir.toFile(); if (FileUtils.deleteQuietly(dir) == false && dir.exists()) { LOG.warn(MessageFormat.format("failed to delete a temporary file: {0}", tmpdir)); } } }
From source file:com.kantenkugel.discordbot.jdocparser.JDoc.java
/** * Searches the whole JavaDocs based on input string and options * * @param input The text to search for.//w w w.j a v a 2 s. c o m * @param options Options refining the search. Valid options are: * <ul> * <li>cs - makes matching case-sensitive</li> * <li>f - only methods are searched. Can't be used together with other type-specific filters.</li> * <li>c - only classes are searched. Can't be used together with other type-specific filters.</li> * <li>var - only values are searched. Can't be used together with other type-specific filters.</li> * </ul> * @return Pairs of the form: Text-representation - Documentation * @throws PatternSyntaxException if regex was used and the regex is not valid */ public static Set<Pair<String, ? extends Documentation>> search(String input, String... options) throws PatternSyntaxException { Set<String> opts = Arrays.stream(options).map(String::toLowerCase).collect(Collectors.toSet()); final boolean isCaseSensitive = opts.contains("cs"); String key = input.toLowerCase(); if (opts.contains("f")) { return docs.values().stream() .flatMap(cls -> cls.methodDocs.entrySet().stream().filter(mds -> mds.getKey().contains(key)) .map(Map.Entry::getValue).flatMap(Collection::stream)) .filter(md -> !isCaseSensitive || md.functionName.contains(input)) .map(md -> Pair.of(md.parent.className + " " + md.functionSig, md)).collect(Collectors.toSet()); } else if (opts.contains("c")) { return docs.values().stream() .filter(cls -> isCaseSensitive ? cls.className.contains(input) : cls.className.toLowerCase().contains(key)) .map(cls -> Pair.of("Class " + cls.className, cls)).collect(Collectors.toSet()); } else if (opts.contains("var")) { return docs.values().stream() .flatMap(cls -> cls.classValues.entrySet().stream().filter(val -> val.getKey().contains(key)) .map(Map.Entry::getValue)) .filter(val -> !isCaseSensitive || val.name.contains(input)) .map(val -> Pair.of(val.parent.className + " " + val.sig, val)).collect(Collectors.toSet()); } else { //search all categories Set<Pair<String, ? extends Documentation>> results = new HashSet<>(); for (JDocParser.ClassDocumentation classDoc : docs.values()) { if (isCaseSensitive ? classDoc.className.contains(input) : classDoc.className.toLowerCase().contains(key)) results.add(Pair.of("Class " + classDoc.className, classDoc)); for (Set<JDocParser.MethodDocumentation> mdcs : classDoc.methodDocs.values()) { for (JDocParser.MethodDocumentation mdc : mdcs) { if (isCaseSensitive ? mdc.functionName.contains(input) : mdc.functionName.toLowerCase().contains(key)) results.add(Pair.of(mdc.parent.className + " " + mdc.functionSig, mdc)); } } for (JDocParser.ValueDocumentation valueDoc : classDoc.classValues.values()) { if (isCaseSensitive ? valueDoc.name.contains(input) : valueDoc.name.toLowerCase().contains(key)) results.add(Pair.of(valueDoc.parent.className + " " + valueDoc.sig, valueDoc)); } } return results; } }
From source file:co.runrightfast.core.security.cert.X509V3CertRequest.java
private Collection<X509CertExtension> augmentExtensions(final Collection<X509CertExtension> extensions, final PublicKey subjectPublicKey, final X509CertExtension... exts) { final JcaX509ExtensionUtils extUtils = jcaX509ExtensionUtils(); return ImmutableList.<X509CertExtension>builder() .add(X509CertExtension.builder().oid(Extension.subjectKeyIdentifier) .value(extUtils.createSubjectKeyIdentifier(subjectPublicKey)).critical(false).build()) .addAll(extensions)// w w w .j av a 2 s . c o m .addAll(exts != null ? Arrays.stream(exts).collect(Collectors.toList()) : Collections.emptyList()) .build(); }
From source file:com.marklogic.entityservices.e2e.ExamplesBase.java
public void importJSON(Path jsonDirectory, String toCollection) throws IOException { logger.info("job started."); WriteHostBatcher batcher = moveMgr.newWriteHostBatcher().withBatchSize(100).withThreadCount(5) .onBatchSuccess((client, batch) -> logger.info("Loaded batch of JSON documents")) .onBatchFailure((client, batch, throwable) -> { logger.error("FAILURE on batch:" + batch.toString() + "\n", throwable); System.err.println(throwable.getMessage()); System.err.println(Arrays.stream(batch.getItems()).map(item -> item.getTargetUri()) .collect(Collectors.joining("\n"))); // throwable.printStackTrace(); });//from w ww.j a v a 2s.c o m ticket = moveMgr.startJob(batcher); importOrDescend(jsonDirectory, batcher, toCollection, Format.JSON); batcher.flush(); }
From source file:cop.raml.utils.Utils.java
public static String offs(String str, int offs, boolean strict) { if (StringUtils.isBlank(str) || offs < 0) return str; String tmp = StringUtils.repeat(StringUtils.SPACE, offs); String[] lines = Arrays.stream(splitLine(str)).map(line -> tmp + (strict ? line : line.trim())) .map(line -> StringUtils.isBlank(line) ? StringUtils.EMPTY : line).toArray(String[]::new); return String.join("\n", lines); }
From source file:com.haulmont.cuba.core.sys.dbupdate.ScriptScanner.java
protected Map<String, ScriptResource> findResourcesByUrlPattern(ResourcePatternResolver resourceResolver, String urlPattern) throws IOException { try {// w w w. j a va 2 s . co m return Arrays.stream(resourceResolver.getResources(urlPattern)).map(ScriptResource::new) .collect(Collectors.toMap(ScriptResource::getName, Function.identity())); } catch (FileNotFoundException e) { //just return empty map return Collections.emptyMap(); } }
From source file:com.github.aptd.simulation.elements.graph.network.local.CPlatform.java
@Override protected boolean updatestate() { if (m_input.isEmpty()) return false; final List<IMessage> l_arrivingtrains = m_input.get(EMessageType.TRAIN_TO_PLATFORM_ARRIVING); final List<IMessage> l_departingtrains = m_input.get(EMessageType.TRAIN_TO_PLATFORM_DEPARTING); final List<IMessage> l_subscribingpassengers = m_input.get(EMessageType.PASSENGER_TO_PLATFORM_SUBSCRIBE); final List<IMessage> l_unsubscribingpassengers = m_input .get(EMessageType.PASSENGER_TO_PLATFORM_UNSUBSCRIBE); if (l_departingtrains.size() > 1) throw new RuntimeException( m_id + " has multiple trains departing simultaneously at " + m_time.current()); if (l_departingtrains.size() == 1) { if (m_train != l_departingtrains.get(0).sender()) throw new RuntimeException(m_id + " has a train departing that's not there at " + m_time.current()); m_passengers.stream().forEach(p -> output( new CMessage(this, p.id(), EMessageType.PLATFORM_TO_PASSENGER_TRAINDEPARTED, m_train.id()))); m_train = null;//from www . j ava 2 s .c o m m_doors.clear(); } l_subscribingpassengers.stream().forEach(msg -> { m_passengers.add((IPassenger) msg.sender()); if (m_train != null) output(new CMessage(this, msg.sender().id(), EMessageType.PLATFORM_TO_PASSENGER_TRAINARRIVED, m_train.id(), m_doors.toArray())); }); l_unsubscribingpassengers.stream().forEach(msg -> m_passengers.remove(msg.sender())); if (l_arrivingtrains.size() > 1) throw new RuntimeException( m_id + " has multiple trains arriving simultaneously at " + m_time.current()); if (l_arrivingtrains.size() == 1) { if (m_train != null) throw new RuntimeException( m_id + " has a second train arriving without the first departing at " + m_time.current()); m_train = (ITrain) l_arrivingtrains.get(0).sender(); Arrays.stream(l_arrivingtrains.get(0).content()).map(o -> (IDoor<?>) o) .sorted(Comparator.comparing(IDoor::id)).forEachOrdered(m_doors::add); m_passengers.stream().forEach(p -> output(new CMessage(this, p.id(), EMessageType.PLATFORM_TO_PASSENGER_TRAINARRIVED, m_train.id(), m_doors.toArray()))); } return true; }
From source file:org.obiba.mica.search.csvexport.SpecificStudyReportGenerator.java
private Map<String, Locale> getCountries() { return Arrays.stream(Locale.getAvailableLocales()).collect(Collectors.toMap(locale -> { try {//from ww w.ja va 2s. c om return locale.getISO3Country(); } catch (RuntimeException e) { return locale.getCountry(); } }, Function.identity(), (a, b) -> a)); }