Mercurial > hg > thermostat-ng > agent
changeset 2774:4592c11860e4
Fix code violations pointed out by PMD plugin
author | Miloslav Zezulka <mzezulka@redhat.com> |
---|---|
date | Mon, 09 Oct 2017 15:34:47 +0200 |
parents | 4f12f8ffdc9b |
children | a4d9e2b10254 |
files | common/test/src/main/java/com/redhat/thermostat/testutils/StubBundleContext.java launcher/src/main/java/com/redhat/thermostat/launcher/internal/BuiltInCommandInfo.java |
diffstat | 2 files changed, 33 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/common/test/src/main/java/com/redhat/thermostat/testutils/StubBundleContext.java Wed Oct 18 15:15:19 2017 -0400 +++ b/common/test/src/main/java/com/redhat/thermostat/testutils/StubBundleContext.java Mon Oct 09 15:34:47 2017 +0200 @@ -285,20 +285,31 @@ for (ServiceInformation info : registeredServices) { for (String serviceInterface : (String[]) info.properties.get(Constants.OBJECTCLASS)) { - if (clazz == null || serviceInterface.equals(clazz)) { - if (toMatch == null || toMatch.match(info.properties)) { - toReturn.add(new StubServiceReference(info, contextBundle)); - } + if(suitableForServiceReference(clazz, serviceInterface, toMatch, info.properties)) { + toReturn.add(new StubServiceReference(info, contextBundle)); } } } - if (toReturn.size() == 0) { + if (toReturn.isEmpty()) { return null; } return toReturn.toArray(new ServiceReference[0]); } - + + private boolean suitableForServiceReference(String clazz, String serviceInterface, + Filter toMatch, Dictionary dictionary) { + return serviceClassMatchesOrEmpty(clazz, serviceInterface) + && satisfiesFilter(toMatch, dictionary); + } + + private boolean serviceClassMatchesOrEmpty(String clazz, String serviceInterface) { + return clazz == null || clazz.equals(serviceInterface); + } + + private boolean satisfiesFilter(Filter toMatch, Dictionary dictionary) { + return toMatch == null || toMatch.match(dictionary); + } @Override public Filter createFilter(String filter) throws InvalidSyntaxException {
--- a/launcher/src/main/java/com/redhat/thermostat/launcher/internal/BuiltInCommandInfo.java Wed Oct 18 15:15:19 2017 -0400 +++ b/launcher/src/main/java/com/redhat/thermostat/launcher/internal/BuiltInCommandInfo.java Mon Oct 09 15:34:47 2017 +0200 @@ -288,15 +288,8 @@ // Conflicts not interpreted as override detected. private boolean optionConflictsWithCommonOptions(Option option, Options options) { for (Option o : (Collection<Option>) options.getOptions()) { - if (optionConflictsWithOption(option, o)) { - /* As a special case, if these things are not defined we do not consider - * this to be a conflict. This will instead be treated as an override, - * specifically for the "required" property of the common option. - * Grep for "secret sauce" to find other relevant snippets in this class. - */ - if (option.getOpt() != null || option.getDescription() != null) { - return true; - } + if (optionConflictsWithOptionAllowOverride(option, o)) { + return true; } } return false; @@ -328,6 +321,20 @@ } return false; } + + + private boolean optionConflictsWithOptionAllowOverride(Option o1, Option o2) { + return optionConflictsWithOption(o1, o2) && optionDefined(o1); + } + + /* As a special case, if these things are not defined we do not consider + * this to be a conflict. This will instead be treated as an override, + * specifically for the "required" property of the common option. + * Grep for "secret sauce" to find other relevant snippets in this class. + */ + private boolean optionDefined(Option o) { + return o.getOpt() != null || o.getDescription() != null; + } private void throwConflictingOption(Option option) { // Throwing this to catch issues during development. Not intended as a