Java Code Examples for java.util.Deque#forEach()

The following examples show how to use java.util.Deque#forEach() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VerifyDistributedSetupTestIT.java    From apicurio-studio with Apache License 2.0 6 votes vote down vote up
private void waitOnInboundMessages(String label, Deque<String> inboundMessages, 
        int expectedNumberOfMessages) {
    int maxTimeToWait = 5000;
    int totalWaitTime = 0;
    System.out.println("[" + label + "]  Waiting for inbound messages.");
    while (inboundMessages.size() < expectedNumberOfMessages && totalWaitTime < maxTimeToWait) {
        System.out.println("[" + label + "]  Inbound Messages size: " + inboundMessages.size());
        try { Thread.sleep(250); } catch (Exception e) {}
        totalWaitTime += 250;
    }
    if (expectedNumberOfMessages != inboundMessages.size()) {
        System.out.println("!!! ---------------------");
        inboundMessages.forEach( message -> {
            System.out.println("[" + label + "]  Message: " + message);
        });
        System.out.println("!!! ---------------------");
    }
    Assert.assertEquals("[" + label + "]  Received an unexpected number of inbound messages.", 
            expectedNumberOfMessages, inboundMessages.size());
    System.out.println("[" + label + "]  Found the expected number of messages (" + expectedNumberOfMessages + ")");
}
 
Example 2
Source File: ByteBufferRLPWriter.java    From incubator-tuweni with Apache License 2.0 5 votes vote down vote up
private void writeEncodedValuesAsList(Deque<byte[]> values) {
  int totalSize = 0;
  for (byte[] value : values) {
    try {
      totalSize = Math.addExact(totalSize, value.length);
    } catch (ArithmeticException e) {
      throw new BufferOverflowException();
    }
  }
  buffer.put(encodeLength(totalSize, 0xc0));
  values.forEach(bytes -> buffer.put(bytes));
}
 
Example 3
Source File: ByteBufferRLPWriter.java    From cava with Apache License 2.0 5 votes vote down vote up
private void writeEncodedValuesAsList(Deque<byte[]> values) {
  int totalSize = 0;
  for (byte[] value : values) {
    try {
      totalSize = Math.addExact(totalSize, value.length);
    } catch (ArithmeticException e) {
      throw new BufferOverflowException();
    }
  }
  buffer.put(encodeLength(totalSize, 0xc0));
  values.forEach(bytes -> buffer.put(bytes));
}
 
Example 4
Source File: CachingBuffer.java    From catnip with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
void replayGuild(final String id) {
    awaitedGuilds.remove(id);
    guildCreateCache.remove(id);
    if(guildBuffers.containsKey(id)) {
        final Deque<JsonObject> queue = guildBuffers.get(id);
        queue.forEach(e -> cacheAndDispatch(e.getString("t"), this.id, e));
        guildBuffers.remove(id);
    }
}
 
Example 5
Source File: ComputeBuildingsWithViewTest.java    From elements-of-programming-interviews-solutions with MIT License 4 votes vote down vote up
private void test(Deque<BuildingWithHeight> expected, LinkedList<Integer> sequence) {
    Deque<BuildingWithHeight> result = ComputeBuildingsWithView.examineBuildingsWithSunset(sequence.iterator());
    expected.forEach( building-> {
        assertTrue(building.equals(result.removeFirst()));
    });
}
 
Example 6
Source File: ComputeBuildingsWithViewTest.java    From elements-of-programming-interviews with MIT License 4 votes vote down vote up
private void test(Deque<BuildingWithHeight> expected, LinkedList<Integer> sequence) {
    Deque<BuildingWithHeight> result = ComputeBuildingsWithView.examineBuildingsWithSunset(sequence.iterator());
    expected.forEach( building-> {
        assertTrue(building.equals(result.removeFirst()));
    });
}