List of usage examples for java.util Queue iterator
Iterator<E> iterator();
From source file:tasly.greathealth.system.shutdown.TaslyDisposableBean.java
@Override public void destroy() throws Exception { LOG.info("tomcat shut down begin handing..."); final List<OmsSaveOrderParameter> omsSaveOrderParameterList = new ArrayList<OmsSaveOrderParameter>(); final Map<ChannelSource, Map<EventType, Queue<OrderCommand>>> command = OrderCommandsStorage.getInstance() .getAllCommands();/*w w w .j a va 2 s. c o m*/ final Map<EventType, Queue<OrderCommand>> orderCommand = command.get(ChannelSource.TMALL); for (final EventType type : orderCommand.keySet()) { if (orderCommand.containsKey(type)) { final Queue<OrderCommand> cmds = orderCommand.get(type); final Iterator<OrderCommand> it = cmds.iterator(); while (it.hasNext()) { final OrderCommand oc = it.next(); omsSaveOrderParameterList.add(this.packgingOmsSaveOrderParameter(type, oc)); } } } try { omsOrderRetrieverService.batchSaveFailOrPendingOrder(omsSaveOrderParameterList); LOG.info("save into the database success"); } catch (final Exception e) { LOG.info("save into the database failed"); e.printStackTrace(); } }
From source file:org.jboss.aerogear.sync.jsonpatch.server.JsonPatchInMemoryDataStoreTest.java
@Test public void getEdits() { final String documentId = "12345"; final String clientId = "client1"; final ServerInMemoryDataStore<JsonNode, JsonPatchEdit> dataStore = new ServerInMemoryDataStore<JsonNode, JsonPatchEdit>(); final JsonPatchEdit editOne = JsonPatchEdit.withChecksum("bogus").clientVersion(0).build(); final JsonPatchEdit editTwo = JsonPatchEdit.withChecksum("bogus").clientVersion(1).build(); dataStore.saveEdits(editOne, documentId, clientId); dataStore.saveEdits(editTwo, documentId, clientId); final Queue<JsonPatchEdit> edits = dataStore.getEdits(documentId, clientId); assertThat(edits.size(), is(2));// w ww . java2 s . com final Iterator<JsonPatchEdit> iterator = edits.iterator(); assertThat(iterator.next().clientVersion(), is(0L)); assertThat(iterator.next().clientVersion(), is(1L)); }
From source file:org.jboss.aerogear.sync.jsonmergepatch.server.JsonPatchInMemoryDataStoreTest.java
@Test public void getEdits() { final String documentId = "12345"; final String clientId = "client1"; final ServerInMemoryDataStore<JsonNode, JsonMergePatchEdit> dataStore = new ServerInMemoryDataStore<JsonNode, JsonMergePatchEdit>(); final JsonMergePatchEdit editOne = JsonMergePatchEdit.withChecksum("bogus").clientVersion(0).build(); final JsonMergePatchEdit editTwo = JsonMergePatchEdit.withChecksum("bogus").clientVersion(1).build(); dataStore.saveEdits(editOne, documentId, clientId); dataStore.saveEdits(editTwo, documentId, clientId); final Queue<JsonMergePatchEdit> edits = dataStore.getEdits(documentId, clientId); assertThat(edits.size(), is(2));/*from w w w.jav a2 s.c o m*/ final Iterator<JsonMergePatchEdit> iterator = edits.iterator(); assertThat(iterator.next().clientVersion(), is(0L)); assertThat(iterator.next().clientVersion(), is(1L)); }
From source file:test.jamocha.languages.clips.BindTest.java
@Test public void testVariableBinding() throws ParseException { final Network network = new Network(); final ByteArrayOutputStream out = initializeAppender(network); run(network, "(unwatch all)"); {/*from ww w .java 2 s.c o m*/ final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(bind ?x 2)"); final Queue<Object> values = returnValues.getLeft(); assertThat(values, hasSize(1)); final Object value = values.iterator().next(); assertThat(value, instanceOf(String.class)); final long two = Long.parseLong((String) value); assertEquals(2L, two); assertThat(returnValues.getRight(), empty()); assertThat(out.toString(), isEmptyString()); out.reset(); } }
From source file:test.jamocha.languages.clips.BindTest.java
@Test public void testVariableUnbinding() throws ParseException { final Network network = new Network(); final ByteArrayOutputStream out = initializeAppender(network); run(network, "(unwatch all)"); {// ww w .j ava 2 s .c o m final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(bind ?x 2)"); final Queue<Object> values = returnValues.getLeft(); assertThat(values, hasSize(1)); final Object value = values.iterator().next(); assertThat(value, instanceOf(String.class)); final long two = Long.parseLong((String) value); assertEquals(2L, two); assertThat(returnValues.getRight(), empty()); assertThat(out.toString(), isEmptyString()); out.reset(); } { final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(bind ?x)"); final Queue<Object> values = returnValues.getLeft(); assertThat(values, hasSize(0)); assertThat(returnValues.getRight(), empty()); assertThat(out.toString(), isEmptyString()); out.reset(); } }
From source file:com.sishuok.chapter3.web.controller.chat.MsgPublisher.java
/** * * @param receiver ??//from w w w. j ava 2s .c o m * @param sender * @param data */ private void publish(String receiver, String sender, String data) { if (receiver == null || receiver.trim().length() == 0) {//?? for (String loginUsername : usernameToDeferredResultMap.keySet()) { if (loginUsername.equals(sender)) { continue; } Queue<DeferredResult<String>> queue = usernameToDeferredResultMap.get(loginUsername); if (queue != null) { Iterator<DeferredResult<String>> iter = queue.iterator(); while (iter.hasNext()) { DeferredResult<String> result = iter.next(); try { result.setResult(data); } catch (Exception e) { e.printStackTrace(); } iter.remove(); } } } } else { //?? Queue<DeferredResult<String>> queue = usernameToDeferredResultMap.get(receiver); if (queue != null) { Iterator<DeferredResult<String>> iter = queue.iterator(); while (iter.hasNext()) { DeferredResult result = iter.next(); try { result.setResult(data); } catch (Exception e) { e.printStackTrace(); } iter.remove(); } } } }
From source file:com.sishuok.chapter3.web.controller.chat.MsgPublisher.java
public void logout(String username) { if (username == null) { return;/*from w w w . j av a2s.co m*/ } Queue<DeferredResult<String>> queue = usernameToDeferredResultMap.get(username); boolean isLogout = false; if (queue != null) { if (queue.size() == 0) { isLogout = true; } else { isLogout = true; Iterator<DeferredResult<String>> iter = queue.iterator(); while (iter.hasNext()) { DeferredResult<String> result = iter.next(); if (!result.isSetOrExpired()) { isLogout = false; break; } } } } if (isLogout) { StringBuilder data = new StringBuilder(); data.append("{"); data.append("\"type\" : \"logout\""); data.append(",\"username\" : \"" + username + "\""); data.append("}"); publish(null, username, data.toString()); usernameToDeferredResultMap.remove(username); } }
From source file:test.jamocha.languages.clips.SystemTest.java
@Test public void testSimpleWatchedFactAssertion() throws ParseException { final Network network = new Network(); final ByteArrayOutputStream out = initializeAppender(network); {/* w w w .j av a 2 s .co m*/ final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(unwatch all)\n(watch facts)\n"); assertThat(returnValues.getLeft(), empty()); assertThat(returnValues.getRight(), empty()); assertThat(out.toString(), isEmptyString()); } { final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(deftemplate t1 (slot s1 (type INTEGER)))\n"); assertThat(returnValues.getLeft(), empty()); assertThat(returnValues.getRight(), empty()); assertThat(out.toString(), isEmptyString()); } { final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(assert (t1 (s1 2)))\n"); final Queue<Object> values = returnValues.getLeft(); assertThat(values, hasSize(1)); final Object value = values.iterator().next(); assertThat(value, instanceOf(String.class)); assertEquals("<Fact-2>", value); assertThat(returnValues.getRight(), empty()); final String output = out.toString(); assertThat(output, not(isEmptyString())); final String[] lines = output.split(linesep); assertThat(lines, arrayWithSize(1)); assertEquals("==> f-2\t(t1 (s1 2))", lines[0]); out.reset(); } }
From source file:test.jamocha.languages.clips.SystemTest.java
@SuppressWarnings("unchecked") @Test//from w w w .jav a2s .c om public void testNodeSharingAllButTerminal() throws ParseException { final Network network = new Network(); final ByteArrayOutputStream out = initializeAppender(network); { final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(unwatch all)\n(watch facts)\n"); assertThat(returnValues.getLeft(), empty()); assertThat(returnValues.getRight(), empty()); assertThat(out.toString(), isEmptyString()); } { final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(deftemplate t1 (slot s1 (type INTEGER)))\n"); assertThat(returnValues.getLeft(), empty()); assertThat(returnValues.getRight(), empty()); assertThat(out.toString(), isEmptyString()); } { final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(defrule r1 (t1 (s1 5)) => (assert (t1 (s1 999))) )\n"); assertThat(returnValues.getLeft(), empty()); assertThat(returnValues.getRight(), empty()); assertThat(out.toString(), isEmptyString()); } { final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(assert (t1 (s1 5)))\n"); final Queue<Object> values = returnValues.getLeft(); assertThat(values, hasSize(1)); final Object value = values.iterator().next(); assertThat(value, instanceOf(String.class)); assertEquals("<Fact-2>", value); assertThat(returnValues.getRight(), empty()); final String[] lines = out.toString().split(linesep); assertThat(lines, arrayWithSize(1)); assertEquals("==> f-2\t(t1 (s1 5))", lines[0]); out.reset(); } { final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(defrule r2 (t1 (s1 5)) => (assert (t1 (s1 888))) )\n"); assertThat(returnValues.getLeft(), empty()); assertThat(returnValues.getRight(), empty()); assertThat(out.toString(), isEmptyString()); } { final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(run)\n"); assertThat(returnValues.getLeft(), empty()); assertThat(returnValues.getRight(), empty()); final String[] lines = out.toString().split(linesep); assertThat(lines, either(arrayContaining(equalTo("==> f-3\t(t1 (s1 888))"), equalTo("==> f-4\t(t1 (s1 999))"))) .or(arrayContaining(equalTo("==> f-3\t(t1 (s1 999))"), equalTo("==> f-4\t(t1 (s1 888))")))); assertThat(lines, arrayWithSize(2)); out.reset(); } }
From source file:test.jamocha.languages.clips.SystemTest.java
@Test public void testSimpleRuleExecution() throws ParseException { final Network network = new Network(); final ByteArrayOutputStream out = initializeAppender(network); {//from www .j ava2s .c o m final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(unwatch all)\n(watch facts)\n"); assertThat(returnValues.getLeft(), empty()); assertThat(returnValues.getRight(), empty()); assertThat(out.toString(), isEmptyString()); } { final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(deftemplate t1 (slot s1 (type INTEGER)))\n"); assertThat(returnValues.getLeft(), empty()); assertThat(returnValues.getRight(), empty()); assertThat(out.toString(), isEmptyString()); } { final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(defrule r1 (t1 (s1 5)) => (assert (t1 (s1 999))) )\n"); assertThat(returnValues.getLeft(), empty()); assertThat(returnValues.getRight(), empty()); assertThat(out.toString(), isEmptyString()); } { final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(assert (t1 (s1 2)))\n"); final Queue<Object> values = returnValues.getLeft(); assertThat(values, hasSize(1)); final Object value = values.iterator().next(); assertThat(value, instanceOf(String.class)); assertEquals("<Fact-2>", value); assertThat(returnValues.getRight(), empty()); final String[] lines = out.toString().split(linesep); assertThat(lines, arrayWithSize(1)); assertEquals("==> f-2\t(t1 (s1 2))", lines[0]); out.reset(); } { final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(assert (t1 (s1 5)))\n"); final Queue<Object> values = returnValues.getLeft(); assertThat(values, hasSize(1)); final Object value = values.iterator().next(); assertThat(value, instanceOf(String.class)); assertEquals("<Fact-3>", value); assertThat(returnValues.getRight(), empty()); final String[] lines = out.toString().split(linesep); assertThat(lines, arrayWithSize(1)); assertEquals("==> f-3\t(t1 (s1 5))", lines[0]); out.reset(); } { final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(run)\n"); assertThat(returnValues.getLeft(), empty()); assertThat(returnValues.getRight(), empty()); final String[] lines = out.toString().split(linesep); assertThat(lines, arrayWithSize(1)); assertEquals("==> f-4\t(t1 (s1 999))", lines[0]); out.reset(); } }