Created
February 22, 2013 22:15
-
-
Save bernardoVale/5016977 to your computer and use it in GitHub Desktop.
Isso?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RulesProject { | |
private static ResourceBundle projectFileList = ResourceBundle | |
.getBundle("utfpr.edu.br.ex2.projectFileList"); | |
private static Map<String,String> propertiesMap = buildPropertiesMap(projectFileList); | |
public static boolean validateFiles(Object bean, Field field) { | |
return hasValue(ValidatorUtils.getValueAsString(bean, field.getProperty())); | |
} | |
/** | |
* Create a specific Hash map of local ResourceBundle | |
* used by default constructor to populate the properties file | |
* @return 'Map<String,String>' | |
*/ | |
private static Map<String,String> buildPropertiesMap(ResourceBundle bundle){ | |
Map<String,String> propertiesMap = new HashMap<String, String>(); | |
//Get keys | |
Set<String> keys = bundle.keySet(); | |
for(String key : keys){ | |
propertiesMap.put(key,getValue(key)); | |
} | |
return propertiesMap; | |
} | |
/** | |
* Get Property Value of | |
* @param key | |
* @return String value | |
*/ | |
private static String getValue(String key){ | |
return projectFileList.getString(key); | |
} | |
/** | |
* Search for a '@param value' on properties file | |
* @return Boolean result of search | |
*/ | |
private static boolean hasValue(String value){ | |
for (Map.Entry<String, String> stringStringEntry : propertiesMap.entrySet()) { | |
Map.Entry pairs = (Map.Entry) stringStringEntry; | |
if (pairs.getValue().equals(value)) return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment