cdc.issues.checks.AbstractIssueDetector Maven / Gradle / Ivy
package cdc.issues.checks;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import cdc.issues.rules.ConfiguredRule;
import cdc.issues.rules.Rule;
import cdc.util.lang.Checks;
public abstract class AbstractIssueDetector implements IssuesDetector {
protected final Factory factory;
protected final String project;
protected final String snapshot;
protected final Set enabledConfiguredRules;
protected final Set enabledRules;
protected AbstractIssueDetector(Factory factory,
String project,
String snapshot,
Set configuredRules) {
Checks.isNotNullOrEmpty(configuredRules, "configuredRules");
this.factory = Checks.isNotNull(factory, "factory");
this.project = project;
this.snapshot = snapshot;
this.enabledConfiguredRules = Collections.unmodifiableSet(new HashSet<>(configuredRules));
final Set rules = new HashSet<>();
for (final ConfiguredRule crule : configuredRules) {
if (!factory.getSupportedRules().contains(crule.getRule())) {
throw new IllegalArgumentException("Non supported rule");
}
rules.add(crule.getRule());
}
this.enabledRules = Collections.unmodifiableSet(rules);
}
@Override
public Factory getFactory() {
return factory;
}
@Override
public final String getProject() {
return project;
}
@Override
public final String getSnapshot() {
return snapshot;
}
@Override
public final Set getEnabledRules() {
return enabledRules;
}
@Override
public final Set getEnabledConfiguredRules() {
return enabledConfiguredRules;
}
@Override
public String toString() {
return IssuesDetector.toString(this);
}
}