Java Code Examples for java.util.Collections#checkedSet()

The following examples show how to use java.util.Collections#checkedSet() . 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: SplitReaggregateSpringTest.java    From camel-cookbook-examples with Apache License 2.0 6 votes vote down vote up
private void assertBooksByCategory(Exchange exchange) {
    Message in = exchange.getIn();
    @SuppressWarnings("unchecked")
    Set<String> books = Collections.checkedSet(in.getBody(Set.class), String.class);
    String category = in.getHeader("category", String.class);
    switch (category) {
        case "Tech":
            assertTrue(books.containsAll(Collections.singletonList("Apache Camel Developer's Cookbook")));
            break;
        case "Cooking":
            assertTrue(books.containsAll(Arrays.asList("Camel Cookbook",
                "Double decadence with extra cream", "Cooking with Butter")));
            break;
        default:
            fail();
            break;
    }
}
 
Example 2
Source File: SplitReaggregateTest.java    From camel-cookbook-examples with Apache License 2.0 6 votes vote down vote up
private void assertBooksByCategory(Exchange exchange) {
    Message in = exchange.getIn();
    @SuppressWarnings("unchecked")
    Set<String> books = Collections.checkedSet(in.getBody(Set.class), String.class);
    String category = in.getHeader("category", String.class);
    switch (category) {
        case "Tech":
            assertTrue(books.containsAll(Collections.singletonList("Apache Camel Developer's Cookbook")));
            break;
        case "Cooking":
            assertTrue(books.containsAll(Arrays.asList("Camel Cookbook",
                "Double decadence with extra cream", "Cooking with Butter")));
            break;
        default:
            fail();
            break;
    }
}
 
Example 3
Source File: AggregateCompletionConditionTest.java    From camel-cookbook-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void testAggregation() throws InterruptedException {
    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(2);

    template.sendBodyAndHeader("direct:in", "One", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Two", "group", "even");
    template.sendBodyAndHeader("direct:in", "Three", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Four", "group", "even");
    template.sendBodyAndHeader("direct:in", "Five", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Six", "group", "even");
    template.sendBodyAndHeader("direct:in", "Seven", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Eight", "group", "even");
    template.sendBodyAndHeader("direct:in", "Nine", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Ten", "group", "even");

    assertMockEndpointsSatisfied();

    List<Exchange> receivedExchanges = mockOut.getReceivedExchanges();
    @SuppressWarnings("unchecked")
    Set<String> odd = Collections.checkedSet(receivedExchanges.get(0).getIn().getBody(Set.class), String.class);
    assertTrue(odd.containsAll(Arrays.asList("One", "Three", "Five", "Seven", "Nine")));

    @SuppressWarnings("unchecked")
    Set<String> even = Collections.checkedSet(receivedExchanges.get(1).getIn().getBody(Set.class), String.class);
    assertTrue(even.containsAll(Arrays.asList("Two", "Four", "Six", "Eight", "Ten")));
}
 
Example 4
Source File: SplitAggregateExceptionHandlingTest.java    From camel-cookbook-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void testHandlesException() throws Exception {
    String[] array = new String[]{"one", "two", "three"};

    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.expectedMessageCount(1);

    template.sendBody("direct:in", array);

    assertMockEndpointsSatisfied();
    Exchange exchange = mockOut.getReceivedExchanges().get(0);
    @SuppressWarnings("unchecked")
    Set<String> backendResponses = Collections.checkedSet(exchange.getIn().getBody(Set.class), String.class);
    assertTrue(backendResponses.containsAll(Arrays.asList("Processed: one", "Failed: two", "Processed: three")));
}
 
Example 5
Source File: AggregateSimpleTest.java    From camel-cookbook-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void testAggregation() throws InterruptedException {
    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(2);

    template.sendBodyAndHeader("direct:in", "One", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Two", "group", "even");
    template.sendBodyAndHeader("direct:in", "Three", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Four", "group", "even");
    template.sendBodyAndHeader("direct:in", "Five", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Six", "group", "even");
    template.sendBodyAndHeader("direct:in", "Seven", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Eight", "group", "even");
    template.sendBodyAndHeader("direct:in", "Nine", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Ten", "group", "even");

    assertMockEndpointsSatisfied();

    List<Exchange> receivedExchanges = mockOut.getReceivedExchanges();
    @SuppressWarnings("unchecked")
    Set<String> odd = Collections.checkedSet(receivedExchanges.get(0).getIn().getBody(Set.class), String.class);
    assertTrue(odd.containsAll(Arrays.asList("One", "Three", "Five", "Seven", "Nine")));

    @SuppressWarnings("unchecked")
    Set<String> even = Collections.checkedSet(receivedExchanges.get(1).getIn().getBody(Set.class), String.class);
    assertTrue(even.containsAll(Arrays.asList("Two", "Four", "Six", "Eight", "Ten")));
}
 
Example 6
Source File: AggregateCompletionTimeoutSpringTest.java    From camel-cookbook-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void testAggregation() throws InterruptedException {
    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(2);

    template.sendBodyAndHeader("direct:in", "One", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Two", "group", "even");
    template.sendBodyAndHeader("direct:in", "Three", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Four", "group", "even");
    template.sendBodyAndHeader("direct:in", "Five", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Six", "group", "even");
    template.sendBodyAndHeader("direct:in", "Seven", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Eight", "group", "even");
    template.sendBodyAndHeader("direct:in", "Nine", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Ten", "group", "even");

    assertMockEndpointsSatisfied();

    for (Exchange exchange : mockOut.getReceivedExchanges()) {
        @SuppressWarnings("unchecked")
        Set<String> set = Collections.checkedSet(exchange.getIn().getBody(Set.class), String.class);
        if (set.contains("One")) { // odd
            assertTrue(set.containsAll(Arrays.asList("One", "Three", "Five", "Seven", "Nine")));
        } else { // even
            assertTrue(set.containsAll(Arrays.asList("Two", "Four", "Six", "Eight", "Ten")));
        }
    }
}
 
Example 7
Source File: AggregateSimpleSpringTest.java    From camel-cookbook-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void testAggregation() throws InterruptedException {
    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(2);

    template.sendBodyAndHeader("direct:in", "One", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Two", "group", "even");
    template.sendBodyAndHeader("direct:in", "Three", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Four", "group", "even");
    template.sendBodyAndHeader("direct:in", "Five", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Six", "group", "even");
    template.sendBodyAndHeader("direct:in", "Seven", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Eight", "group", "even");
    template.sendBodyAndHeader("direct:in", "Nine", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Ten", "group", "even");

    assertMockEndpointsSatisfied();

    List<Exchange> receivedExchanges = mockOut.getReceivedExchanges();
    @SuppressWarnings("unchecked")
    Set<String> odd = Collections.checkedSet(receivedExchanges.get(0).getIn().getBody(Set.class), String.class);
    assertTrue(odd.containsAll(Arrays.asList("One", "Three", "Five", "Seven", "Nine")));

    @SuppressWarnings("unchecked")
    Set<String> even = Collections.checkedSet(receivedExchanges.get(1).getIn().getBody(Set.class), String.class);
    assertTrue(even.containsAll(Arrays.asList("Two", "Four", "Six", "Eight", "Ten")));
}
 
Example 8
Source File: AggregateCompletionConditionSpringTest.java    From camel-cookbook-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void testAggregation() throws InterruptedException {
    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(2);

    template.sendBodyAndHeader("direct:in", "One", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Two", "group", "even");
    template.sendBodyAndHeader("direct:in", "Three", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Four", "group", "even");
    template.sendBodyAndHeader("direct:in", "Five", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Six", "group", "even");
    template.sendBodyAndHeader("direct:in", "Seven", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Eight", "group", "even");
    template.sendBodyAndHeader("direct:in", "Nine", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Ten", "group", "even");

    assertMockEndpointsSatisfied();

    List<Exchange> receivedExchanges = mockOut.getReceivedExchanges();
    @SuppressWarnings("unchecked")
    Set<String> odd = Collections.checkedSet(receivedExchanges.get(0).getIn().getBody(Set.class), String.class);
    assertTrue(odd.containsAll(Arrays.asList("One", "Three", "Five", "Seven", "Nine")));

    @SuppressWarnings("unchecked")
    Set<String> even = Collections.checkedSet(receivedExchanges.get(1).getIn().getBody(Set.class), String.class);
    assertTrue(even.containsAll(Arrays.asList("Two", "Four", "Six", "Eight", "Ten")));
}
 
Example 9
Source File: java_util_Collections_CheckedSet.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
protected Set<String> getAnotherObject() {
    Set<String> set = Collections.emptySet();
    return Collections.checkedSet(set, String.class);
}
 
Example 10
Source File: java_util_Collections_CheckedSet.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
protected Set<String> getObject() {
    Set<String> set = Collections.singleton("string");
    return Collections.checkedSet(set, String.class);
}
 
Example 11
Source File: java_util_Collections_CheckedSet.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
protected Set<String> getAnotherObject() {
    Set<String> set = Collections.emptySet();
    return Collections.checkedSet(set, String.class);
}
 
Example 12
Source File: java_util_Collections_CheckedSet.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
protected Set<String> getAnotherObject() {
    Set<String> set = Collections.emptySet();
    return Collections.checkedSet(set, String.class);
}
 
Example 13
Source File: java_util_Collections_CheckedSet.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
protected Set<String> getObject() {
    Set<String> set = Collections.singleton("string");
    return Collections.checkedSet(set, String.class);
}
 
Example 14
Source File: java_util_Collections_CheckedSet.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
protected Set<String> getObject() {
    Set<String> set = Collections.singleton("string");
    return Collections.checkedSet(set, String.class);
}
 
Example 15
Source File: AggregateParallelProcessingTest.java    From camel-cookbook-examples with Apache License 2.0 4 votes vote down vote up
@Test
public void testAggregation() throws InterruptedException {
    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(2);

    template.sendBodyAndHeader("direct:in", "One", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Two", "group", "even");
    template.sendBodyAndHeader("direct:in", "Three", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Four", "group", "even");
    template.sendBodyAndHeader("direct:in", "Five", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Six", "group", "even");
    template.sendBodyAndHeader("direct:in", "Seven", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Eight", "group", "even");
    template.sendBodyAndHeader("direct:in", "Nine", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Ten", "group", "even");

    assertMockEndpointsSatisfied();

    final List<Exchange> receivedExchanges = mockOut.getReceivedExchanges();
    final Message message1 = receivedExchanges.get(0).getIn();
    final Message message2 = receivedExchanges.get(1).getIn();

    log.info("exchange(0).header.group = {}", message1.getHeader("group"));
    log.info("exchange(0).property.CamelAggregatedCompletedBy = {}", message1.getExchange().getProperty("CamelAggregatedCompletedBy"));
    log.info("exchange(1).header.group = {}", message2.getHeader("group"));
    log.info("exchange(1).property.CamelAggregatedCompletedBy = {}", message2.getExchange().getProperty("CamelAggregatedCompletedBy"));

    final List<String> odd = Arrays.asList("One", "Three", "Five", "Seven", "Nine");
    final List<String> even = Arrays.asList("Two", "Four", "Six", "Eight", "Ten");

    @SuppressWarnings("unchecked")
    final Set<String> set1 = Collections.checkedSet(message1.getBody(Set.class), String.class);
    @SuppressWarnings("unchecked")
    final Set<String> set2 = Collections.checkedSet(message2.getBody(Set.class), String.class);

    if ("odd".equals(message1.getHeader("group"))) {
        assertTrue(set1.containsAll(odd));
        assertTrue(set2.containsAll(even));
    } else {
        assertTrue(set1.containsAll(even));
        assertTrue(set2.containsAll(odd));
    }
}
 
Example 16
Source File: AggregateExecutorServiceSpringTest.java    From camel-cookbook-examples with Apache License 2.0 4 votes vote down vote up
@Test
public void testAggregation() throws InterruptedException {
    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(2);

    template.sendBodyAndHeader("direct:in", "One", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Two", "group", "even");
    template.sendBodyAndHeader("direct:in", "Three", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Four", "group", "even");
    template.sendBodyAndHeader("direct:in", "Five", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Six", "group", "even");
    template.sendBodyAndHeader("direct:in", "Seven", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Eight", "group", "even");
    template.sendBodyAndHeader("direct:in", "Nine", "group", "odd");
    template.sendBodyAndHeader("direct:in", "Ten", "group", "even");

    assertMockEndpointsSatisfied();

    final List<Exchange> receivedExchanges = mockOut.getReceivedExchanges();
    final Message message1 = receivedExchanges.get(0).getIn();
    final Message message2 = receivedExchanges.get(1).getIn();

    log.info("exchange(0).header.group = {}", message1.getHeader("group"));
    log.info("exchange(0).property.CamelAggregatedCompletedBy = {}", message1.getExchange().getProperty("CamelAggregatedCompletedBy"));
    log.info("exchange(1).header.group = {}", message2.getHeader("group"));
    log.info("exchange(1).property.CamelAggregatedCompletedBy = {}", message2.getExchange().getProperty("CamelAggregatedCompletedBy"));

    final List<String> odd = Arrays.asList("One", "Three", "Five", "Seven", "Nine");
    final List<String> even = Arrays.asList("Two", "Four", "Six", "Eight", "Ten");

    @SuppressWarnings("unchecked")
    final Set<String> set1 = Collections.checkedSet(message1.getBody(Set.class), String.class);
    @SuppressWarnings("unchecked")
    final Set<String> set2 = Collections.checkedSet(message2.getBody(Set.class), String.class);

    if ("odd".equals(message1.getHeader("group"))) {
        assertTrue(set1.containsAll(odd));
        assertTrue(set2.containsAll(even));
    } else {
        assertTrue(set1.containsAll(even));
        assertTrue(set2.containsAll(odd));
    }
}
 
Example 17
Source File: java_util_Collections_CheckedSet.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
protected Set<String> getAnotherObject() {
    Set<String> set = Collections.emptySet();
    return Collections.checkedSet(set, String.class);
}
 
Example 18
Source File: AbstractRuntimeObjectSchemaTest.java    From protostuff with Apache License 2.0 4 votes vote down vote up
PojoWithObjectCollectionFields fill()
{
    LinkedList<String> ll = new LinkedList<String>();
    ll.add("zero");
    HashMap<String, Boolean> empty = newMap();

    TreeSet<String> ts = new TreeSet<String>();
    ts.add("two");

    EnumSet<Size> es = EnumSet.allOf(Size.class);

    emptySet = Collections.emptySet();
    emptyList = Collections.emptyList();
    singletonSet = Collections.singleton("three");
    singletonList = Collections.singletonList("four");
    setFromMap = Collections.newSetFromMap(empty);
    copiesList = Collections.nCopies(1, "five");

    unmodifiableCollection = Collections
            .unmodifiableCollection(Collections.emptyList()); // no
    // equals
    // impl
    unmodifiableSet = Collections.unmodifiableSet(Collections
            .emptySet());
    unmodifiableSortedSet = Collections.unmodifiableSortedSet(ts);
    unmodifiableList = Collections.unmodifiableList(ll);
    unmodifiableRandomAccessList = Collections
            .unmodifiableList(newList("six"));

    assertTrue(unmodifiableRandomAccessList.getClass().getName()
            .endsWith("RandomAccessList"));

    synchronizedCollection = Collections
            .synchronizedCollection(Collections.emptyList()); // no
    // equals
    // impl
    synchronizedSet = Collections.synchronizedSet(es);
    synchronizedSortedSet = Collections.synchronizedSortedSet(ts);
    synchronizedList = Collections.synchronizedList(ll);
    synchronizedRandomAccessList = Collections
            .synchronizedList(newList("seven"));

    assertTrue(synchronizedRandomAccessList.getClass().getName()
            .endsWith("RandomAccessList"));

    checkedCollection = Collections.checkedCollection(newList("eight"),
            String.class); // no equals impl
    checkedSet = Collections.checkedSet(es, Size.class);
    checkedSortedSet = Collections.checkedSortedSet(ts, String.class);
    checkedList = Collections.checkedList(ll, String.class);
    checkedRandomAccessList = Collections.checkedList(newList("nine"),
            String.class);

    assertTrue(checkedRandomAccessList.getClass().getName()
            .endsWith("RandomAccessList"));

    return this;
}
 
Example 19
Source File: java_util_Collections_CheckedSet.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
protected Set<String> getAnotherObject() {
    Set<String> set = Collections.emptySet();
    return Collections.checkedSet(set, String.class);
}
 
Example 20
Source File: java_util_Collections_CheckedSet.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
protected Set<String> getObject() {
    Set<String> set = Collections.singleton("string");
    return Collections.checkedSet(set, String.class);
}