📄 projectconfig.java
字号:
public boolean appendConfigStream(InputStream configFileStream) throws IOException { return appendConfigStream(myConfig, configFileStream); } private static boolean appendConfigStream(Properties currentValues, InputStream configFileStream) throws IOException { // Read from stream Properties newProps = new Properties(); newProps.load(configFileStream); configFileStream.close(); // Read new properties Enumeration en = newProps.keys(); while (en.hasMoreElements()) { String key = (String) en.nextElement(); String property = newProps.getProperty(key); if (property.startsWith("+ ")) { if (currentValues.getProperty(key) != null) { currentValues.setProperty(key, currentValues.getProperty(key) + " " + property.substring(1).trim()); } else { currentValues.setProperty(key, property.substring(1).trim()); } } else { currentValues.setProperty(key, property); } } return true; } /** * @return All property names in configuration */ public Enumeration<String> getPropertyNames() { return (Enumeration<String>) myConfig.propertyNames(); } /** * Get string value with given id. * * @param callingClass * Class which value belongs to * @param id * Id of value to return * @param defaultValue * Default value to return if id is not found * @return Value or defaultValue if id wasn't found */ public String getStringValue(Class callingClass, String id, String defaultValue) { return getStringValue(myConfig, callingClass, id, defaultValue); } private static String getStringValue(Properties currentValues, Class callingClass, String id, String defaultValue) { String val = currentValues.getProperty(callingClass.getName() + "." + id); if (val == null) { /*logger.warn("Could not find key named '" + callingClass.getName() + "." + id + "'");*/ return defaultValue; } return val; } /** * Returns value of given name. * * @param name * Name * @return Value as string */ public String getStringValue(String name) { if (!myConfig.containsKey(name)) { logger.debug("Could not find key named '" + name + "'"); } return myConfig.getProperty(name); } /** * Get string value with given id. * * @param callingClass * Class which value belongs to * @param id * Id of value to return * @return Value or null if id wasn't found */ public String getStringValue(Class callingClass, String id) { return getStringValue(callingClass, id, null); } /** * Get string array value with given id. * * @param callingClass * Class which value belongs to * @param id * Id of value to return * @return Value or null if id wasn't found */ public String[] getStringArrayValue(Class callingClass, String id) { String stringVal = getStringValue(callingClass, id, null); if (stringVal == null) { return new String[0]; } return getStringValue(callingClass, id, "").split(" "); } /** * Get string value with given id. * * @param callingClass * Class which value belongs to * @param id * Id of value to return * @return Value or null if id wasn't found */ public String getValue(Class callingClass, String id) { return getStringValue(callingClass, id); } /** * Get string array value with given id. * * @param id * Id of value to return * @return Value or null if id wasn't found */ public String[] getStringArrayValue(String id) { String stringVal = getStringValue(id); if (stringVal == null) { return new String[0]; } return getStringValue(id).split(" "); } /** * Get integer value with given id. * * @param callingClass * Class which value belongs to * @param id * Id of value to return * @param defaultValue * Default value to return if id is not found * @return Value or defaultValue if id wasn't found */ public int getIntegerValue(Class callingClass, String id, int defaultValue) { String str = getStringValue(callingClass, id); if (str == null) { return defaultValue; } return Integer.parseInt(str); } /** * Get integer value with given id. * * @param callingClass * Class which value belongs to * @param id * Id of value to return * @return Value or 0 if id wasn't found */ public int getIntegerValue(Class callingClass, String id) { return getIntegerValue(callingClass, id, 0); } /** * Get double value with given id. * * @param callingClass * Class which value belongs to * @param id * Id of value to return * @param defaultValue * Default value to return if id is not found * @return Value or defaultValue if id wasn't found */ public double getDoubleValue(Class callingClass, String id, double defaultValue) { String str = getStringValue(callingClass, id); if (str == null) { return defaultValue; } return Double.parseDouble(str); } /** * Get double value with given id. * * @param callingClass * Class which value belongs to * @param id * Id of value to return * @return Value or 0.0 if id wasn't found */ public double getDoubleValue(Class callingClass, String id) { return getDoubleValue(callingClass, id, 0.0); } /** * Get boolean value with given id. * * @param callingClass * Class which value belongs to * @param id * Id of value to return * @param defaultValue * Default value to return if id is not found * @return Value or defaultValue if id wasn't found */ public boolean getBooleanValue(Class callingClass, String id, boolean defaultValue) { String str = getStringValue(callingClass, id); if (str == null) { return defaultValue; } return Boolean.parseBoolean(str); } /** * Get boolean value with given id. * * @param callingClass * Class which value belongs to * @param id * Id of value to return * @return Value or false if id wasn't found */ public boolean getBooleanValue(Class callingClass, String id) { return getBooleanValue(callingClass, id, false); } public ProjectConfig clone() { try { ProjectConfig clone = new ProjectConfig(false); clone.myConfig = (Properties) this.myConfig.clone(); clone.myProjectDirHistory = (Vector<File>) this.myProjectDirHistory.clone(); return clone; } catch (Exception e) { return null; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -