List of usage examples for java.util Collections checkedSet
public static <E> Set<E> checkedSet(Set<E> s, Class<E> type)
From source file:Main.java
public static void main(String args[]) { Set<String> hset = new TreeSet<String>(); // populate the set hset.add("from"); hset.add("java2s.com"); hset.add("tutorial"); // get typesafe view of the set Set<String> tsset = Collections.checkedSet(hset, String.class); System.out.println(tsset);// w w w . j a v a2 s. co m }
From source file:org.camelcookbook.splitjoin.splitaggregate.SplitAggregateExceptionHandlingSpringTest.java
@Test public void testHandlesException() throws Exception { String[] array = new String[] { "one", "two", "three" }; MockEndpoint mockOut = getMockEndpoint("mock:out"); mockOut.expectedMessageCount(1);//w w w . ja v a 2 s .c o m 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"))); }
From source file:org.camelcookbook.splitjoin.splitaggregate.SplitAggregateSpringTest.java
@Test public void testSplitAggregatesResponses() throws Exception { String[] array = new String[] { "one", "two", "three" }; MockEndpoint mockOut = getMockEndpoint("mock:out"); mockOut.expectedMessageCount(1);/* w w w . j a v a 2 s .co m*/ 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", "Processed: two", "Processed: three"))); }
From source file:org.camelcookbook.splitjoin.aggregatetimeouts.AggregateCompletionTimeoutSpringTest.java
@Test public void testAggregation() throws InterruptedException { MockEndpoint mockOut = getMockEndpoint("mock:out"); mockOut.setExpectedMessageCount(2);//from w ww. ja v a2s .c o m 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"))); } } }
From source file:org.camelcookbook.splitjoin.aggregate.AggregateCompletionConditionSpringTest.java
@Test public void testAggregation() throws InterruptedException { MockEndpoint mockOut = getMockEndpoint("mock:out"); mockOut.setExpectedMessageCount(2);// w ww. j a v a 2s. c o m 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"))); }
From source file:org.camelcookbook.splitjoin.aggregate.AggregateDynamicCompletionSizeSpringTest.java
@Test public void testAggregation() throws InterruptedException { MockEndpoint mockOut = getMockEndpoint("mock:out"); mockOut.setExpectedMessageCount(2);/*w w w. ja va2s.c om*/ Map<String, Object> oddHeaders = new HashMap<String, Object>(); oddHeaders.put("group", "odd"); oddHeaders.put("batchSize", "5"); Map<String, Object> evenHeaders = new HashMap<String, Object>(); evenHeaders.put("group", "even"); evenHeaders.put("batchSize", "4"); template.sendBodyAndHeaders("direct:in", "One", oddHeaders); template.sendBodyAndHeaders("direct:in", "Two", evenHeaders); template.sendBodyAndHeaders("direct:in", "Three", oddHeaders); template.sendBodyAndHeaders("direct:in", "Four", evenHeaders); template.sendBodyAndHeaders("direct:in", "Five", oddHeaders); template.sendBodyAndHeaders("direct:in", "Six", evenHeaders); template.sendBodyAndHeaders("direct:in", "Seven", oddHeaders); template.sendBodyAndHeaders("direct:in", "Eight", evenHeaders); template.sendBodyAndHeaders("direct:in", "Nine", oddHeaders); assertMockEndpointsSatisfied(); List<Exchange> receivedExchanges = mockOut.getReceivedExchanges(); @SuppressWarnings("unchecked") Set<String> even = Collections.checkedSet(receivedExchanges.get(0).getIn().getBody(Set.class), String.class); assertTrue(even.containsAll(Arrays.asList("Two", "Four", "Six", "Eight"))); @SuppressWarnings("unchecked") Set<String> odd = Collections.checkedSet(receivedExchanges.get(1).getIn().getBody(Set.class), String.class); assertTrue(odd.containsAll(Arrays.asList("One", "Three", "Five", "Seven", "Nine"))); }
From source file:org.camelcookbook.splitjoin.splitreaggregate.SplitReaggregateSpringTest.java
private void assertBooksByCategory(Exchange exchange) { Message in = exchange.getIn();//from w ww . jav a 2 s . c o m @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; } }
From source file:org.camelcookbook.splitjoin.aggregateparallel.AggregateExecutorServiceSpringTest.java
@Test public void testAggregation() throws InterruptedException { MockEndpoint mockOut = getMockEndpoint("mock:out"); mockOut.setExpectedMessageCount(2);/* w w w . j a va 2 s. c o m*/ 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)); } }
From source file:mitm.application.djigzo.admin.hibernate.AdminEntity.java
@Override @SuppressWarnings({ "unchecked", "rawtypes" }) public Set<Authority> getAuthorities() { /*/* www . j a va 2s . c o m*/ * For this implementation We only allow AuthorityEntity to the set but we want to keep the * interface to be as clean as possible and not depend on anything Hibernate related. */ return (Set) Collections.checkedSet(authorities, AuthorityEntity.class); }