@Override public int size() { checkState(!closed, destroyedMessage); // TODO: Maintain a separate counter for tracking live elements in map. return Maps.filterValues(items, MapValue::isAlive).size(); }
@Override public Set<K> keySet() { checkState(!closed, destroyedMessage); return Maps.filterValues(items, MapValue::isAlive).keySet() .stream() .map(this::decodeKey) .collect(Collectors.toSet()); }
/** * Helper for getting stats. * * @return */ public Map<String, ManagedLedgerImpl> getManagedLedgers() { // Return a view of already created ledger by filtering futures not yet completed return Maps.filterValues(Maps.transformValues(ledgers, future -> future.getNow(null)), Predicates.notNull()); }
@Override public Collection<V> values() { checkState(!closed, destroyedMessage); return Collections2.transform(Maps.filterValues(items, MapValue::isAlive).values(), value -> value.get(this::decodeValue)); }
@Override public Map<Symbol, Symbol> visitProject(ProjectNode node, Set<Symbol> lookupSymbols) { // Map from output Symbols to source Symbols Map<Symbol, Symbol> directSymbolTranslationOutputMap = Maps.transformValues(Maps.filterValues(node.getAssignments().getMap(), SymbolReference.class::isInstance), Symbol::from); Map<Symbol, Symbol> outputToSourceMap = lookupSymbols.stream() .filter(directSymbolTranslationOutputMap.keySet()::contains) .collect(toImmutableMap(identity(), directSymbolTranslationOutputMap::get)); checkState(!outputToSourceMap.isEmpty(), "No lookup symbols were able to pass through the projection"); // Map from source Symbols to underlying index source Symbols Map<Symbol, Symbol> sourceToIndexMap = node.getSource().accept(this, ImmutableSet.copyOf(outputToSourceMap.values())); // Generate the Map the connects lookup symbols to underlying index source symbols Map<Symbol, Symbol> outputToIndexMap = Maps.transformValues(Maps.filterValues(outputToSourceMap, in(sourceToIndexMap.keySet())), Functions.forMap(sourceToIndexMap)); return ImmutableMap.copyOf(outputToIndexMap); }
public static List<Map> filterNullValues(List<Map<String, Object>> mapList) { return Lists.transform(mapList, (Function<Map, Map>) input -> Maps.filterValues(input, Objects::nonNull)); }
@Override protected Map<String, String> create(Entry<String, String>[] entries) { Map<String, String> map = Maps.newHashMap(); putEntries(map, entries); map.putAll(ENTRIES_TO_FILTER); return Maps.filterValues(map, FILTER_VALUES); } })
/** Parameters which must be referenced in any tree matched to this placeholder. */ Set<UVariableDecl> requiredParameters() { return Maps.filterValues( annotatedParameters(), (ImmutableClassToInstanceMap<Annotation> annotations) -> !annotations.containsKey(MayOptionallyUse.class)) .keySet(); }
@Override public Set<Map.Entry<K, V>> entrySet() { checkState(!closed, destroyedMessage); return Maps.filterValues(items, MapValue::isAlive) .entrySet() .stream() .map(e -> Pair.of(decodeKey(e.getKey()), decodeValue(e.getValue().get()))) .collect(Collectors.toSet()); }
@Override public void clear() { checkState(!closed, destroyedMessage); Maps.filterValues(items, MapValue::isAlive) .forEach((k, v) -> remove(decodeKey(k))); }
/** * Filter, sort and page results. * * Returns JSON map with resulting destination views and total number of matched destinations * * @param page - defines result page to be returned * @param pageSize - defines page size to be used * @throws IOException */ String filter(int page, int pageSize) throws IOException { ObjectMapper mapper = new ObjectMapper(); destinations = Maps.filterValues(destinations, getPredicate()); Map<ObjectName, DestinationView> pagedDestinations = getPagedDestinations(page, pageSize); Map<String, Object> result = new HashMap<String, Object>(); result.put("data", pagedDestinations); result.put("count", destinations.size()); StringWriter writer = new StringWriter(); mapper.writeValue(writer, result); return writer.toString(); }
@Override protected NavigableMap<String, String> create(Entry<String, String>[] entries) { NavigableMap<String, String> map = new SafeTreeMap<>(); putEntries(map, entries); map.put("banana", "toast"); map.put("eggplant", "spam"); return Maps.filterValues(map, FILTER_VALUES); } })
@Override protected SortedMap<String, String> create(Entry<String, String>[] entries) { SortedMap<String, String> map = new NonNavigableSortedMap(); putEntries(map, entries); map.putAll(ENTRIES_TO_FILTER); return Maps.filterValues(map, FILTER_VALUES); } })
@Override protected BiMap<String, String> create(Entry<String, String>[] entries) { BiMap<String, String> map = HashBiMap.create(); putEntries(map, entries); map.putAll(ENTRIES_TO_FILTER); return Maps.filterValues(map, FILTER_VALUES); } })
public void testFilteredValuesClear() { Map<String, Integer> unfiltered = createUnfiltered(); unfiltered.put("one", 1); unfiltered.put("two", 2); unfiltered.put("three", 3); unfiltered.put("four", 4); Map<String, Integer> filtered = Maps.filterValues(unfiltered, EVEN); assertEquals(ImmutableMap.of("one", 1, "two", 2, "three", 3, "four", 4), unfiltered); assertEquals(ImmutableMap.of("two", 2, "four", 4), filtered); filtered.clear(); assertEquals(ImmutableMap.of("one", 1, "three", 3), unfiltered); assertTrue(filtered.isEmpty()); }
public void testFilteredValuesIllegalPutAll() { Map<String, Integer> unfiltered = createUnfiltered(); Map<String, Integer> filtered = Maps.filterValues(unfiltered, EVEN); filtered.put("a", 2); unfiltered.put("b", 4); unfiltered.put("c", 5); assertEquals(ImmutableMap.of("a", 2, "b", 4), filtered); try { filtered.putAll(ImmutableMap.of("c", 4, "zzz", 5, "b", 6)); fail(); } catch (IllegalArgumentException expected) { } assertEquals(ImmutableMap.of("a", 2, "b", 4), filtered); }
public void testFilteredValuesIllegalSetValue() { Map<String, Integer> unfiltered = createUnfiltered(); Map<String, Integer> filtered = Maps.filterValues(unfiltered, EVEN); filtered.put("a", 2); filtered.put("b", 4); assertEquals(ImmutableMap.of("a", 2, "b", 4), filtered); Entry<String, Integer> entry = filtered.entrySet().iterator().next(); try { entry.setValue(5); fail(); } catch (IllegalArgumentException expected) { } assertEquals(ImmutableMap.of("a", 2, "b", 4), filtered); }
public void testFilteredValuesIllegalPut() { Map<String, Integer> unfiltered = createUnfiltered(); Map<String, Integer> filtered = Maps.filterValues(unfiltered, EVEN); filtered.put("a", 2); unfiltered.put("b", 4); unfiltered.put("c", 5); assertEquals(ImmutableMap.of("a", 2, "b", 4), filtered); try { filtered.put("yyy", 3); fail(); } catch (IllegalArgumentException expected) { } assertEquals(ImmutableMap.of("a", 2, "b", 4), filtered); }
@Override public void evict(byte[] id) { try { List<LeadershipEvent<byte[]>> changes = Lists.newArrayList(); Set<String> topics = Maps.filterValues(elections, e -> e.candidates().stream().anyMatch(candidate -> Arrays.equals(candidate, id))).keySet(); topics.forEach(topic -> { Leadership<byte[]> oldLeadership = leadership(topic); elections.compute(topic, (k, v) -> v.evict(id, termCounter(topic)::incrementAndGet)); Leadership<byte[]> newLeadership = leadership(topic); if (!Objects.equal(oldLeadership, newLeadership)) { notifyLeadershipChange(topic, oldLeadership, newLeadership); } }); } catch (Exception e) { getLogger().error("State machine operation failed", e); throw Throwables.propagate(e); } }
@Test public void computeOptimizedScanPartitionOrAndCombinedFilter() { KafkaScanTrimmer kafkaScanTrimmer = new KafkaScanTrimmer(fullHouse, null); // partition = 1 or (partition >2 and <= 3) ExprNodeGenericFuncDesc eq = eq(Lists.newArrayList(partitionColumn, ConstantExprBuilder.build(1))); ExprNodeGenericFuncDesc lessEq = lessThanEq(Lists.newArrayList(partitionColumn, ConstantExprBuilder.build(3))); ExprNodeGenericFuncDesc greater = greaterThan(Lists.newArrayList(partitionColumn, ConstantExprBuilder.build(2))); ExprNodeGenericFuncDesc orNode = or(Lists.newArrayList(and(Lists.newArrayList(lessEq, greater)), eq)); Map actual = kafkaScanTrimmer.computeOptimizedScan(SerializationUtilities .deserializeExpression(SerializationUtilities.serializeExpression(orNode))); Map expected = Maps.filterValues(fullHouse, tp -> Objects.requireNonNull(tp).getPartition() == 1 || tp.getPartition() == 3); Assert.assertEquals(expected, actual); assertNotNull(orNode); }