Author: tchemit Date: 2011-01-18 08:06:31 +0100 (Tue, 18 Jan 2011) New Revision: 2020 Url: http://nuiton.org/repositories/revision/nuiton-utils/2020 Log: improve ApplicationConfig code Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfig.java Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfig.java =================================================================== --- trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfig.java 2011-01-18 06:51:43 UTC (rev 2019) +++ trunk/nuiton-utils/src/main/java/org/nuiton/util/ApplicationConfig.java 2011-01-18 07:06:31 UTC (rev 2020) @@ -587,14 +587,17 @@ this.value = value; } + protected <T> List<T> convertListOption(Class<T> type) { + List<T> result= (List<T>) config.convertOption(type, key, value, true); + return result; + } /** * Get option value as {@link String}. * * @return value as String */ public List<String> getOption() { - List<String> result = (List<String>)config.convertOption( - String.class, key, value, true); + List<String> result = convertListOption(String.class); return result; } @@ -604,8 +607,7 @@ * @return value as file */ public List<File> getOptionAsFile() { - List<File> tmp = (List<File>)config.convertOption( - File.class, key, value, true); + List<File> tmp = convertListOption(File.class); List<File> result = new ArrayList<File>(tmp.size()); for (File file : tmp) { result.add(file.getAbsoluteFile()); @@ -619,8 +621,7 @@ * @return value as URL */ public List<URL> getOptionAsURL() { - List<URL> result = (List<URL>)config.convertOption( - URL.class, key, value, true); + List<URL> result = convertListOption(URL.class); return result; } @@ -630,8 +631,7 @@ * @return value as Class */ public List<Class> getOptionAsClass() { - List<Class> result = (List<Class>)config.convertOption( - Class.class, key, value, true); + List<Class> result = convertListOption(Class.class); return result; } @@ -641,8 +641,7 @@ * @return value as Date */ public List<Date> getOptionAsDate() { - List<Date> result = (List<Date>)config.convertOption( - Date.class, key, value, true); + List<Date> result = convertListOption(Date.class); return result; } @@ -652,8 +651,7 @@ * @return value as Time */ public List<Time> getOptionAsTime() { - List<Time> result = (List<Time>)config.convertOption( - Time.class, key, value, true); + List<Time> result = convertListOption(Time.class); return result; } @@ -663,8 +661,7 @@ * @return value as Timestamp */ public List<Timestamp> getOptionAsTimestamp() { - List<Timestamp> result = (List<Timestamp>)config.convertOption( - Timestamp.class, key, value, true); + List<Timestamp> result = convertListOption(Timestamp.class); return result; } @@ -674,8 +671,7 @@ * @return value as {@code int} */ public List<Integer> getOptionAsInt() { - List<Integer> result = (List<Integer>)config.convertOption( - Integer.class, key, value, true); + List<Integer> result = convertListOption(Integer.class); return result; } @@ -685,8 +681,7 @@ * @return value as {@code double} */ public List<Double> getOptionAsDouble() { - List<Double> result = (List<Double>)config.convertOption( - Double.class, key, value, true); + List<Double> result = convertListOption(Double.class); return result; } @@ -696,8 +691,7 @@ * @return value as {@code boolean}. */ public List<Boolean> getOptionAsBoolean() { - List<Boolean> result = (List<Boolean>)config.convertOption( - Boolean.class, key, value, true); + List<Boolean> result = convertListOption(Boolean.class); return result; } } @@ -723,11 +717,11 @@ * method is automaticaly called * * @param configFilename name of wikitty config file + * @throws ArgumentsParserException */ public ApplicationConfig(String configFilename) throws ArgumentsParserException { this(); - parse(new String[]{ - "--option", ApplicationConfig.CONFIG_FILE_NAME, configFilename}); + parse("--option", CONFIG_FILE_NAME, configFilename); } /** @@ -751,7 +745,7 @@ * Get user home directory (system property {@code user.home}). * @return user home directory */ - static public String getUserHome() { + public static String getUserHome() { String result = System.getProperty("user.home"); return result; } @@ -895,7 +889,7 @@ } /** - * Add action to list of action to do + * Add action to list of action to do. * * @param action action to add, can be null. */ @@ -955,7 +949,7 @@ /** * Add alias for action. This method put just -- front the actionMethod and - * call {@link #addAlias(String, String...)} + * call {@link #addAlias(String, String...)}. * * @param alias the alias to add for the given method action * @param actionMethod must be fully qualified method path: @@ -967,7 +961,7 @@ /** * Set name of file where options are read (in /etc, $HOME, $CURDIR) - * This set used {@link #setDefaultOption(String, String)} + * This set used {@link #setDefaultOption(String, String)}. * * @param name file name */ @@ -978,6 +972,7 @@ /** * Get name of file where options are read (in /etc, $HOME, $CURDIR). + * * @return name of file */ public String getConfigFileName() { @@ -1293,9 +1288,12 @@ * @param key option key * @param value value to convert * @param asList value is string that represente a list - * @return + * @return the converted option in the required type */ - protected <T> Object convertOption(Class<T> clazz, String key, String value, boolean asList) { + protected <T> Object convertOption(Class<T> clazz, + String key, + String value, + boolean asList) { String cacheKey = key + "-" + asList + "-" + clazz.getName(); int hash = 0;
participants (1)
-
tchemit@users.nuiton.org