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 com.databasesandlife.util;
import java.util.*;
/**
* Utility class for manipulating Properties objects, as if they were
* hierarchical objects. Lists can be created with .0. .1., etc, and key/value
* pairs can also be constructed.
*
* @author This source is copyright Adrian Smith and licensed under the LGPL 3.
* @see Project on GitHub
*/
public class PropertiesUtil {
protected static Hashtable propertiesForResouceName = new Hashtable<>();
/**
* Takes a prefix like "rules" and then finds "rules.0.x" etc, puts them
* into lots of Properties objects with keys like "x" and position 0 in
* the array. If prefix is "" then finds "0.x" etc.
*/
public static List splitToList(Properties p, String prefix) {
if ( ! prefix.equals("")) prefix += ".";
List propertiesForIndex = new ArrayList<>();
for (Enumeration> e = p.keys(); e.hasMoreElements(); ) {
String key = (String) e.nextElement();
if (! key.startsWith(prefix)) continue; // wrong prefix
String indexAndSubKey = key.substring(prefix.length());
int dotAfterIndex = indexAndSubKey.indexOf('.');
if (dotAfterIndex == -1) continue; // seems to have no "."
String indexStr = indexAndSubKey.substring(0, dotAfterIndex);
int index = Integer.parseInt(indexStr);
while (index >= propertiesForIndex.size()) propertiesForIndex.add(new Properties());
Properties propsThisIndex = propertiesForIndex.get(index);
String subKey = indexAndSubKey.substring(dotAfterIndex+1);
String value = p.getProperty(key);
propsThisIndex.setProperty(subKey, value);
}
return propertiesForIndex;
}
/**
* Takes a prefix like "rules" and then finds "rules.0.x" etc, puts them
* into lots of Properties objects with keys like "x" and position 0 in
* the array. If prefix is "" then finds "0.x" etc.
*/
public static Properties[] splitToArray(Properties p, String prefix) {
return splitToList(p, prefix).toArray(new Properties[0]);
}
/** Takes a prefix like "rules" and then finds "rules.name.key", puts
* them in a Hashtable of Property objects, where they keys are the
* strings like "name", and the values are Properties objects, from
* "key" to value. If prefix is "" then finds "name.key" etc.
* @return a Hashtable from String objects to Properties objects
* @deprecated use {@link #splitToMap(Properties,String)}
*/
public static Hashtable splitToHashtable(Properties p, String prefix) {
if ( ! prefix.equals("")) prefix += ".";
Hashtable propertiesForName = new Hashtable<>();
for (Enumeration