Skip to content

Instantly share code, notes, and snippets.

@bernardoVale
Created February 22, 2013 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bernardoVale/5016977 to your computer and use it in GitHub Desktop.
Save bernardoVale/5016977 to your computer and use it in GitHub Desktop.
Isso?
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