Skip to content

Commit

Permalink
#343 Parameterize logger call
Browse files Browse the repository at this point in the history
and clean up surrounding code
  • Loading branch information
ascheman committed Sep 19, 2024
1 parent 2a8f2cb commit 7a867d9
Showing 1 changed file with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@
import java.util.stream.Collectors;

/**
* abstract factory to create Checker instances
* Factory to create Checker instances
*/
public class CheckerCreator {
private static final Logger logger = LoggerFactory.getLogger(CheckerCreator.class);

public static List<Checker> createCheckerClassesFrom(final List<Class<? extends Checker>> checkerClasses, final Configuration configuration) {
private CheckerCreator() {
}

public static List<Checker> createCheckerClassesFrom(final List<Class<? extends Checker>> checkerClasses,
final Configuration configuration) {

return checkerClasses.stream()
.map(checkerClass -> CheckerCreator.createSingleChecker(checkerClass, configuration))
Expand All @@ -27,31 +31,35 @@ private static boolean isCase(Class<? extends Checker> caseValue, Class<? extend
return false;
}

public static Checker createSingleChecker(final Class<? extends Checker> checkerClass, final Configuration pConfig) {
Checker checker;
public static Checker createSingleChecker(final Class<? extends Checker> checkerClass,
final Configuration configuration) {
if (null == checkerClass) {
throw new UnknownCheckerException("Checker Class must not be 'null'");
}

Checker checker;
// switch over all possible Checker classes
// in case of new Checkers, this has to be adapted,
// as Checker constructors will differ in minor details!

// clearly violates the open-close principle

if (isCase(BrokenCrossReferencesChecker.class, checkerClass)) {
checker = new BrokenCrossReferencesChecker(pConfig);
checker = new BrokenCrossReferencesChecker(configuration);
} else if (isCase(BrokenHttpLinksChecker.class, checkerClass)) {
checker = new BrokenHttpLinksChecker(pConfig);
checker = new BrokenHttpLinksChecker(configuration);
} else if (isCase(DuplicateIdChecker.class, checkerClass)) {
checker = new DuplicateIdChecker(pConfig);
checker = new DuplicateIdChecker(configuration);
} else if (isCase(ImageMapChecker.class, checkerClass)) {
checker = new ImageMapChecker(pConfig);
checker = new ImageMapChecker(configuration);
} else if (isCase(MissingAltInImageTagsChecker.class, checkerClass)) {
checker = new MissingAltInImageTagsChecker(pConfig);
checker = new MissingAltInImageTagsChecker(configuration);
} else if (isCase(MissingImageFilesChecker.class, checkerClass)) {
checker = new MissingImageFilesChecker(pConfig);
checker = new MissingImageFilesChecker(configuration);
} else if (isCase(MissingLocalResourcesChecker.class, checkerClass)) {
checker = new MissingLocalResourcesChecker(pConfig);
checker = new MissingLocalResourcesChecker(configuration);
} else {
logger.warn("unknown Checker " + checkerClass.toString());
logger.error("unknown Checker {}", checkerClass);
throw new UnknownCheckerException(checkerClass.toString());
}

Expand Down

0 comments on commit 7a867d9

Please sign in to comment.