List of usage examples for org.apache.commons.collections.set ListOrderedSet asList
public List asList()
From source file:com.nextep.designer.beng.services.BENGServices.java
/** * Retrieves the container (modules) on which depend the specified one. Used by the build engine * to determine dependent deliveries./*from w w w. j ava2 s . co m*/ * * @param c the container for which the dependencies will be retrieved * @return the containers on which the specified container depend */ @SuppressWarnings("unchecked") public static List<IVersionContainer> getContainerDependencies(IVersionContainer c) { ListOrderedSet dependencies = new ListOrderedSet(); // Retrieving the reference map of our current container Map<IReference, IReferenceable> containerRefMap = VersionHelper.getVersionable(c).getReferenceMap(); // We browse all versionable of our container for (IVersionable<?> v : c.getContents()) { // For each of them we retrieve the loose dependencies Collection<IReference> references = v.getReferenceDependencies(); for (IReference r : references) { // If the remote dependency is not from our container we save it if (!containerRefMap.containsKey(r)) { IReferenceable instance = VersionHelper.getReferencedItem(r); if (instance instanceof IVersionable) { final IVersionable<?> versionedDependency = (IVersionable<?>) instance; if (!versionedDependency.getContainer().equals(c)) { dependencies.add(versionedDependency.getContainer()); } } } } } return (List<IVersionContainer>) dependencies.asList(); }
From source file:com.nextep.designer.beng.services.impl.DeliveryService.java
@SuppressWarnings("unchecked") @Override//from ww w . j a va2s . co m public List<IVersionInfo> buildDependencies(List<IVersionInfo> processed, IDeliveryModule module) { IVersionInfo moduleRelease = module.getTargetRelease(); if (processed.contains(moduleRelease)) { return Collections.EMPTY_LIST; } else { processed.add(moduleRelease); } // FIXME transform the collection to IVersionable<IVersionContainer> // collection ListOrderedSet containers = new ListOrderedSet(); // containers.addAll(getContainerDependencies(moduleContainer)); for (IVersionInfo vc : module.getDependencies()) { containers.add(vc); } for (IVersionInfo c : new ArrayList<IVersionInfo>(containers)) { final IDeliveryModule depModule = loadDelivery(c); if (depModule != null) { containers.addAll(0, buildDependencies(processed, depModule)); } else { throw new ErrorException(BengMessages.getString("missingDependentDelivery")); //$NON-NLS-1$ } } // containers.add(moduleRelease); return containers.asList(); }
From source file:org.encuestame.persistence.dao.imp.AccountDaoImp.java
public List<UserAccount> getPublicProfiles(final String keyword, final Integer maxResults, final Integer startOn) { final List<UserAccount> searchResult = (List<UserAccount>) getHibernateTemplate() .execute(new HibernateCallback() { public Object doInHibernate(org.hibernate.Session session) { List<UserAccount> searchResult = new ArrayList<UserAccount>(); long start = System.currentTimeMillis(); final Criteria criteria = session.createCriteria(UserAccount.class); //only shared profiles. criteria.add(Restrictions.eq("sharedProfile", Boolean.TRUE)); // limit results if (maxResults != null) { criteria.setMaxResults(maxResults.intValue()); }//from www . j a va 2s . c o m // start on page x if (startOn != null) { criteria.setFirstResult(startOn.intValue()); } searchResult = (List<UserAccount>) fetchMultiFieldQueryParserFullText(keyword, new String[] { "completeName, username" }, UserAccount.class, criteria, new SimpleAnalyzer()); final List listAllSearch = new LinkedList(); listAllSearch.addAll(searchResult); // Fetch result by phrase final List<UserAccount> phraseFullTestResult = (List<UserAccount>) fetchPhraseFullText( keyword, "completeName", UserAccount.class, criteria, new SimpleAnalyzer()); log.debug("phraseFullTestResult:{" + phraseFullTestResult.size()); listAllSearch.addAll(phraseFullTestResult); // Fetch result by wildcard final List<UserAccount> wildcardFullTextResult = (List<UserAccount>) fetchWildcardFullText( keyword, "completeName", UserAccount.class, criteria, new SimpleAnalyzer()); log.debug("wildcardFullTextResult:{" + wildcardFullTextResult.size()); listAllSearch.addAll(wildcardFullTextResult); // Fetch result by prefix final List<UserAccount> prefixQueryFullTextResuslts = (List<UserAccount>) fetchPrefixQueryFullText( keyword, "completeName", UserAccount.class, criteria, new SimpleAnalyzer()); log.debug("prefixQueryFullTextResuslts:{" + prefixQueryFullTextResuslts.size()); listAllSearch.addAll(prefixQueryFullTextResuslts); // Fetch fuzzy results final List<UserAccount> fuzzyQueryFullTextResults = (List<UserAccount>) fetchFuzzyQueryFullText( keyword, "completeName", UserAccount.class, criteria, new SimpleAnalyzer(), SIMILARITY_VALUE); log.debug("fuzzyQueryFullTextResults: {" + fuzzyQueryFullTextResults.size()); listAllSearch.addAll(fuzzyQueryFullTextResults); log.debug("listAllSearch size:{" + listAllSearch.size()); // removing duplcates final ListOrderedSet totalResultsWithoutDuplicates = ListOrderedSet .decorate(new LinkedList()); totalResultsWithoutDuplicates.addAll(listAllSearch); /* * Limit results if is enabled. */ List<UserAccount> totalList = totalResultsWithoutDuplicates.asList(); if (maxResults != null && startOn != null) { log.debug("split to " + maxResults + " starting on " + startOn + " to list with size " + totalList.size()); totalList = totalList.size() > maxResults ? totalList.subList(startOn, maxResults) : totalList; } long end = System.currentTimeMillis(); log.debug("UserAccount{ totalResultsWithoutDuplicates:{" + totalList.size() + " items with search time:" + (end - start) + " milliseconds"); return totalList; } }); return searchResult; }
From source file:org.encuestame.persistence.dao.imp.CommentDao.java
@SuppressWarnings("unchecked") public List<Comment> getCommentsByKeyword(final String keyword, final Integer maxResults, final Long[] excludes) { log.info("keyword " + keyword); List<Comment> searchResult = (List) getHibernateTemplate().execute(new HibernateCallback() { @SuppressWarnings("deprecation") public Object doInHibernate(org.hibernate.Session session) { List<Comment> searchResult = new ArrayList<Comment>(); long start = System.currentTimeMillis(); final Criteria criteria = session.createCriteria(Comment.class); // limit results if (maxResults != null) { criteria.setMaxResults(maxResults.intValue()); }/*from ww w . j a v a 2s . co m*/ if (excludes != null && excludes.length > 0) { for (int i = 0; i < excludes.length; i++) { log.debug("excluding hashtag... " + excludes[i]); criteria.add(Restrictions.ne("commentId", excludes[i])); } } searchResult = (List<Comment>) fetchMultiFieldQueryParserFullText(keyword, new String[] { "comment" }, Comment.class, criteria, new SimpleAnalyzer()); final List<Comment> listAllSearch = new LinkedList<Comment>(); listAllSearch.addAll(searchResult); // Fetch result by phrase final List<Comment> phraseFullTestResult = (List<Comment>) fetchPhraseFullText(keyword, "comment", Comment.class, criteria, new SimpleAnalyzer()); log.debug("phraseFullTestResult comment:{" + phraseFullTestResult.size()); listAllSearch.addAll(phraseFullTestResult); // Fetch result by wildcard final List<Comment> wildcardFullTextResult = (List<Comment>) fetchWildcardFullText(keyword, "comment", Comment.class, criteria, new SimpleAnalyzer()); log.debug("wildcardFullTextResult comment:{" + wildcardFullTextResult.size()); listAllSearch.addAll(wildcardFullTextResult); // Fetch result by prefix final List<Comment> prefixQueryFullTextResuslts = (List<Comment>) fetchPrefixQueryFullText(keyword, "comment", Comment.class, criteria, new SimpleAnalyzer()); log.debug("prefixQueryFullTextResuslts comment:{" + prefixQueryFullTextResuslts.size()); listAllSearch.addAll(prefixQueryFullTextResuslts); // Fetch fuzzy results final List<Comment> fuzzyQueryFullTextResults = (List<Comment>) fetchFuzzyQueryFullText(keyword, "comment", Comment.class, criteria, new SimpleAnalyzer(), SIMILARITY_VALUE); log.debug("fuzzyQueryFullTextResults comment: {" + fuzzyQueryFullTextResults.size()); listAllSearch.addAll(fuzzyQueryFullTextResults); log.debug("listAllSearch size:{" + listAllSearch.size()); // removing duplcates final ListOrderedSet totalResultsWithoutDuplicates = ListOrderedSet.decorate(new LinkedList()); totalResultsWithoutDuplicates.addAll(listAllSearch); /* * Limit results if is enabled. */ List<Comment> totalList = totalResultsWithoutDuplicates.asList(); if (maxResults != null) { log.debug("split to " + maxResults + " to list with size " + totalList.size()); totalList = totalList.size() > maxResults ? totalList.subList(0, maxResults) : totalList; } long end = System.currentTimeMillis(); //log.debug("HashTag{ totalResultsWithoutDuplicates:{" // + totalList.size() + " items with search time:" // + (end - start) + " milliseconds"); return totalList; } }); return searchResult; }
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// w ww .ja v a 2s .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(); }