com.danielsomerfield.cvecheck.gradle.handlers.buildRules.ListBackedBuildRules.groovy Maven / Gradle / Ivy
package com.danielsomerfield.cvecheck.gradle.handlers.buildRules
class ListBackedBuildRules implements BuildRules {
private List addedRules = []
private List defaultRules = []
ListBackedBuildRules(List defaultRules = []) {
this.defaultRules = defaultRules;
}
@Override
void addBuildRule(final BuildRule rule) {
addedRules.add(rule)
}
@Override
public void each(Closure closure) {
getRules().each closure
}
@Override
public Collection map(final Closure closure) {
getRules().collect(closure)
}
@Override
int size() {
getRules().size()
}
BuildRule get(int index) {
return getRules().get(index)
}
private List getRules() {
addedRules.empty ? defaultRules : addedRules
}
@Override
public String toString() {
return "ListBackedBuildRules{" +
"addedRules=" + addedRules +
", defaultRules=" + defaultRules +
'}';
}
}