List of usage examples for java.util Spliterator DISTINCT
int DISTINCT
To view the source code for java.util Spliterator DISTINCT.
Click Source Link
From source file:com.simiacryptus.util.test.EnglishWords.java
/** * Load stream./* www. ja v a 2 s . com*/ * * @return the stream */ public static Stream<EnglishWords> load() { if (thread == null) { synchronized (WikiArticle.class) { if (thread == null) { thread = new Thread(EnglishWords::read); thread.setDaemon(true); thread.start(); } } } Iterator<EnglishWords> iterator = new AsyncListIterator<>(queue, thread); return StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.DISTINCT), false) .filter(x -> x != null); }
From source file:com.simiacryptus.util.test.Shakespeare.java
/** * Load stream./*from w ww .j a va 2 s . com*/ * * @return the stream */ public static Stream<Shakespeare> load() { if (thread == null) { synchronized (WikiArticle.class) { if (thread == null) { thread = new Thread(Shakespeare::read); thread.setDaemon(true); thread.start(); } } } Iterator<Shakespeare> iterator = new AsyncListIterator<>(queue, thread); return StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.DISTINCT), false) .filter(x -> x != null); }
From source file:com.github.steveash.guavate.Guavate.java
/** * Creates a stream that combines two other streams, continuing until either stream ends. * <p>//w w w . ja v a 2 s. c om * The combiner function is called once for each pair of objects found in the input streams. * @param <A> the type of the first stream * @param <B> the type of the second stream * @param <R> the type of the resulting stream * @param stream1 the first stream * @param stream2 the first stream * @param zipper the function used to combine the pair of objects * @return a stream of pairs, one from each stream */ private static <A, B, R> Stream<R> zip(Stream<A> stream1, Stream<B> stream2, BiFunction<A, B, R> zipper) { // this is private for now, to see if it is really needed on the API // it suffers from generics problems at the call site with common zipper functions // as such, it is less useful than it might seem Spliterator<A> split1 = stream1.spliterator(); Spliterator<B> split2 = stream2.spliterator(); // merged stream lacks some characteristics int characteristics = split1.characteristics() & split2.characteristics() & ~(Spliterator.DISTINCT | Spliterator.SORTED); long size = Math.min(split1.getExactSizeIfKnown(), split2.getExactSizeIfKnown()); Iterator<A> it1 = Spliterators.iterator(split1); Iterator<B> it2 = Spliterators.iterator(split2); Iterator<R> it = new Iterator<R>() { @Override public boolean hasNext() { return it1.hasNext() && it2.hasNext(); } @Override public R next() { return zipper.apply(it1.next(), it2.next()); } }; Spliterator<R> split = Spliterators.spliterator(it, size, characteristics); return StreamSupport.stream(split, false); }
From source file:net.morimekta.providence.maven.plugin.BaseGenerateSourcesMojo.java
boolean executeInternal(File outputDir, IncludeExcludeFileSelector files, String defaultInputIncludes, boolean testCompile) throws MojoExecutionException, MojoFailureException { Set<File> inputs = ProvidenceInput.getInputFiles(project, files, defaultInputIncludes); if (inputs.isEmpty()) { return false; }/* ww w . java2 s . c om*/ if (!outputDir.exists()) { if (!outputDir.mkdirs()) { throw new MojoExecutionException("Unable to create target directory " + outputDir); } } TreeSet<File> includes = new TreeSet<>(); File workingDir = new File(buildDir, testCompile ? "providence-test" : "providence"); File[] deleteFiles = workingDir.listFiles(); if (!workingDir.exists()) { if (!workingDir.mkdirs()) { throw new MojoExecutionException("Unable to create working directory " + workingDir); } } else if (deleteFiles != null) { StreamSupport.<File>stream( Spliterators.spliterator(deleteFiles, Spliterator.DISTINCT | Spliterator.IMMUTABLE), false) .forEach(File::delete); } Set<Artifact> resolvedArtifacts = new HashSet<>(); for (Dependency dep : dependencies) { dep.setType(ProvidenceAssemblyMojo.TYPE); if (dep.getClassifier() == null || dep.getClassifier().isEmpty()) { dep.setClassifier(ProvidenceAssemblyMojo.CLASSIFIER); } Artifact artifact = repositorySystem.createDependencyArtifact(dep); // Avoid resolving stuff we already have resolved. if (resolvedArtifacts.contains(artifact)) { continue; } ArtifactResolutionRequest request = new ArtifactResolutionRequest(); request.setLocalRepository(localRepository); request.setRemoteRepositories(remoteRepositories); request.setResolveTransitively(false); request.setArtifact(artifact); ArtifactResolutionResult result = artifactResolver.resolve(request); boolean found = false; for (Artifact resolved : result.getArtifacts()) { if (artifact.equals(resolved)) { resolvedArtifacts.add(resolved); addDependencyInclude(workingDir, includes, resolved); found = true; break; } } if (!found) { throw new MojoFailureException("Unable to resolve providence dependency: " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion() + ":" + artifact.getClassifier()); } } if (includeDirs != null) { DirectoryScanner includeScanner = new DirectoryScanner(); includeScanner.setIncludes(includeDirs.getIncludes()); if (includeDirs.getExcludes() != null) { includeScanner.setExcludes(includeDirs.getExcludes()); } includeScanner.setBasedir(project.getBasedir()); includeScanner.scan(); for (String dir : includeScanner.getIncludedDirectories()) { includes.add(new File(project.getBasedir(), dir)); } for (String dir : includeScanner.getExcludedDirectories()) { includes.remove(new File(project.getBasedir(), dir)); } } inputs.stream().map(File::getParentFile).forEach(includes::add); FileManager fileManager = new FileManager(outputDir); DocumentParser parser = new ThriftDocumentParser(); TypeLoader loader = new TypeLoader(includes, parser); LinkedList<CDocument> documents = new LinkedList<>(); for (File in : inputs) { try { documents.add(loader.load(in)); } catch (IOException e) { throw new MojoExecutionException("Failed to read thrift file: " + in.getName(), e); } catch (ParseException e) { getLog().warn(e.getMessage()); getLog().warn(".---------------------."); throw new MojoFailureException("Failed to parse thrift file: " + in.getName(), e); } } try { Generator generator; if (tiny) { TinyOptions options = new TinyOptions(); options.jackson = jackson; if (android) { throw new MojoExecutionException("Android option not compatible with 'tiny_java' variant."); } generator = new TinyGenerator(fileManager, loader.getRegistry(), options); } else { JOptions options = new JOptions(); options.android = android; if (jackson) { throw new MojoExecutionException("Jackson option not compatible with 'java' variant."); } generator = new JGenerator(fileManager, loader.getRegistry(), options); } for (CDocument doc : documents) { try { generator.generate(doc); } catch (IOException e) { throw new MojoExecutionException("Failed to write document: " + doc.getPackageName(), e); } catch (GeneratorException e) { getLog().warn(e.getMessage()); throw new MojoFailureException("Failed to generate document: " + doc.getPackageName(), e); } } } catch (GeneratorException e) { getLog().warn(e.getMessage()); throw new MojoFailureException("Failed to generate file: " + e.getMessage(), e); } return compileOutput; }
From source file:com.joyent.manta.client.MantaClient.java
/** * Return a stream of the contents of a directory in Manta. * * @param path The fully qualified path of the directory. * @return A {@link Stream} of {@link MantaObjectResponse} listing the contents of the directory. * @throws IOException thrown when there is a problem getting the listing over the network *//*from w ww . j a va2 s .c o m*/ public Stream<MantaObject> listObjects(final String path) throws IOException { final MantaDirectoryListingIterator itr = streamingIterator(path); /* We preemptively check the iterator for a next value because that will * trigger an error if the path doesn't exist or is otherwise inaccessible. * This error typically takes the form of an UncheckedIOException, so we * unwind that exception if the cause is a MantaClientHttpResponseException * and rethrow another MantaClientHttpResponseException, so that the * stacktrace will point to this running method. */ try { if (!itr.hasNext()) { itr.close(); return Stream.empty(); } } catch (UncheckedIOException e) { if (e.getCause() instanceof MantaClientHttpResponseException) { throw e.getCause(); } else { throw e; } } final int additionalCharacteristics = Spliterator.CONCURRENT | Spliterator.ORDERED | Spliterator.NONNULL | Spliterator.DISTINCT; Stream<Map<String, Object>> backingStream = StreamSupport .stream(Spliterators.spliteratorUnknownSize(itr, additionalCharacteristics), false); Stream<MantaObject> stream = backingStream.map(MantaObjectConversionFunction.INSTANCE).onClose(itr::close); danglingStreams.add(stream); return stream; }
From source file:org.dice_research.topicmodeling.io.test.AbstractCorpusIOTest.java
public void writeCorpus() { OutputStream out = null;//from www .ja va 2 s .c o m try { if (writer != null) { out = new BufferedOutputStream(new FileOutputStream(testFile)); writer.writeCorpus(corpus, out); } else if (consumer != null) { StreamSupport.stream(Spliterators.spliterator(corpus.iterator(), corpus.getNumberOfDocuments(), Spliterator.DISTINCT & Spliterator.NONNULL), false).forEach(consumer); } else { Assert.fail("Test is misconfigured since writer==null and consumer==null."); } } catch (Exception e) { e.printStackTrace(); Assert.fail("Got an Exception: " + e.getLocalizedMessage()); } finally { IOUtils.closeQuietly(out); if ((consumer != null) && (consumer instanceof Closeable)) { IOUtils.closeQuietly((Closeable) consumer); } } }
From source file:org.dice_research.topicmodeling.io.test.AbstractCorpusIOTest.java
public Corpus readCorpus() { InputStream in = null;//from ww w . j a va 2 s . co m try { if (reader != null) { in = new BufferedInputStream(new FileInputStream(testFile)); reader.readCorpus(in); return reader.getCorpus(); } else if (supplier != null) { return new DocumentListCorpus<List<Document>>(StreamSupport .stream(Spliterators.spliteratorUnknownSize(new DocumentSupplierAsIterator(supplier), Spliterator.DISTINCT & Spliterator.NONNULL), false) .collect(Collectors.toList())); } else { Assert.fail("Test is misconfigured since reader==null and supplier==null."); } } catch (Exception e) { e.printStackTrace(); Assert.fail("Got an Exception: " + e.getLocalizedMessage()); } finally { IOUtils.closeQuietly(in); } return null; }