Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add two new methods to ConfigUtils: #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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