All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cloud.localstack.docker.command.RegexStream Maven / Gradle / Ivy

The newest version!
package cloud.localstack.docker.command;

import java.util.Spliterator;
import java.util.function.Consumer;
import java.util.regex.Matcher;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

public class RegexStream {

    private final MatcherSpliterator matcherSpliterator;

    public RegexStream(Matcher matcher) {
        this.matcherSpliterator = new MatcherSpliterator(matcher);
    }

    public Stream stream(){
        return StreamSupport.stream(matcherSpliterator, false);
    }


    private class MatcherSpliterator implements Spliterator {

        private final Matcher matcher;
        public MatcherSpliterator(Matcher matcher) {
            this.matcher = matcher;
        }

        @Override
        public boolean tryAdvance(Consumer action) {
            boolean found = matcher.find();
            if(found) {
                action.accept(matcher);
            }
            return found;
        }

        @Override
        public Spliterator trySplit() {
            return null;
        }

        @Override
        public long estimateSize() {
            return 0;
        }

        @Override
        public int characteristics() {
            return 0;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy