Skip to content

Commit

Permalink
Applied skeletal implementation to interface migration automated refa…
Browse files Browse the repository at this point in the history
…ctoring.

Used methods from both concrete and abstract classes as input. There was one manual change reversal due to an implementation stemming from a unit test that was too test specific.
  • Loading branch information
Raffi Khatchadourian committed Jul 18, 2016
1 parent b7d444d commit e939d8c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 24 deletions.
10 changes: 9 additions & 1 deletion bootique/src/main/java/com/nhl/bootique/cli/Cli.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,15 @@ public interface Cli {
* @throws RuntimeException
* if there's more then one value for the option.
*/
String optionString(String name);
default String optionString(String name) {
List<String> allStrings = optionStrings(name);

if (allStrings.size() > 1) {
throw new RuntimeException("More than one value specified for option: " + name);
}

return allStrings.isEmpty() ? null : allStrings.get(0);
}

/**
* Returns all arguments that are not options or option values in the order
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ public Map<String, String> subproperties(String prefix) {
return filterByPrefix(properties, prefix, ".");
}

@Override
public Map<String, String> frameworkProperties() {
return subproperties(FRAMEWORK_PROPERTIES_PREFIX);
}

@Override
public String getVariable(String name) {
return variables.get(name);
Expand All @@ -60,11 +55,6 @@ public Map<String, String> variables(String prefix) {
return filterByPrefix(variables, prefix, "_");
}

@Override
public Map<String, String> frameworkVariables() {
return variables(FRAMEWORK_VARIABLES_PREFIX);
}

protected Map<String, String> filterByPrefix(Map<String, String> unfiltered, String prefix, String separator) {
String lPrefix = prefix.endsWith(separator) ? prefix : prefix + separator;
int len = lPrefix.length();
Expand Down
11 changes: 9 additions & 2 deletions bootique/src/main/java/com/nhl/bootique/env/Environment.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.nhl.bootique.env;

import static com.nhl.bootique.env.DefaultEnvironment.FRAMEWORK_PROPERTIES_PREFIX;
import static com.nhl.bootique.env.DefaultEnvironment.FRAMEWORK_VARIABLES_PREFIX;

import java.util.Map;

/**
Expand Down Expand Up @@ -28,7 +31,9 @@ public interface Environment {
*
* @return a map of all properties that start with "bq." prefix.
*/
Map<String, String> frameworkProperties();
default Map<String, String> frameworkProperties() {
return subproperties(FRAMEWORK_PROPERTIES_PREFIX);
}

/**
* Returns a value of the environment variable with a given name.
Expand Down Expand Up @@ -58,5 +63,7 @@ public interface Environment {
* @since 0.17
* @return a map of all variables that start with "BQ_" prefix.
*/
Map<String, String> frameworkVariables();
default Map<String, String> frameworkVariables() {
return variables(FRAMEWORK_VARIABLES_PREFIX);
}
}
11 changes: 0 additions & 11 deletions bootique/src/main/java/com/nhl/bootique/jopt/JoptCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,6 @@ public List<String> optionStrings(String name) {
return optionSet.valuesOf(name).stream().map(o -> String.valueOf(o)).collect(toList());
}

@Override
public String optionString(String name) {
List<String> allStrings = optionStrings(name);

if (allStrings.size() > 1) {
throw new RuntimeException("More than one value specified for option: " + name);
}

return allStrings.isEmpty() ? null : allStrings.get(0);
}

@SuppressWarnings("unchecked")
@Override
public List<String> standaloneArguments() {
Expand Down

0 comments on commit e939d8c

Please sign in to comment.