List of usage examples for org.apache.commons.collections.set ListOrderedSet ListOrderedSet
public ListOrderedSet()
ListOrderedSet
using a HashSet
and an ArrayList
internally. From source file:org.openmrs.util.databasechange.ConceptValidatorChangeSet.java
/** * Retrieves the list of allowed locales from the database, sets the default locale, english and * the default locale will be added to the list allowed locales if not yet included * * @param connection The database connection * @return A list of allowed locales/*from ww w .j a v a2 s . c o m*/ */ @SuppressWarnings("unchecked") private List<Locale> getAllowedLocalesList(JdbcConnection connection) { Statement stmt = null; ListOrderedSet allowedLocales = new ListOrderedSet(); try { //get the default locale stmt = connection.createStatement(); ResultSet rs_defaultLocale = stmt .executeQuery("SELECT property_value FROM global_property WHERE property = '" + OpenmrsConstants.GLOBAL_PROPERTY_DEFAULT_LOCALE + "'"); if (rs_defaultLocale.next()) { String defaultLocaleStr = rs_defaultLocale.getString("property_value"); if (!StringUtils.isBlank(defaultLocaleStr) && defaultLocaleStr.length() > 1) { Locale defaultLocale_GP = LocaleUtility.fromSpecification(defaultLocaleStr); if (defaultLocale_GP != null) { defaultLocale = defaultLocale_GP; } } else { updateWarnings.add("'" + defaultLocaleStr + "' is an invalid value for the global property default locale"); } } allowedLocales.add(defaultLocale); //get the locale.allowed.list ResultSet rs_allowedLocales = stmt .executeQuery("SELECT property_value FROM global_property WHERE property = '" + OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST + "'"); if (rs_allowedLocales.next()) { String allowedLocaleStr = rs_allowedLocales.getString("property_value"); if (!StringUtils.isBlank(allowedLocaleStr)) { String[] localesArray = allowedLocaleStr.split(","); for (String localeStr : localesArray) { if (localeStr.trim().length() > 1) { allowedLocales.add(LocaleUtility.fromSpecification(localeStr.trim())); } else { updateWarnings.add("'" + localeStr + "' is an invalid value for the global property locale.allowed.list"); } } } } else { log.warn("The global property '" + OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST + "' isn't set"); } } catch (DatabaseException e) { log.warn("Error generated", e); } catch (SQLException e) { log.warn("Error generated", e); } finally { if (stmt != null) { try { stmt.close(); } catch (SQLException e) { log.warn("Failed to close the statement object"); } } } //if it isn't among allowedLocales.add(new Locale("en")); return allowedLocales.asList(); }
From source file:org.springjutsu.validation.rules.ValidationRulesContainer.java
/** * Copy rules from parent classes into child classes. *//* w w w . j av a2 s.c o m*/ @SuppressWarnings("unchecked") protected void initInheritance() { Set<Class<?>> inheritanceChecked = new HashSet<Class<?>>(); for (ValidationEntity entity : validationEntityMap.values()) { Stack<Class<?>> classStack = new Stack<Class<?>>(); classStack.push(entity.getValidationClass()); for (Class<?> clazz = entity.getValidationClass().getSuperclass(); clazz != null && clazz != Object.class; clazz = clazz.getSuperclass()) { classStack.push(clazz); } Set<ValidationRule> inheritableRules = new ListOrderedSet(); Set<ValidationTemplateReference> inheritableTemplateReferences = new ListOrderedSet(); Set<ValidationContext> inheritableContexts = new ListOrderedSet(); Set<String> inheritableExclusionPaths = new HashSet<String>(); Set<String> inheritableInclusionPaths = new HashSet<String>(); while (!classStack.isEmpty()) { Class<?> clazz = classStack.pop(); if (supportsClass(clazz) && !inheritanceChecked.contains(clazz)) { validationEntityMap.get(clazz).getRules().addAll(inheritableRules); validationEntityMap.get(clazz).getValidationContexts().addAll(inheritableContexts); validationEntityMap.get(clazz).getExcludedPaths().addAll(inheritableExclusionPaths); validationEntityMap.get(clazz).getIncludedPaths().addAll(inheritableInclusionPaths); validationEntityMap.get(clazz).getTemplateReferences().addAll(inheritableTemplateReferences); } if (hasRulesForClass(clazz)) { inheritableRules.addAll(validationEntityMap.get(clazz).getRules()); } if (supportsClass(clazz)) { inheritableContexts.addAll(validationEntityMap.get(clazz).getValidationContexts()); inheritableExclusionPaths.addAll(validationEntityMap.get(clazz).getExcludedPaths()); inheritableInclusionPaths.addAll(validationEntityMap.get(clazz).getIncludedPaths()); } inheritanceChecked.add(clazz); } } }