org.kiwiproject.util.regex.MatcherSpliterator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kiwi Show documentation
Show all versions of kiwi Show documentation
Kiwi is a utility library. We really like Google's Guava, and also use Apache Commons.
But if they don't have something we need, and we think it is useful, this is where we put it.
package org.kiwiproject.util.regex;
import static java.util.Objects.requireNonNull;
import java.util.Spliterators;
import java.util.function.Consumer;
import java.util.regex.MatchResult;
import java.util.regex.Matcher;
/**
* A simple {@link java.util.Spliterator} over a {@link Matcher}.
*/
public class MatcherSpliterator extends Spliterators.AbstractSpliterator {
private final Matcher matcher;
public MatcherSpliterator(Matcher matcher) {
super(Long.MAX_VALUE, ORDERED | NONNULL | IMMUTABLE);
this.matcher = matcher;
}
@Override
public boolean tryAdvance(Consumer super MatchResult> action) {
requireNonNull(action, "action cannot be null");
if (!matcher.find()) {
return false;
}
action.accept(matcher.toMatchResult());
return true;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy