List of usage examples for java.util Collections checkedList
public static <E> List<E> checkedList(List<E> list, Class<E> type)
From source file:Main.java
public static void main(String args[]) { List<String> arlst = new ArrayList<String>(); arlst.add("A"); arlst.add("B"); arlst.add("C"); arlst.add("from java2s.com"); // create typesafe view of the list List<String> tslst = Collections.checkedList(arlst, String.class); System.out.println(tslst);//from www .j a v a 2 s .c o m }
From source file:Main.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public static <T> void checkedAtRuntime(List<T> list, Class<T> clazz, Object data) { List tryToAddNotTStuff = Collections.checkedList(list, clazz); try {//from w w w. j a va2s. c o m tryToAddNotTStuff.add(data); } catch (ClassCastException e) { System.out.println("can't add data different that expected"); } System.out.println(tryToAddNotTStuff); }
From source file:document_search.MultiQuerySearch.java
public static List<MultiQueryResults> search(Index i, int docLimit, String searchField, Analyzer a, String... queries) {//from w ww .j av a 2 s . c o m ParseWrapper parser = new ParseWrapper(new QueryParser(searchField, a)); // Parse all available results List<QueryPair> queryList = Arrays.asList(queries).stream().map(parser::parseQuery) .filter(query -> query != null).collect(Collectors.toList()); // Create the overall query BooleanQuery query = new BooleanQuery(); for (QueryPair pair : queryList) { query.add(pair.query, BooleanClause.Occur.SHOULD); } // FIXME: We should not have index searchers here, but we still do! :-( Fuck Lucene and its vast plots of, features... IndexSearcher searcher = new IndexSearcher(i.getIndexer().getReader()); // TODO: Refactor this because it looks terrible, functional style is better, but the functional isn't good... List<MultiQueryResults> queryResults = Collections.checkedList(new ArrayList<>(), MultiQueryResults.class); for (Index.IndexDocument doc : i.runQuery(query, docLimit)) { // Create new multi query results MultiQueryResults results = new MultiQueryResults(doc.id, doc.score, Arrays.asList(queries)); // Explain the individual query results for (QueryPair queryPair : queryList) { try { double score = searcher.explain(queryPair.query, doc.lucene_id).getValue(); QueryResults individualResults = new QueryResults(doc.id, queryPair.term, score); results.addQueryResult(individualResults); } catch (IOException e) { e.printStackTrace(); } } // Add the Multi-query results to the overall list queryResults.add(results); } return queryResults; }
From source file:org.sventon.web.ctrl.template.FlattenController.java
@Override protected ModelAndView svnHandle(final SVNConnection connection, final BaseCommand command, final long headRevision, final UserRepositoryContext userRepositoryContext, final HttpServletRequest request, final HttpServletResponse response, final BindException exception) throws Exception { final List<DirEntry> entries = Collections.checkedList(new ArrayList<DirEntry>(), DirEntry.class); logger.debug("Flattening directories below: " + command.getPath()); entries.addAll(getCache().findDirectories(command.getName(), command.getPath())); logger.debug(entries.size() + " entries found"); final Map<String, Object> model = new HashMap<String, Object>(); logger.debug("Sort params: " + userRepositoryContext.getSortType().name() + ", " + userRepositoryContext.getSortMode()); new DirEntrySorter(userRepositoryContext.getSortType(), userRepositoryContext.getSortMode()).sort(entries); model.put("dirEntries", entries); model.put("isFlatten", true); // Indicates that path should be shown in browser view. return new ModelAndView(getViewName(), model); }
From source file:indexer.Index.java
public List<IndexDocument> runQuery(Query q, int maxResults) { IndexReader reader = getIndexer().getReader(); IndexSearcher searcher = new IndexSearcher(reader); try {/*from w w w . j a v a 2s . c o m*/ TopDocs docs = searcher.search(q, maxResults); return Arrays.asList(docs.scoreDocs).stream().map(s -> { try { int uniqueId = Integer.parseInt(reader.document(s.doc).get(IndexerFields.ID.name())); return new IndexDocument(uniqueId, s.doc, s.score); } catch (IOException e) { log.error("Error while converting document", e); return null; } }).filter(d -> d != null).collect(Collectors.toList()); } catch (IOException e) { log.error("There was an error while attempting a search.", e); return Collections.checkedList(new ArrayList<>(), IndexDocument.class); } }
From source file:es.upm.fiware.rss.dao.impl.ObCountryDaoImpl.java
/** * //from w w w. j a v a2 s. c o m * @param hql * @return */ private List<BmObCountry> listObCountryQuery(final String hql) { ObCountryDaoImpl.LOGGER.debug(hql); List<BmObCountry> list = this.getSession().createQuery(hql).list(); List<BmObCountry> resultList = Collections.checkedList(list, BmObCountry.class); return resultList; }
From source file:org.openeos.jbpm.integration.internal.dao.JbpmProcessInstanceDAOHibernateImpl.java
@Override @Transactional(readOnly = true)/*from w ww . j ava 2 s . c o m*/ public List<JbpmProcessInstance> findByEventType(String eventType) { Criteria crit = getSession().createCriteria(JbpmProcessInstance.class); crit.createCriteria(JbpmProcessInstance.PROPERTY_EVENT_TYPE_LIST) .add(Restrictions.eq(JbpmProcessInstanceEventType.PROPERTY_EVENT_TYPE, eventType)); return Collections.checkedList(crit.list(), JbpmProcessInstance.class); }
From source file:es.upm.fiware.rss.dao.impl.DbeAppProviderDaoImpl.java
@Override public List<DbeAppProvider> getProvidersByAggregator(String aggregatorId) { String hql = "from DbeAppProvider as p where p.id.aggregator='" + aggregatorId + "'"; List<DbeAppProvider> resultList; try {//from ww w. j a v a2 s . c om List list = this.getSession().createQuery(hql).list(); resultList = Collections.checkedList(list, DbeAppProvider.class); } catch (Exception e) { return null; } return resultList; }
From source file:es.upm.fiware.rss.dao.impl.SharingReportDaoImpl.java
@Override public List<SharingReport> getSharingReportsByParameters(String aggregator, String providerId, String productClass) {/* w w w . jav a2s .com*/ // Build queries String hql = "from SharingReport l"; if (null != aggregator && !aggregator.isEmpty()) { hql += " where l.owner.id.aggregator.txEmail= '" + aggregator + "'"; if (null != providerId && !providerId.isEmpty()) { hql += " and l.owner.id.txAppProviderId= '" + providerId + "'"; if (null != productClass && !productClass.isEmpty()) { hql += " and l.productClass= '" + productClass + "'"; } } } List<SharingReport> resultList; try { List list = this.getSession().createQuery(hql).list(); resultList = Collections.checkedList(list, SharingReport.class); } catch (Exception e) { return null; } if (null == resultList || resultList.isEmpty()) { resultList = null; } return resultList; }
From source file:org.sventon.web.ctrl.template.SearchEntriesController.java
@Override protected ModelAndView svnHandle(final SVNConnection connection, final BaseCommand command, final long headRevision, final UserRepositoryContext userRepositoryContext, final HttpServletRequest request, final HttpServletResponse response, final BindException exception) throws Exception { final String searchString = ServletRequestUtils.getRequiredStringParameter(request, SEARCH_STRING_PARAMETER);/*from www. j a v a2 s . c o m*/ final String startDir = ServletRequestUtils.getRequiredStringParameter(request, START_DIR_PARAMETER); final Map<String, Object> model = new HashMap<String, Object>(); logger.debug("Searching cache for [" + searchString + "] in directory [" + startDir + "]"); final List<DirEntry> entries = Collections.checkedList(new ArrayList<DirEntry>(), DirEntry.class); if (CamelCasePattern.isValid(searchString)) { logger.debug("Search string was in upper case only - performing CamelCase cache search"); entries.addAll(getCache().findEntriesByCamelCase(command.getName(), new CamelCasePattern(searchString), startDir)); model.put("searchType", SearchType.CAMELCASE); } else { entries.addAll(getCache().findEntries(command.getName(), searchString, startDir)); model.put("searchType", SearchType.TEXT); } if (logger.isDebugEnabled()) { logger.debug("Sort params: " + userRepositoryContext.getSortType().name() + ", " + userRepositoryContext.getSortMode()); } new DirEntrySorter(userRepositoryContext.getSortType(), userRepositoryContext.getSortMode()).sort(entries); model.put("dirEntries", entries); model.put("searchString", searchString); model.put("locks", getRepositoryService().getLocks(connection, command.getPath(), false)); model.put("startDir", startDir); model.put("isEntrySearch", true); // Indicates that path should be shown in browser view. return new ModelAndView(getViewName(), model); }