static <K> Predicate<Entry<K, ?>> keyPredicateOnEntries(Predicate<? super K> keyPredicate) { return compose(keyPredicate, Maps.<K>keyFunction()); }
static <V> Predicate<Entry<?, V>> valuePredicateOnEntries(Predicate<? super V> valuePredicate) { return compose(valuePredicate, Maps.<V>valueFunction()); }
@Override public List<SchemaTableName> listTables(ConnectorSession session, String schemaNameOrNull) { if (schemaNameOrNull == null) { return ImmutableList.copyOf(TABLES.keySet()); } return TABLES.keySet().stream() .filter(compose(schemaNameOrNull::equals, SchemaTableName::getSchemaName)) .collect(toImmutableList()); }
static <V> Predicate<Entry<?, V>> valuePredicateOnEntries(Predicate<? super V> valuePredicate) { return compose(valuePredicate, Maps.<V>valueFunction()); }
static <K> Predicate<Entry<K, ?>> keyPredicateOnEntries(Predicate<? super K> keyPredicate) { return compose(keyPredicate, Maps.<K>keyFunction()); }
public Set<ValueAttribute> computeConstructorArguments() { return ImmutableSet.copyOf( FluentIterable.from(getSettableAttributes()) .filter(Predicates.compose(Predicates.not(Predicates.equalTo(-1)), ToConstructorArgumentOrder.FUNCTION)) .toSortedList(Ordering.natural().onResultOf(ToConstructorArgumentOrder.FUNCTION))); }
public void testComposeOfPredicateAndFunctionIsAssociative() { Map<Float, String> m = ImmutableMap.of(4.0f, "A", 3.0f, "B", 2.0f, "C", 1.0f, "D"); Predicate<? super Integer> h = Predicates.equalTo(42); Function<? super String, Integer> g = new HashCodeFunction(); Function<Float, String> f = Functions.forMap(m, "F"); Predicate<Float> p1 = Predicates.compose(Predicates.compose(h, g), f); Predicate<Float> p2 = Predicates.compose(h, Functions.compose(g, f)); // Might be nice (eventually) to have: // assertEquals(p1, p2); // But for now, settle for this: assertEquals(p1.hashCode(), p2.hashCode()); assertEquals(p1.apply(1.0f), p2.apply(1.0f)); assertEquals(p1.apply(5.0f), p2.apply(5.0f)); }
@GwtIncompatible // SerializableTester public void testComposeSerialization() { Function<String, String> trim = TrimStringFunction.INSTANCE; Predicate<String> equalsFoo = Predicates.equalTo("Foo"); Predicate<String> trimEqualsFoo = Predicates.compose(equalsFoo, trim); SerializableTester.reserializeAndAssert(trimEqualsFoo); }
public void testCompose() { Function<String, String> trim = TrimStringFunction.INSTANCE; Predicate<String> equalsFoo = Predicates.equalTo("Foo"); Predicate<String> equalsBar = Predicates.equalTo("Bar"); Predicate<String> trimEqualsFoo = Predicates.compose(equalsFoo, trim); Function<String, String> identity = Functions.identity(); assertTrue(trimEqualsFoo.apply("Foo")); assertTrue(trimEqualsFoo.apply(" Foo ")); assertFalse(trimEqualsFoo.apply("Foo-b-que")); new EqualsTester() .addEqualityGroup(trimEqualsFoo, Predicates.compose(equalsFoo, trim)) .addEqualityGroup(equalsFoo) .addEqualityGroup(trim) .addEqualityGroup(Predicates.compose(equalsFoo, identity)) .addEqualityGroup(Predicates.compose(equalsBar, trim)) .testEquals(); }
/** * Returns a convenient predicate on {@link ModuleTargeting}. * * <p>As this is used to determine if a conditional module should be installed, the device * incompatibility safety checks are not performed. Should this happen, the module will simply * fail the matching. */ public Predicate<ModuleTargeting> getModuleTargetingPredicate() { return Predicates.compose(this::matchesTargeting, this::getTargetingValue); }
/** * Returns a convenient predicate on {@link ApkTargeting} message. */ public Predicate<ApkTargeting> getApkTargetingPredicate() { return Predicates.compose(this::matchesTargeting, this::getTargetingValue); }
private List<Entry<Cell, byte[]>> postFilterEmptyValues( TableReference tableRef, Iterator<Entry<Cell, byte[]>> mergeIterators) { List<Entry<Cell, byte[]>> mergedWritesWithoutEmptyValues = new ArrayList<>(); Predicate<Entry<Cell, byte[]>> nonEmptyValuePredicate = Predicates.compose(Predicates.not(Value.IS_EMPTY), MapEntries.getValueFunction()); long numEmptyValues = 0; while (mergeIterators.hasNext()) { Entry<Cell, byte[]> next = mergeIterators.next(); if (nonEmptyValuePredicate.apply(next)) { mergedWritesWithoutEmptyValues.add(next); } else { numEmptyValues++; } } getMeter(AtlasDbMetricNames.CellFilterMetrics.EMPTY_VALUE, tableRef).mark(numEmptyValues); return mergedWritesWithoutEmptyValues; }
private List<Entry<Cell, byte[]>> getPostFilteredWithLocalWrites(final TableReference tableRef, final SortedMap<Cell, byte[]> postFiltered, final RangeRequest rangeRequest, List<RowResult<Value>> prePostFilter, final byte[] endRowExclusive) { Map<Cell, Value> prePostFilterCells = Cells.convertRowResultsToCells(prePostFilter); Collection<Entry<Cell, byte[]>> postFilteredCells = Collections2.filter( postFiltered.entrySet(), Predicates.compose( Predicates.in(prePostFilterCells.keySet()), MapEntries.getKeyFunction())); Collection<Entry<Cell, byte[]>> localWritesInRange = getLocalWritesForRange( tableRef, rangeRequest.getStartInclusive(), endRowExclusive).entrySet(); return mergeInLocalWrites( tableRef, postFilteredCells.iterator(), localWritesInRange.iterator(), rangeRequest.isReverse()); }
private NavigableMap<Cell, byte[]> getReadsInRange(TableReference table, RangeRequest range) { NavigableMap<Cell, byte[]> reads = getReadsForTable(table); if (range.getStartInclusive().length != 0) { reads = reads.tailMap(Cells.createSmallestCellForRow(range.getStartInclusive()), true); } if (range.getEndExclusive().length != 0) { reads = reads.headMap(Cells.createSmallestCellForRow(range.getEndExclusive()), false); } Map<Cell, byte[]> writes = writesByTable.get(table); if (writes != null) { reads = Maps.filterKeys(reads, Predicates.not(Predicates.in(writes.keySet()))); } if (!range.getColumnNames().isEmpty()) { Predicate<Cell> columnInNames = Predicates.compose( Predicates.in(range.getColumnNames()), Cell::getColumnName); reads = Maps.filterKeys(reads, columnInNames); } return reads; }
return; Predicate<CellConflict> conflicting = Predicates.compose( Predicates.in(conflictingCells), CellConflict.getCellFunction());
@Override public Set<RunningInstance> apply(Set<RegionAndName> regionAndIds) { if (checkNotNull(regionAndIds, "regionAndIds").isEmpty()) return ImmutableSet.of(); if (any(regionAndIds, compose(containsPattern("sir-"), nameFunction()))) return getSpots(regionAndIds); return super.apply(regionAndIds); }
protected void ensureGroupsExist(String group1Name, String group2Name) { Set<SecurityGroup> twoResults = client.describeSecurityGroupsInRegion(null, group1Name, group2Name); assertNotNull(twoResults); assertTrue(twoResults.size() >= 2);// in VPC could be multiple groups with the same name assertTrue(all(twoResults, compose(in(ImmutableSet.of(group1Name, group2Name)), new Function<SecurityGroup, String>() { @Override public String apply(SecurityGroup in) { return in.getName(); } }))); }
private static Predicate<String> boundedUnits(final long lowerBound, final long upperBound, final boolean caseSensitive, final String... suffixes) { return Predicates.or(Predicates.isNull(), Predicates.and(new HasSuffix(caseSensitive, suffixes), Predicates.compose(new Bounds(lowerBound, upperBound), new StripUnits()))); }
/** * Make sure that if there are args with multiple names (e.g. "-log" and "-verbose"), * the usage will only display it once. */ @Test public void repeatedArgs() { Cli<Args1> parser = singleCommandParser(Args1.class); CommandMetadata command = find(parser.getMetadata().getDefaultGroupCommands(), compose(equalTo("Args1"), CommandMetadata::getName)); assertEquals(command.getAllOptions().size(), 8); }
@Test(groups="Live") public void testReturnsStdout() throws Exception { feed = CmdFeed.builder() .entity(entity) .machine(machine) .poll(new CommandPollConfig<String>(SENSOR_STRING) .command("echo hello") .onSuccess(SshValueFunctions.stdout())) .build(); EntityAsserts.assertAttributeEventually(entity, SENSOR_STRING, Predicates.compose(Predicates.equalTo("hello"), StringFunctions.trim())); }