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

The following examples show how to use java.util.Collections#checkedSet() . These examples are extracted from open source projects. 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
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
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
@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
@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
@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
@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
@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
@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
protected Set<String> getObject() {
    Set<String> set = Collections.singleton("string");
    return Collections.checkedSet(set, String.class);
}
 
Example 10
protected Set<String> getObject() {
    Set<String> set = Collections.singleton("string");
    return Collections.checkedSet(set, String.class);
}
 
Example 11
protected Set<String> getAnotherObject() {
    Set<String> set = Collections.emptySet();
    return Collections.checkedSet(set, String.class);
}
 
Example 12
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 13
protected Set<String> getAnotherObject() {
    Set<String> set = Collections.emptySet();
    return Collections.checkedSet(set, String.class);
}
 
Example 14
@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 15
@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
protected Set<String> getObject() {
    Set<String> set = Collections.singleton("string");
    return Collections.checkedSet(set, String.class);
}
 
Example 17
protected Set<String> getObject() {
    Set<String> set = Collections.singleton("string");
    return Collections.checkedSet(set, String.class);
}
 
Example 18
protected Set<String> getAnotherObject() {
    Set<String> set = Collections.emptySet();
    return Collections.checkedSet(set, String.class);
}
 
Example 19
protected Set<String> getAnotherObject() {
    Set<String> set = Collections.emptySet();
    return Collections.checkedSet(set, String.class);
}
 
Example 20
protected Set<String> getAnotherObject() {
    Set<String> set = Collections.emptySet();
    return Collections.checkedSet(set, String.class);
}