AggregationArguments { public <T extends Expression> Optional<T> keyword(final String key, Class<T> expected) { return Optional.ofNullable(kw.remove(key)).map(v -> v.cast(expected)); } AggregationArguments(
        final List<? extends Expression> args, final Map<String, ? extends Expression> kw
    ); List<T> all(final Class<T> expected); Optional<T> positionalOrKeyword(
        final String key, Class<T> expected
    ); Optional<T> positional(Class<T> expected); Optional<T> keyword(final String key, Class<T> expected); void throwUnlessEmpty(final String name);  }
@Test public void keyword() { final AggregationArguments arguments = new AggregationArguments(ImmutableList.of(), ImmutableMap.of("a", a, "b", b)); assertEquals(Optional.of(a), arguments.keyword("a", Expression.class)); assertEquals(Optional.empty(), arguments.keyword("a", Expression.class)); assertEquals(Optional.of(b), arguments.keyword("b", Expression.class)); verify(a).cast(Expression.class); verify(b).cast(Expression.class); }