nl.vpro.domain.api.MatcherList Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of api-domain Show documentation
Show all versions of api-domain Show documentation
Contains the objects used by the Frontend API, like forms and result objects
package nl.vpro.domain.api;
import java.util.Iterator;
import java.util.List;
import javax.xml.bind.annotation.XmlAttribute;
import org.checkerframework.checker.nullness.qual.NonNull;
/**
* Represents a list of {@link Matcher}, itself being a Matcher again.
* @author Michiel Meeuwissen
* @since 2.8
*/
public abstract class MatcherList> implements Iterable, Matcher {
public static final Match DEFAULT_MATCH = Match.MUST;
@XmlAttribute
protected Match match = DEFAULT_MATCH;
protected MatcherList() {
}
protected MatcherList(Match m) {
this.match = m == null ? this.match : m;
}
@Override
public Match getMatch() {
return match;
}
public abstract List asList();
@NonNull
@Override
public Iterator iterator() {
return asList().iterator();
}
// cannot implement List because that'll confuse jaxb
public int size() {
return asList().size();
}
public boolean isEmpty() {
return asList().isEmpty();
}
// cannot implement List because that'll confuse jaxb
public T get(int index) {
return asList().get(index);
}
@Override
public String toString() {
return match + ":" + (asList() == null ? "null" : asList().toString());
}
@Override
public boolean test(V s) {
boolean hasShould = false;
boolean shouldResult = false;
for(T t : this) {
boolean match = t.test(s);
switch(t.getMatch()) {
case NOT:
// fall through
case MUST:
if (! match) {
return false;
}
break;
case SHOULD:
hasShould = true;
shouldResult |= match;
break;
}
}
return ! hasShould || shouldResult;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy