List of usage examples for org.apache.commons.collections IteratorUtils filteredIterator
public static Iterator filteredIterator(Iterator iterator, Predicate predicate)
From source file:com.github.liyp.test.TestMain.java
@SuppressWarnings("unchecked") public static void main(String[] args) { // add a shutdown hook to stop the server Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override// w w w . j a v a2 s.co m public void run() { System.out.println("########### shoutdown begin...."); try { Thread.sleep(10000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("########### shoutdown end...."); } })); System.out.println(args.length); Iterator<String> iterator1 = IteratorUtils .arrayIterator(new String[] { "one", "two", "three", "11", "22", "AB" }); Iterator<String> iterator2 = IteratorUtils.arrayIterator(new String[] { "a", "b", "c", "33", "ab", "aB" }); Iterator<String> chainedIter = IteratorUtils.chainedIterator(iterator1, iterator2); System.out.println("=================="); Iterator<String> iter = IteratorUtils.filteredIterator(chainedIter, new Predicate() { @Override public boolean evaluate(Object arg0) { System.out.println("xx:" + arg0.toString()); String str = (String) arg0; return str.matches("([a-z]|[A-Z]){2}"); } }); while (iter.hasNext()) { System.out.println(iter.next()); } System.out.println("==================="); System.out.println("asas".matches("[a-z]{4}")); System.out.println("Y".equals(null)); System.out.println(String.format("%02d", 1000L)); System.out.println(ArrayUtils.toString(splitAndTrim(" 11, 21,12 ,", ","))); System.out.println(new ArrayList<String>().toString()); JSONObject json = new JSONObject("{\"keynull\":null}"); json.put("bool", false); json.put("keya", "as"); json.put("key2", 2212222222222222222L); System.out.println(json); System.out.println(json.get("keynull").equals(null)); String a = String.format("{\"id\":%d,\"method\":\"testCrossSync\"," + "\"circle\":%d},\"isEnd\":true", 1, 1); System.out.println(a.getBytes().length); System.out.println(new String[] { "a", "b" }); System.out.println(new JSONArray("[\"aa\",\"\"]")); String data = String.format("%9d %s", 1, RandomStringUtils.randomAlphanumeric(10)); System.out.println(data.getBytes().length); System.out.println(ArrayUtils.toString("1|2| 3| 333||| 3".split("\\|"))); JSONObject j1 = new JSONObject("{\"a\":\"11111\"}"); JSONObject j2 = new JSONObject(j1.toString()); j2.put("b", "22222"); System.out.println(j1 + " | " + j2); System.out.println("======================"); String regex = "\\d+(\\-\\d+){2} \\d+(:\\d+){2}"; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher("2015-12-28 15:46:14 _NC250_MD:motion de\n"); String eventDate = matcher.find() ? matcher.group() : ""; System.out.println(eventDate); }
From source file:com.amalto.core.storage.hibernate.InstanceScrollOptimization.java
@Override public StorageResults visit(Select select) { ComplexTypeMetadata mainType = select.getTypes().get(0); Paging paging = select.getPaging();//from w ww . j a va 2 s. c om int start = paging.getStart(); if (start != 0) { throw new IllegalStateException( "This optimization is only use for iterating over all instances (start is not supported)."); } if (paging.getLimit() != Integer.MAX_VALUE) { // Optimization *could* work when page size is set... however it also means the analysis of the query is // redirecting to the wrong optimization, and this is an issue. throw new UnsupportedOperationException(); } // Perform same query as input *but* adds an order by clause 'by id' that allows efficient filtering (iterator // should // only return unique results). Select copy = select.copy(); Collection<FieldMetadata> keyFields = mainType.getKeyFields(); for (FieldMetadata keyField : keyFields) { copy.addOrderBy(new OrderBy(new Field(keyField), OrderBy.Direction.ASC)); } Criteria criteria = createCriteria(copy); // Perform the query with order by id. // Create the filtered result iterator CloseableIterator<DataRecord> nonFilteredIterator = new ScrollableIterator(mappings, storageClassLoader, criteria.scroll(), callbacks); Predicate isUniqueFilter = new UniquePredicate(); // Unique filter returns only different instances Iterator filteredIterator = IteratorUtils.filteredIterator(nonFilteredIterator, isUniqueFilter); FilteredIteratorWrapper uniqueIterator = new FilteredIteratorWrapper(nonFilteredIterator, filteredIterator, select); return new HibernateStorageResults(storage, select, uniqueIterator); }
From source file:gr.omadak.leviathan.asp.objects.GenericClass.java
public Iterator getProperties() { return members == null ? IteratorUtils.EMPTY_ITERATOR : IteratorUtils.filteredIterator(members.values().iterator(), new Predicate() { public boolean evaluate(Object obj) { return obj instanceof Property; }//from w w w . j a v a2 s .c o m }); }
From source file:gr.omadak.leviathan.asp.objects.GenericClass.java
public Iterator getMethods() { return members == null ? IteratorUtils.EMPTY_ITERATOR : IteratorUtils.filteredIterator(members.values().iterator(), new Predicate() { public boolean evaluate(Object obj) { return obj instanceof Method; }//ww w .ja va 2s. co m }); }
From source file:gov.nih.nci.caarray.util.owlparser.AbstractOntologyOwlParser.java
@SuppressWarnings("unchecked") private void handle(Element rootElement) throws ParseException { try {//ww w.ja va 2s. co m startProcessing(); if (url == null) { url = rootElement.attributeValue(getBaseAttributeName()); } handleOntologyDescription(rootElement.element(getOntologyElementName())); List<Element> classElements = rootElement.elements(getClassElementName()); // two passes: one to create categories, one to resolve subclassing references handleClasses(classElements.iterator()); handleSubclasses(classElements.iterator()); List<Element> allElements = rootElement.elements(); Iterator<Element> individualElements = IteratorUtils.filteredIterator(allElements.iterator(), IndividualElementPredicate.INSTANCE); handleIndividuals(individualElements); } finally { finishProcessing(); } }
From source file:com.projity.grouping.core.transform.filtering.NodeFilter.java
public Iterator filteredIterator(Iterator i) { return IteratorUtils.filteredIterator(i, this); }
From source file:io.wcm.config.core.persistence.impl.ToolsConfigPagePersistenceProvider.java
@SuppressWarnings("unchecked") private Iterator<Resource> getResourceInheritanceChainInternal(final String configName, final Iterator<String> paths, final ResourceResolver resourceResolver) { // find all matching items among all configured paths Iterator<Resource> matchingResources = IteratorUtils.transformedIterator(paths, new Transformer() { @Override//from ww w .j av a2 s. c om public Object transform(Object input) { String configPath = buildResourcePath((String) input, configName); Resource resource = resourceResolver.getResource(configPath); if (resource != null) { log.trace("+ Found matching config resource for inheritance chain: {}", configPath); } else { log.trace("- No matching config resource for inheritance chain: {}", configPath); } return resource; } }); Iterator<Resource> result = IteratorUtils.filteredIterator(matchingResources, PredicateUtils.notNullPredicate()); if (result.hasNext()) { return result; } else { return null; } }
From source file:gr.omadak.leviathan.asp.objects.JsUserDefinedMethod.java
public Iterator getLocalFunctions() { return localFunctions == null ? IteratorUtils.EMPTY_ITERATOR : IteratorUtils.filteredIterator(localFunctions.iterator(), new Predicate() { public boolean evaluate(Object ob) { JsUserDefinedMethod method = (JsUserDefinedMethod) ob; return method.definedAsVar && !method.definedInVar; }/*from w ww .j a v a2 s .c om*/ }); }
From source file:io.wcm.caconfig.extensions.persistence.impl.ToolsConfigPagePersistenceStrategy.java
@SuppressWarnings("unchecked") private Iterator<Resource> getResourceInheritanceChainInternal(final Collection<String> bucketNames, final String configName, final Iterator<String> paths, final ResourceResolver resourceResolver) { // find all matching items among all configured paths Iterator<Resource> matchingResources = IteratorUtils.transformedIterator(paths, new Transformer() { @Override/*from w w w .j a v a 2s.c o m*/ public Object transform(Object input) { String path = (String) input; for (String bucketName : bucketNames) { final String name = bucketName + "/" + configName; final String configPath = buildResourcePath(path, name); Resource resource = resourceResolver.getResource(configPath); if (resource != null) { log.trace("+ Found matching config resource for inheritance chain: {}", configPath); return resource; } else { log.trace("- No matching config resource for inheritance chain: {}", configPath); } } return null; } }); Iterator<Resource> result = IteratorUtils.filteredIterator(matchingResources, PredicateUtils.notNullPredicate()); if (result.hasNext()) { return result; } return null; }
From source file:nl.strohalm.cyclos.controls.reports.members.transactions.ExportMembersTransactionsDetailsToCsvAction.java
@Override @SuppressWarnings({ "unchecked", "rawtypes" }) protected List<?> executeQuery(final ActionContext context) { final MembersReportHandler reportHandler = getReportHandler(); final Pair<MembersTransactionsReportDTO, Iterator<MemberTransactionDetailsReportData>> pair = reportHandler .handleTransactionsDetails(context); final MembersTransactionsReportDTO dto = pair.getFirst(); final Iterator<MemberTransactionDetailsReportData> reportIterator = pair.getSecond(); final Iterator iterator = IteratorUtils.filteredIterator(reportIterator, new Predicate() { @Override// ww w . j av a 2 s. c o m public boolean evaluate(final Object element) { final MemberTransactionDetailsReportData data = (MemberTransactionDetailsReportData) element; if (dto.isIncludeNoTraders()) { return true; } return data.getAmount() != null; } }); return new IteratorListImpl(iterator); }