List of usage examples for org.apache.commons.collections IteratorUtils arrayIterator
public static ResettableIterator arrayIterator(Object array)
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 . jav 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:info.magnolia.cms.util.Rule.java
/** * get a string representation of this rule * @return string representation// ww w.j a v a 2 s. co m */ public String toString() { StringBuffer buffer = new StringBuffer(); Iterator typeIterator = IteratorUtils.arrayIterator(allowedTypes); while (typeIterator.hasNext()) { buffer.append((String) typeIterator.next()); buffer.append(","); } return new String(buffer); }
From source file:gr.omadak.leviathan.asp.AspParser.java
public void parseDir(File sdir, boolean vbDefault) { FileFilter filter = new FileFilter() { public boolean accept(File f) { boolean result = f.isDirectory(); if (!result) { String name = f.getName(); int lastDot = name.lastIndexOf('.'); result = lastDot > 0 && "asp".equalsIgnoreCase(name.substring(lastDot + 1)); }/*from w ww . j a va2 s . co m*/ return result; } }; Stack stack = new Stack(); stack.push(sdir); while (!stack.isEmpty()) { File dir = (File) stack.pop(); for (Iterator it = IteratorUtils.arrayIterator(dir.listFiles(filter)); it.hasNext();) { File f = (File) it.next(); if (f.isDirectory()) { stack.push(f); } else { try { parseFile(f, vbDefault); } catch (ANTLRException ae) { LOG.error("Failed to parse file:" + f.getAbsolutePath(), ae); } catch (Exception ex) { LOG.error("Failed to parse file:" + f.getAbsolutePath() + " with error", ex); } } } } }
From source file:org.apache.cayenne.access.trans.QualifierTranslator.java
private final void appendList(Expression listExpr, DbAttribute paramDesc) throws IOException { Iterator<?> it = null;// w w w.ja v a 2 s.c o m Object list = listExpr.getOperand(0); if (list instanceof List) { it = ((List<?>) list).iterator(); } else if (list instanceof Object[]) { it = IteratorUtils.arrayIterator((Object[]) list); } else { String className = (list != null) ? list.getClass().getName() : "<null>"; throw new IllegalArgumentException("Unsupported type for the list expressions: " + className); } // process first element outside the loop // (unroll loop to avoid condition checking if (it.hasNext()) appendLiteral(it.next(), paramDesc, listExpr); else return; while (it.hasNext()) { out.append(", "); appendLiteral(it.next(), paramDesc, listExpr); } }
From source file:org.apache.cayenne.access.translator.select.QualifierTranslator.java
private final void appendList(Expression listExpr, DbAttribute paramDesc) throws IOException { Iterator<?> it;/*from w w w.j a va 2 s.c o m*/ Object list = listExpr.getOperand(0); if (list instanceof List) { it = ((List<?>) list).iterator(); } else if (list instanceof Object[]) { it = IteratorUtils.arrayIterator((Object[]) list); } else { String className = (list != null) ? list.getClass().getName() : "<null>"; throw new IllegalArgumentException("Unsupported type for the list expressions: " + className); } // process first element outside the loop // (unroll loop to avoid condition checking if (it.hasNext()) { appendLiteral(it.next(), paramDesc, listExpr); } else { return; } while (it.hasNext()) { out.append(", "); appendLiteral(it.next(), paramDesc, listExpr); } }
From source file:org.apache.cayenne.query.SQLTemplate.java
/** * Returns an iterator over parameter sets. Each element returned from the * iterator is a java.util.Map.//w w w.j av a2s . co m */ @SuppressWarnings("unchecked") public Iterator<Map<String, ?>> parametersIterator() { return (parameters == null || parameters.length == 0) ? IteratorUtils.emptyIterator() : IteratorUtils.transformedIterator(IteratorUtils.arrayIterator(parameters), nullMapTransformer); }
From source file:org.dspace.checker.HandleDispatcher.java
/** * Private initialization routine./*ww w.jav a 2s .c o m*/ * * @throws SQLException * if database access fails. */ private synchronized void init() throws SQLException { if (!init) { DSpaceObject dso = handleService.resolveToObject(context, handle); Iterator<Bitstream> bitstreams = null; switch (dso.getType()) { case Constants.BITSTREAM: bitstreams = IteratorUtils.arrayIterator(dso); break; case Constants.ITEM: bitstreams = bitstreamService.findAllInItem(context, (org.dspace.content.Item) dso); break; case Constants.COLLECTION: bitstreams = bitstreamService.findAllInCollection(context, (org.dspace.content.Collection) dso); break; case Constants.COMMUNITY: bitstreams = bitstreamService.findAllInCommunity(context, (org.dspace.content.Community) dso); break; } delegate = new IteratorDispatcher(bitstreams); init = true; } }
From source file:org.mule.routing.EventGroup.java
/** * Returns an iterator over a snapshot copy of this group's collected events., * optionally sorted by arrival order. If * you need to iterate over the group and e.g. remove select events, do so via * {@link #removeEvent(MuleEvent)}. If you need to do so atomically in order to * prevent e.g. concurrent reception/aggregation of the group during iteration, * wrap the iteration in a synchronized block on the group instance. * * @return an iterator over collected {@link MuleEvent}s. * @throws ObjectStoreException//from w w w . jav a 2 s. co m */ @SuppressWarnings("unchecked") public Iterator<MuleEvent> iterator(boolean sortByArrival) throws ObjectStoreException { synchronized (events) { if (events.allKeys().isEmpty()) { return IteratorUtils.emptyIterator(); } else { return IteratorUtils.arrayIterator(this.toArray(sortByArrival)); } } }
From source file:org.mule.transport.jms.JmsMessageUtilsTestCase.java
@Test public void testMapMessageWithNullValue() throws Exception { String[] keys = new String[] { "key", "null" }; Iterator<String> keyIterator = IteratorUtils.arrayIterator(keys); Enumeration<String> keyEnumeration = new IteratorEnumeration(keyIterator); MapMessage mockMessage1 = mock(MapMessage.class); when(mockMessage1.getMapNames()).thenReturn(keyEnumeration); when(mockMessage1.getObject("key")).thenReturn("value"); when(mockMessage1.getObject("null")).thenReturn(null); Object result = JmsMessageUtils.toObject(mockMessage1, JmsConstants.JMS_SPECIFICATION_11, ENCODING); assertNotNull(result);//ww w. j av a2 s . c o m assertTrue(result instanceof Map); Map map = (Map) result; assertEquals("value", map.get("key")); assertNull(map.get("null")); }
From source file:org.mule.transport.jms.JmsMuleMessageFactoryTestCase.java
@Override protected Object getValidTransportMessage() throws Exception { TextMessage textMessage = mock(TextMessage.class); when(textMessage.getText()).thenReturn(MESSAGE_TEXT); when(textMessage.getJMSCorrelationID()).thenReturn(null); when(textMessage.getJMSDeliveryMode()).thenReturn(Integer.valueOf(1)); when(textMessage.getJMSDestination()).thenReturn(null); when(textMessage.getJMSExpiration()).thenReturn(Long.valueOf(0)); when(textMessage.getJMSMessageID()).thenReturn("1234567890"); when(textMessage.getJMSPriority()).thenReturn(Integer.valueOf(4)); when(textMessage.getJMSRedelivered()).thenReturn(Boolean.FALSE); when(textMessage.getJMSReplyTo()).thenReturn(null); when(textMessage.getJMSTimestamp()).thenReturn(Long.valueOf(0)); when(textMessage.getJMSType()).thenReturn(null); when(textMessage.getPropertyNames()) .thenReturn(IteratorUtils.asEnumeration(IteratorUtils.arrayIterator(new Object[] { "foo" }))); when(textMessage.getObjectProperty("foo")).thenReturn("bar"); return textMessage; }