📄 proputils.java
字号:
* does. If it doesn't end in a period, add one, and then return that. The * returned string should be good for prepending to other properties. */ public static String getScopedPropertyPrefix(String pre) { if (pre == null || pre.length() == 0) { return ""; } else if (pre.endsWith(".")) { return pre; } else { return pre + "."; } } /** * Should be called by a PropertyConsumer in the * getPropertiesInfo(Properties) method to create a property marker name for * a custom PropertyEditor that will modify several top-level properties, * i.e. the com.bbn.openmap.omGraphics.DrawingAttributesPropertyEditor. * * @param realComponentPropertyPrefix the top-level prefix that the * PropertyConsumer being set with the properties has. Can be null. * @param anyDesiredScoper an additional scoping mechanism if there are more * than one custom editors being used for a given getPropertyInfo * call. * @return The string that is used for a marker for a custom editor. */ public static String getDummyMarkerForPropertyInfo( String realComponentPropertyPrefix, String anyDesiredScoper) { return DUMMY_MARKER_NAME + (anyDesiredScoper != null ? anyDesiredScoper : "") + "." + (realComponentPropertyPrefix != null ? realComponentPropertyPrefix : ""); } /** * Should be used inside a * PropertyConsumerPropertyEditor.setProperties(String, Properties) method * to set the real property prefix. The PropertyConsumer that the Inspector * is looking at should use the getDummyMarker() call to create the marker * for the getPropertyInfor(Properties) call. * * @param possibleDummyMarker * @return the encoded 'real' property prefix for the PropertyConsumer * embedded in the dummy marker, or the possibleDummyMarker if it's * not a dummy marker. */ public static String decodeDummyMarkerFromPropertyInfo( String possibleDummyMarker) { if (possibleDummyMarker != null && possibleDummyMarker.startsWith(DUMMY_MARKER_NAME)) { int lastDot = possibleDummyMarker.lastIndexOf("."); if (lastDot != -1) { possibleDummyMarker = possibleDummyMarker.substring(lastDot + 1); } } return possibleDummyMarker; } /** * It kills Properties to have null values set. You can wrap a property * value in this in PropertyConsumer.getProperties() to not worry about it. * Returns "" if prop == null, else returns what was passed in. */ public static String unnull(String prop) { if (prop == null) { return ""; } return prop; } /** * Takes a string of `;' separated paths and returns an array of parsed * strings. NOTE: this method currently doesn't support appropriate quoting * of the `;' character, although it probably should... * * @param p properties * @param propName the name of the property * @return Array of strings representing paths. */ public static String[] initPathsFromProperties(Properties p, String propName) { return initPathsFromProperties(p, propName, null); } /** * Takes a string of `;' separated paths and returns an array of parsed * strings. NOTE: this method currently doesn't support appropriate quoting * of the `;' character, although it probably should... * * @param p properties * @param propName the name of the property * @param defaultPaths the value of the paths to set if the property doesn't * exist, or if is doesn't contain anything. * @return Array of strings representing paths. */ public static String[] initPathsFromProperties(Properties p, String propName, String[] defaultPaths) { String[] ret = stringArrayFromProperties(p, propName, ";"); if (ret == null) { ret = defaultPaths; } return ret; } /** * Gets an integer out of a properties object. Returns the default value if * something goes wrong. * * @param p properties * @param propName name of the property associated with the wanted value. * @param defaultValue what to return if the property name doesn't exist, or * if the value isn't a numerical value. * @return integer value associated with the property. */ public static int intFromProperties(Properties p, String propName, int defaultValue) { int ret = defaultValue; String intString = p.getProperty(propName); if (intString != null) { try { ret = Integer.parseInt(intString.trim()); } catch (NumberFormatException e) { ret = defaultValue; } } return ret; } /** * Gets an float out of a properties object. Returns the default value if * something goes wrong. * * @param p properties * @param propName name of the property associated with the wanted value. * @param defaultValue what to return if the property name doesn't exist, or * if the value isn't a numerical value. * @return float value associated with the property. */ public static float floatFromProperties(Properties p, String propName, float defaultValue) { float ret = defaultValue; String floatString = p.getProperty(propName); if (floatString != null) { try { ret = Float.parseFloat(floatString.trim()); } catch (NumberFormatException e) { ret = defaultValue; } } return ret; } /** * Gets an boolean out of a properties object. Returns the default value if * something goes wrong. * * @param p properties * @param propName name of the property associated with the wanted value. * @param defaultValue what to return if the property name doesn't exist, or * if the value isn't a numerical value. * @return boolean value associated with the property. */ public static boolean booleanFromProperties(Properties p, String propName, boolean defaultValue) { boolean ret = defaultValue; String booleanString = p.getProperty(propName); if (booleanString != null) { ret = booleanString.trim().toLowerCase().equals("true"); } return ret; } /** * Creates an object out of a property name. If anything fails, return null. * * @param p properties * @param propName name of class to instantiate. * @return null on failure, otherwise, a default constructed instance of the * class named in the property. */ public static Object objectFromProperties(Properties p, String propName) { Object ret = null; String objectName = p.getProperty(propName); if (objectName != null) { ret = ComponentFactory.create(objectName); } return ret; } /** * Takes a string of representing token separated properties and returns an * array of parsed strings. NOTE: this method currently doesn't support * appropriate quoting of the token, although it probably should... * * @param p properties * @param propName the name of the property * @param tok the characters separating the strings. * @return Array of strings between the tokens. */ public static String[] stringArrayFromProperties(Properties p, String propName, String tok) { String[] ret = null; String raw = p.getProperty(propName); if (raw != null && raw.length() != 0) { try { StringTokenizer token = new StringTokenizer(raw, tok); int numPaths = token.countTokens(); ret = new String[numPaths]; for (int i = 0; i < numPaths; i++) { ret[i] = token.nextToken(); } return ret; } catch (java.util.NoSuchElementException e) { e.printStackTrace(); } } return ret; } /** * Gets a double out of a properties object. Returns the default value if * something goes wrong. * * @param p properties * @param propName name of the property associated with the wanted value. * @param defaultValue what to return if the property name doesn't exist, or * if the value isn't a numerical value. * @return double value associated with the property. */ public static double doubleFromProperties(Properties p, String propName, double defaultValue) { double ret = defaultValue; String doubleString = p.getProperty(propName); if (doubleString != null) { try { ret = Double.parseDouble(doubleString.trim()); } catch (NumberFormatException e) { ret = defaultValue; } } return ret; } /** * Gets a long out of a properties object. Returns the default value if * something goes wrong. * * @param p properties * @param propName name of the property associated with the wanted value. * @param defaultValue what to return if the property name doesn't exist, or * if the value isn't a numerical value. * @return long value associated with the property. */ public static long longFromProperties(Properties p, String propName, long defaultValue) { long ret = defaultValue; String longString = p.getProperty(propName); if (longString != null) { try {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -