@Override public boolean removeAll(Collection<?> collection) { Iterator<Entry<K, V>> entryItr = unfiltered.entrySet().iterator(); boolean result = false; while (entryItr.hasNext()) { Entry<K, V> entry = entryItr.next(); if (predicate.apply(entry) && collection.contains(entry.getValue())) { entryItr.remove(); result = true; } } return result; }
@Override public RoutingResult route() { Collection<RoutingResult> result = new ArrayList<>(logicTables.size()); Collection<String> bindingTableNames = new TreeSet<>(String.CASE_INSENSITIVE_ORDER); for (String each : logicTables) { Optional<TableRule> tableRule = shardingRule.findTableRule(each); if (tableRule.isPresent()) { if (!bindingTableNames.contains(each)) { result.add(new StandardRoutingEngine(shardingRule, tableRule.get().getLogicTable(), shardingConditions).route()); if (result.isEmpty()) { throw new ShardingException("Cannot find table rule and default data source with logic tables: '%s'", logicTables); if (1 == result.size()) { return result.iterator().next();
public void testValuesRemoveAll() { final Map<K, V> map; try { map = makePopulatedMap(); } catch (UnsupportedOperationException e) { return; } Collection<V> valueCollection = map.values(); Set<V> valuesToRemove = singleton(valueCollection.iterator().next()); if (supportsRemove) { valueCollection.removeAll(valuesToRemove); for (V value : valuesToRemove) { assertFalse(valueCollection.contains(value)); } for (V value : valueCollection) { assertFalse(valuesToRemove.contains(value)); } } else { try { valueCollection.removeAll(valuesToRemove); fail("Expected UnsupportedOperationException."); } catch (UnsupportedOperationException expected) { } } assertInvariants(map); }
assertEquals(map.size(), keySet.size()); assertEquals(keySet.size() == 0, keySet.isEmpty()); assertEquals(!keySet.isEmpty(), keySet.iterator().hasNext()); assertTrue(map.containsKey(key)); assertTrue(map.containsValue(value)); assertTrue(valueCollection.contains(value)); assertTrue(valueCollection.containsAll(Collections.singleton(value))); assertTrue(entrySet.contains(mapEntry(key, value))); assertEquals(map.size(), valueCollection.size()); assertEquals(valueCollection.size() == 0, valueCollection.isEmpty()); assertEquals(!valueCollection.isEmpty(), valueCollection.iterator().hasNext()); for (V value : valueCollection) { assertTrue(map.containsValue(value)); assertEquals(!entrySet.isEmpty(), entrySet.iterator().hasNext()); assertEntrySetNotContainsString(entrySet);
private List<ShardingValue> getShardingValuesFromShardingConditions(final Collection<String> shardingColumns, final ShardingCondition shardingCondition) { List<ShardingValue> result = new ArrayList<>(shardingColumns.size()); for (ShardingValue each : shardingCondition.getShardingValues()) { Optional<BindingTableRule> bindingTableRule = shardingRule.findBindingTableRule(logicTableName); if ((logicTableName.equals(each.getLogicTableName()) || bindingTableRule.isPresent() && bindingTableRule.get().hasLogicTable(logicTableName)) && shardingColumns.contains(each.getColumnName())) { result.add(each); } } return result; }
public void testIterator() { setUpTest(); one.add("1"); two.add("2"); c.addComposited(one); c.addComposited(two); Iterator i = c.iterator(); Object next = i.next(); assertTrue(c.contains(next)); assertTrue(one.contains(next)); next = i.next(); i.remove(); assertTrue(!c.contains(next)); assertTrue(!two.contains(next)); }
private static Collection<String> catalogsToCache(RawStore rs) throws MetaException { Collection<String> confValue = MetastoreConf.getStringCollection(rs.getConf(), ConfVars.CATALOGS_TO_CACHE); if (confValue == null || confValue.isEmpty() || (confValue.size() == 1 && confValue.contains(""))) { return rs.getCatalogs(); } else { return confValue; } }
public void testPermutationSetEmpty() { Collection<List<Integer>> permutationSet = Collections2.permutations(Collections.<Integer>emptyList()); assertEquals(1, permutationSet.size()); assertTrue(permutationSet.contains(Collections.<Integer>emptyList())); Iterator<List<Integer>> permutations = permutationSet.iterator(); assertNextPermutation(Collections.<Integer>emptyList(), permutations); assertNoMorePermutations(permutations); }
public void testTransformedCollection() { Collection coll = TransformedCollection.decorate(new ArrayList(), STRING_TO_INTEGER_TRANSFORMER); assertEquals(0, coll.size()); Object[] els = getFullElements(); for (int i = 0; i < els.length; i++) { coll.add(els[i]); assertEquals(i + 1, coll.size()); assertEquals(true, coll.contains(new Integer((String) els[i]))); assertEquals(false, coll.contains(els[i])); } assertEquals(true, coll.remove(new Integer((String) els[0]))); }
static <K, V> boolean retainAllKeys( Map<K, V> map, Predicate<? super Entry<K, V>> entryPredicate, Collection<?> keyCollection) { Iterator<Entry<K, V>> entryItr = map.entrySet().iterator(); boolean result = false; while (entryItr.hasNext()) { Entry<K, V> entry = entryItr.next(); if (entryPredicate.apply(entry) && !keyCollection.contains(entry.getKey())) { entryItr.remove(); result = true; } } return result; }
if (freeSlots.isEmpty()) { throw new IllegalStateException("Trying to assign to a full node " + nodeId); if (executors.size() == 0) { LOG.warn("Trying to assign nothing from " + td.getId() + " to " + nodeId + " (Ignored)"); target = getFreeSlots().iterator().next(); if (!freeSlots.contains(target)) { throw new IllegalStateException( "Trying to assign already used slot " + target.getPort() + " on node " + nodeId);
public void testValuesRetainAll() { final Map<K, V> map; try { map = makePopulatedMap(); } catch (UnsupportedOperationException e) { return; } Collection<V> valueCollection = map.values(); Set<V> valuesToRetain = singleton(valueCollection.iterator().next()); if (supportsRemove) { valueCollection.retainAll(valuesToRetain); for (V value : valuesToRetain) { assertTrue(valueCollection.contains(value)); } for (V value : valueCollection) { assertTrue(valuesToRetain.contains(value)); } } else { try { valueCollection.retainAll(valuesToRetain); fail("Expected UnsupportedOperationException."); } catch (UnsupportedOperationException expected) { } } assertInvariants(map); }
@Override protected void initServletContext(ServletContext servletContext) { Collection<ViewResolver> matchingBeans = BeanFactoryUtils.beansOfTypeIncludingAncestors(obtainApplicationContext(), ViewResolver.class).values(); if (this.viewResolvers == null) { this.viewResolvers = new ArrayList<>(matchingBeans.size()); for (ViewResolver viewResolver : matchingBeans) { if (this != viewResolver) { this.viewResolvers.add(viewResolver); } } } else { for (int i = 0; i < this.viewResolvers.size(); i++) { ViewResolver vr = this.viewResolvers.get(i); if (matchingBeans.contains(vr)) { continue; } String name = vr.getClass().getName() + i; obtainApplicationContext().getAutowireCapableBeanFactory().initializeBean(vr, name); } } AnnotationAwareOrderComparator.sort(this.viewResolvers); this.cnmFactoryBean.setServletContext(servletContext); }
/** * @throws Exception If failed. */ @Test public void testCallAsyncMultiple() throws Exception { Collection<ClosureTestCallable> jobs = F.asList(new ClosureTestCallable(), new ClosureTestCallable()); IgniteFuture<Collection<Integer>> fut = callAsync(0, jobs, null); Collection<Integer> results = fut.get(); assert !results.isEmpty() : "Collection of results is empty."; assert results.size() == jobs.size() : "Collection of results must be of size: " + jobs.size() + "."; for (int i = 1; i <= jobs.size(); i++) assert results.contains(i) : "Collection of results does not contain value: " + i; }
/** * @param set Set. * @param size Expected size. */ private void assertSetContent(IgniteSet<Integer> set, int size) { Collection<Integer> data = new HashSet<>(size); for (Integer val : set) assertTrue(data.add(val)); assertEquals(size, data.size()); for (int val = 0; val < size; val++) assertTrue(data.contains(val)); }