Widened.
This commit is contained in:
@@ -37,18 +37,17 @@ import com.samskivert.util.StringUtil;
|
||||
import com.threerings.getdown.Log;
|
||||
|
||||
/**
|
||||
* Parses a file containing key/value pairs and returns a {@link HashMap}
|
||||
* with the values. Keys may be repeated, in which case they will be made
|
||||
* to reference an array of values.
|
||||
* Parses a file containing key/value pairs and returns a {@link HashMap} with the values. Keys may
|
||||
* be repeated, in which case they will be made to reference an array of values.
|
||||
*/
|
||||
public class ConfigUtil
|
||||
{
|
||||
/**
|
||||
* Parses a configuration file containing key/value pairs. The file
|
||||
* must be in the UTF-8 encoding.
|
||||
* Parses a configuration file containing key/value pairs. The file must be in the UTF-8
|
||||
* encoding.
|
||||
*
|
||||
* @return a list of <code>String[]</code> instances containing the
|
||||
* key/value pairs in the order they were parsed from the file.
|
||||
* @return a list of <code>String[]</code> instances containing the key/value pairs in the
|
||||
* order they were parsed from the file.
|
||||
*/
|
||||
public static List<String[]> parsePairs (File config, boolean checkPlatform)
|
||||
throws IOException
|
||||
@@ -61,8 +60,7 @@ public class ConfigUtil
|
||||
FileInputStream fin = null;
|
||||
try {
|
||||
fin = new FileInputStream(config);
|
||||
BufferedReader bin =
|
||||
new BufferedReader(new InputStreamReader(fin, "UTF-8"));
|
||||
BufferedReader bin = new BufferedReader(new InputStreamReader(fin, "UTF-8"));
|
||||
String line = null;
|
||||
while ((line = bin.readLine()) != null) {
|
||||
// nix comments
|
||||
@@ -103,14 +101,12 @@ public class ConfigUtil
|
||||
platform = platform.substring(1);
|
||||
if (osname.indexOf(platform) != -1) {
|
||||
Log.info("Skipping [platform=!" + platform +
|
||||
", key=" + pair[0] +
|
||||
", value=" + pair[1] + "].");
|
||||
", key=" + pair[0] + ", value=" + pair[1] + "].");
|
||||
continue;
|
||||
}
|
||||
} else if (osname.indexOf(platform) == -1) {
|
||||
Log.info("Skipping [platform=" + platform +
|
||||
", key=" + pair[0] +
|
||||
", value=" + pair[1] + "].");
|
||||
", key=" + pair[0] + ", value=" + pair[1] + "].");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -128,23 +124,21 @@ public class ConfigUtil
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a configuration file containing key/value pairs. The file
|
||||
* must be in the UTF-8 encoding.
|
||||
* Parses a configuration file containing key/value pairs. The file must be in the UTF-8
|
||||
* encoding.
|
||||
*
|
||||
* @return a map from keys to values, where a value will be an array
|
||||
* of strings if more than one key/value pair in the config file was
|
||||
* associated with the same key.
|
||||
* @return a map from keys to values, where a value will be an array of strings if more than
|
||||
* one key/value pair in the config file was associated with the same key.
|
||||
*/
|
||||
public static HashMap<String, Object> parseConfig (File config,
|
||||
boolean checkPlatform)
|
||||
public static HashMap<String, Object> parseConfig (File config, boolean checkPlatform)
|
||||
throws IOException
|
||||
{
|
||||
List<String[]> pairs = parsePairs(config, checkPlatform);
|
||||
HashMap<String, Object> data = new HashMap<String, Object>();
|
||||
|
||||
// I thought that we could use HashMap<String, String[]> and put
|
||||
// new String[] {pair[1]} for the null case, but it mysteriously dies
|
||||
// on launch, so leaving it as HashMap<String, Object> for now
|
||||
// I thought that we could use HashMap<String, String[]> and put new String[] {pair[1]} for
|
||||
// the null case, but it mysteriously dies on launch, so leaving it as HashMap<String,
|
||||
// Object> for now
|
||||
for (Iterator iter = pairs.iterator(); iter.hasNext(); ) {
|
||||
String[] pair = (String[])iter.next();
|
||||
Object value = data.get(pair[0]);
|
||||
@@ -165,9 +159,8 @@ public class ConfigUtil
|
||||
}
|
||||
|
||||
/**
|
||||
* Massages a single string into an array and leaves existing array
|
||||
* values as is. Simplifies access to parameters that are expected to
|
||||
* be arrays.
|
||||
* Massages a single string into an array and leaves existing array values as is. Simplifies
|
||||
* access to parameters that are expected to be arrays.
|
||||
*/
|
||||
public static String[] getMultiValue (HashMap data, String name)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user