Example usage for java.util Spliterator IMMUTABLE

List of usage examples for java.util Spliterator IMMUTABLE

Introduction

In this page you can find the example usage for java.util Spliterator IMMUTABLE.

Prototype

int IMMUTABLE

To view the source code for java.util Spliterator IMMUTABLE.

Click Source Link

Document

Characteristic value signifying that the element source cannot be structurally modified; that is, elements cannot be added, replaced, or removed, so such changes cannot occur during traversal.

Usage

From source file:Main.java

/**
 * Converts an {@link java.util.Iterator} to {@link java.util.stream.Stream}.
 *///from   ww  w . j  a va2s.co  m
public static <T> Stream<T> iterate(Iterator<? extends T> iterator) {
    int characteristics = Spliterator.ORDERED | Spliterator.IMMUTABLE;
    return StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, characteristics), false);
}

From source file:com.simiacryptus.mindseye.applications.HadoopUtil.java

/**
 * To stream stream./*from  www  .j av  a  2 s.  co m*/
 *
 * @param <T>            the type parameter
 * @param remoteIterator the remote iterator
 * @return the stream
 */
@Nonnull
public static <T> Stream<T> toStream(final RemoteIterator<T> remoteIterator) {
    return StreamSupport.stream(Spliterators.spliterator(new Iterator<T>() {
        @Override
        public boolean hasNext() {
            try {
                return remoteIterator.hasNext();
            } catch (Throwable e) {
                logger.warn("Error listing files", e);
                return false;
            }
        }

        @Override
        public T next() {
            try {
                return remoteIterator.next();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }, -1, Spliterator.IMMUTABLE), true);
}

From source file:com.steelbridgelabs.oss.neo4j.Neo4JTestGraphProvider.java

@Override
public Map<String, Object> getBaseConfiguration(String graphName, Class<?> test, String testMethodName,
        LoadGraphWith.GraphData graphData) {
    // build configuration
    Configuration configuration = Neo4JGraphConfigurationBuilder.connect("localhost", "neo4j", "123")
            .withName(graphName).withElementIdProvider(ElementIdProvider.class).build();
    // create property map from configuration
    Map<String, Object> map = StreamSupport
            .stream(Spliterators.spliteratorUnknownSize(configuration.getKeys(),
                    Spliterator.NONNULL | Spliterator.IMMUTABLE), false)
            .collect(Collectors.toMap(key -> key, configuration::getProperty));
    // append class name
    map.put(Graph.GRAPH, Neo4JGraph.class.getName());
    // return configuration map
    return map;/*from   w  w  w .j  a v  a2s.com*/
}

From source file:net.dv8tion.jda.core.utils.cache.impl.AbstractCacheView.java

@Override
public Spliterator<T> spliterator() {
    return Spliterators.spliterator(elements.values(), Spliterator.IMMUTABLE);
}

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;
    }//from   w w w. ja  va2s.c  o  m

    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:org.apache.tinkerpop.gremlin.process.traversal.Traversal.java

/**
 * Return the traversal as a {@link Stream}.
 *
 * @return the traversal as a stream./* w ww. jav  a2s  .co m*/
 */
public default Stream<E> toStream() {
    return StreamSupport.stream(
            Spliterators.spliteratorUnknownSize(this, Spliterator.IMMUTABLE | Spliterator.SIZED), false);
}