Skip to content

Commit

Permalink
Add two new methods to ConfigUtils:
Browse files Browse the repository at this point in the history
Set<String> parseSimpleArrayAsSet(String configPrefix); and,
Set<String> parseSimpleArrayAsSet(Configuration configuration, String configPrefix)
  • Loading branch information
Nahshon Unna-Tsameret authored and Nahshon Unna-Tsameret committed Mar 10, 2020
1 parent c5bd171 commit 3e442f0
Showing 1 changed file with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@
import java.net.URISyntaxException;
import java.net.URL;
import java.text.DecimalFormatSymbols;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.*;
import java.util.regex.Pattern;

/**
Expand Down Expand Up @@ -217,6 +214,46 @@ public static Map<String, String> parseSimpleArrayAsMap(Configuration configurat
return result;
}

/**
* parse a simple array and return it as a Set.
* @param configPrefix the prefix that is the basis of the array. E.g.
*
* given:
*
* smartcardAdaptor.cardFeatures.23.sbmMSB.0=0x00
* smartcardAdaptor.cardFeatures.23.sbmMSB.1=0x01
*
* the config prefix will be:
* smartcardAdaptor.cardFeatures.23.sbmMSB
*
* @return the Set where a distinct list of values.
*/
public static Set<String> parseSimpleArrayAsSet(String configPrefix) {

Configuration configuration = ConfigurationFactory.getConfiguration();

return parseSimpleArrayAsSet(configuration, configPrefix);
}

public static Set<String> parseSimpleArrayAsSet(Configuration configuration, String configPrefix) {

Set<String> result = new HashSet<String>();

// get a subset of the configuration based on the config prefix.
final Configuration subset = configuration.subset(configPrefix);

@SuppressWarnings("unchecked")
final Iterator<String> keys = subset.getKeys();

while (keys.hasNext()) {

final String key = keys.next();
result.add(subset.getString(key));
}

return result;
}

/**
* create inner key map by taking what ever is after the first dot.
*
Expand Down

0 comments on commit 3e442f0

Please sign in to comment.