
com.github.dakusui.crest.matcherbuilders.ListMatcherBuilder Maven / Gradle / Ivy
package com.github.dakusui.crest.matcherbuilders;
import com.github.dakusui.crest.core.InternalUtils;
import com.github.dakusui.crest.functions.TransformingPredicate;
import com.github.dakusui.crest.utils.printable.Predicates;
import java.util.Collection;
import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toList;
public class ListMatcherBuilder> extends ObjectMatcherBuilder, SELF> {
protected ListMatcherBuilder(Function super IN, ? extends List> function) {
super(function);
}
public SELF containsAll(Collection> collection) {
return this.check(
new TransformingPredicate, Collection>>(
String.format("containsAll%s", InternalUtils.summarize(collection)),
Predicates.isEmpty(),
InternalUtils.function(
String.format("notCovered%s", InternalUtils.summarize(collection)),
objects -> collection.stream(
).filter(
each -> !objects.contains(each)
).collect(
toList()
))
)
);
}
public SELF containsOnly(Collection> collection) {
return this.check(
new TransformingPredicate, Collection>>(
String.format("containsOnly%s", InternalUtils.summarize(collection)),
Predicates.isEmpty(),
InternalUtils.function(
String.format("extra%s", InternalUtils.summarize(collection)),
objects -> objects.stream(
).filter(
each -> !collection.contains(each)
).collect(
toList()
))
)
);
}
public SELF containsExactly(Collection> collection) {
return this.check(
new TransformingPredicate, Collection>>(
String.format("containsExactly%s", InternalUtils.summarize(collection)),
Predicates.isEmpty(),
InternalUtils.function(
String.format("difference%s", InternalUtils.summarize(collection)),
objects -> Stream.concat(
objects.stream(), collection.stream()
).filter(
each -> !(collection.contains(each) && objects.contains(each))
).collect(
toList()
))
)
);
}
public SELF containsNone(Collection> collection) {
return this.check(
new TransformingPredicate, Collection>>(
String.format("containsNone%s", InternalUtils.summarize(collection)),
Predicates.isEmpty(),
InternalUtils.function(
String.format("contained%s", InternalUtils.summarize(collection)),
objects -> objects.stream(
).filter(
collection::contains
).collect(
toList()
))
)
);
}
public SELF contains(Object entry) {
return this.check(Predicates.contains(entry));
}
public SELF isEmpty() {
return this.check(Predicates.isEmpty());
}
public SELF allMatch(Predicate super ENTRY> predicate) {
return this.check(
InternalUtils.predicate(
String.format("allMatch[%s]", predicate),
entries -> entries.stream().allMatch(predicate)
));
}
public SELF anyMatch(Predicate super ENTRY> predicate) {
return this.check(
InternalUtils.predicate(
String.format("anyMatch[%s]", predicate),
entries -> entries.stream().anyMatch(predicate)
));
}
public SELF noneMatch(Predicate super ENTRY> predicate) {
return this.check(
InternalUtils.predicate(
String.format("noneMatch[%s]", predicate),
entries -> entries.stream().noneMatch(predicate)
));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy