Example usage for org.apache.commons.collections.set ListOrderedSet decorate

List of usage examples for org.apache.commons.collections.set ListOrderedSet decorate

Introduction

In this page you can find the example usage for org.apache.commons.collections.set ListOrderedSet decorate.

Prototype

public static ListOrderedSet decorate(List list) 

Source Link

Document

Factory method to create an ordered set using the supplied list to retain order.

Usage

From source file:org.axonframework.common.TestUtils.java

@SuppressWarnings({ "unchecked" })
public static <T> Set<T> setOf(T... items) {
    return ListOrderedSet.decorate(Arrays.asList(items));
}

From source file:org.axonframework.eventhandling.saga.SagaManagerTest.java

@SuppressWarnings({ "unchecked" })
private <T> Set<T> setOf(T... items) {
    return ListOrderedSet.decorate(Arrays.asList(items));
}

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 w  w  w  . j ava  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 w w w  .  ja va2s.com
            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.jahia.services.importexport.ImportExportBaseService.java

private void importSiteProperties(JahiaSite site, Properties p, JCRSessionWrapper session) {
    Set<Object> keys = p.keySet();
    final Set<String> languages = new HashSet<String>();
    final Set<String> inactiveLanguages = new HashSet<String>();
    final Set<String> inactiveLiveLanguages = new HashSet<String>();
    final Set<String> mandatoryLanguages = new HashSet<String>();

    List<String> installedModules = site.getInstalledModules();
    try {/*  w  ww. j  a v  a  2 s.c  om*/
        // site.getInstalledModules() may return outdated data
        installedModules = sitesService.getSiteByKey(site.getSiteKey(), session).getInstalledModules();
    } catch (RepositoryException e) {
        logger.error("Cannot get installed modules ", e);
    }

    String templateSet = site.getTemplateFolder();
    JahiaTemplateManagerService templateManagerService = ServicesRegistry.getInstance()
            .getJahiaTemplateManagerService();
    try {
        if (!installedModules.contains(templateSet)) {
            templateManagerService.installModule(
                    templateManagerService.getAnyDeployedTemplatePackage(templateSet),
                    "/sites/" + site.getSiteKey(), session);
        }
    } catch (RepositoryException e) {
        logger.error("Cannot deploy module " + templateSet, e);
    }

    String defaultLanguage = null;
    String lowestRankLanguage = null;
    int currentRank = 0;

    List<JahiaTemplatesPackage> modules = new ArrayList<JahiaTemplatesPackage>();

    for (Object key : keys) {
        String property = (String) key;
        String value = p.getProperty(property);
        StringTokenizer st = new StringTokenizer(property, ".");
        String firstKey = st.nextToken();

        try {
            if (firstKey.equals("language")) {
                String lang = st.nextToken();

                if (!languages.contains(lang)) {
                    languages.add(lang);
                    if (!Boolean.valueOf(p.getProperty("language." + lang + ".activated", "true"))) {
                        inactiveLiveLanguages.add(lang);
                    }
                    if (Boolean.valueOf(p.getProperty("language." + lang + ".disabledCompletely", "false"))) {
                        inactiveLanguages.add(lang);
                        languages.remove(lang);
                    }
                    if (Boolean.valueOf(p.getProperty("language." + lang + ".mandatory", "false"))) {
                        mandatoryLanguages.add(lang);
                    }
                    if (!inactiveLanguages.contains(lang) && (StringUtils.isEmpty(lowestRankLanguage)
                            || p.containsKey("language." + lang + ".rank"))) {
                        int langRank = NumberUtils.toInt(p.getProperty("language." + lang + ".rank"));
                        if (currentRank == 0 || langRank < currentRank) {
                            currentRank = langRank;
                            lowestRankLanguage = lang;
                        }
                    }
                }
            } else if (firstKey.equals("defaultLanguage")) {
                defaultLanguage = value;
            } else if (firstKey.equals("mixLanguage")) {
                site.setMixLanguagesActive(Boolean.parseBoolean(value));
            } else if (firstKey.equals("allowsUnlistedLanguages")) {
                site.setAllowsUnlistedLanguages(Boolean.parseBoolean(value));
            } else if (firstKey.equals("description")) {
                site.setDescription(value);
            } else if (firstKey.startsWith("defaultSite") && "true".equals(value)
                    && sitesService.getDefaultSite(session) == null) {
                sitesService.setDefaultSite(site, session);
            } else if (firstKey.equals("installedModules")) {
                if (!installedModules.contains(value) && !templateSet.equals(value)) {
                    JahiaTemplatesPackage pkg = templateManagerService.getAnyDeployedTemplatePackage(value);
                    if (pkg != null) {
                        modules.add(pkg);
                    } else {
                        logger.info("unable to find module {} in deployed modules", value);
                    }
                }
            }
        } catch (RepositoryException e) {
            logger.error("Cannot set site property  " + firstKey, e);
        }
    }

    @SuppressWarnings("unchecked")
    Set<String> siteLangs = ListOrderedSet.decorate(new LinkedList<String>(languages));
    if (!siteLangs.isEmpty()) {
        site.setLanguages(siteLangs);
        site.setInactiveLanguages(inactiveLanguages);
        site.setInactiveLiveLanguages(inactiveLiveLanguages);
        site.setMandatoryLanguages(mandatoryLanguages);
        if (defaultLanguage == null) {
            defaultLanguage = StringUtils.isEmpty(lowestRankLanguage) ? siteLangs.iterator().next()
                    : lowestRankLanguage;
        }
        site.setDefaultLanguage(defaultLanguage);
        /*try {
        JahiaSite jahiaSite = sitesService.getSiteByKey(JahiaSitesService.SYSTEM_SITE_KEY,session);
        // update the system site only if it does not yet contain at least one of the site languages
        Set<String> jahiaSiteLanguages = new HashSet<String>(jahiaSite.getLanguages());
        if (!jahiaSiteLanguages.containsAll(site.getLanguages())) {
            jahiaSiteLanguages.addAll(site.getLanguages());
            jahiaSite.setLanguages(jahiaSiteLanguages);
        }
        sitesService.updateSystemSitePermissions(jahiaSite, session);
        } catch (RepositoryException e) {
        logger.error("Cannot update system site", e);
        }*/
    } else {
        logger.error(
                "Unable to find site languages in the provided site.properties descriptor. Skip importing site settings.");
    }

    try {
        templateManagerService.installModules(modules, "/sites/" + site.getSiteKey(), session);

        session.save();
    } catch (RepositoryException e) {
        logger.error("Cannot deploy module " + modules, e);
    }

}