Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package edu.stanford.nlp.util;
import java.io.IOException;
import java.io.PrintStream;
import java.io.StringReader;
import java.io.StringWriter;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.Map.Entry;
/** Utilities methods for standard (but woeful) Java Properties objects.
*
* @author Sarah Spikes
* @author David McClosky
*/
public class PropertiesUtils {
private PropertiesUtils() {}
/**
* Returns true iff the given Properties contains a property with the given
* key (name), and its value is not "false" or "no" or "off".
*
* @param props Properties object
* @param key The key to test
* @return true iff the given Properties contains a property with the given
* key (name), and its value is not "false" or "no" or "off".
*/
public static boolean hasProperty(Properties props, String key) {
String value = props.getProperty(key);
if (value == null) {
return false;
}
value = value.toLowerCase();
return ! (value.equals("false") || value.equals("no") || value.equals("off"));
}
/** Create a Properties object from the passed in String arguments.
* The odd numbered arguments are the names of keys, and the even
* numbered arguments are the value of the preceding key
*
* @param args An even-length list of alternately key and value
*/
public static Properties asProperties(String... args) {
if (args.length % 2 != 0) {
throw new IllegalArgumentException("Need an even number of arguments but there were " + args.length);
}
Properties properties = new Properties();
for (int i = 0; i < args.length; i += 2) {
properties.setProperty(args[i], args[i + 1]);
}
return properties;
}
/** Convert from Properties to String. */
public static String asString(Properties props) {
try {
StringWriter sw = new StringWriter();
props.store(sw, null);
return sw.toString();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
/** Convert from String to Properties. */
public static Properties fromString(String str) {
try {
StringReader sr = new StringReader(str);
Properties props = new Properties();
props.load(sr);
return props;
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
// printing -------------------------------------------------------------------
public static void printProperties(String message, Properties properties,
PrintStream stream) {
if (message != null) {
stream.println(message);
}
if (properties.isEmpty()) {
stream.println(" [empty]");
} else {
List> entries = getSortedEntries(properties);
for (Map.Entry entry : entries) {
if ( ! "".equals(entry.getKey())) {
stream.format(" %-30s = %s%n", entry.getKey(), entry.getValue());
}
}
}
stream.println();
}
public static void printProperties(String message, Properties properties) {
printProperties(message, properties, System.out);
}
/**
* Tired of Properties not behaving like {@code Map}s? This method will solve that problem for you.
*/
public static Map asMap(Properties properties) {
Map map = Generics.newHashMap();
for (Entry