### Question:
HasTypesCollectors { public static <T extends HasTypes> Collector<T, ?, List<T>> matchingTypes( T hasTypes ) { return hasTypesToListCollector( hasTypes, new HasAssignableFromType<>( hasTypes ) ); } private  HasTypesCollectors(); static Collector<T, ?, Optional<T>> matchingType( T hasTypes ); static Collector<T, ?, Optional<T>> closestType( T hasTypes ); static Collector<T, ?, List<T>> matchingTypes( T hasTypes ); static Collector<T, ?, List<T>> closestTypes( T hasTypes ); static Collector<T, ?, Optional<T>> matchingType( Type type ); static Collector<T, ?, Optional<T>> closestType( Type type ); static Collector<T, ?, List<T>> matchingTypes( Type type ); static Collector<T, ?, List<T>> closestTypes( Type type );  }### Answer:
@Test public void selectMatchingTypes() { List<ValueType> valueTypes = Arrays.asList( ValueType.of( String.class ), ValueType.of( Integer.class ), ValueType.of( Number.class ) ); List<ValueType> number = valueTypes.stream().collect( HasTypesCollectors.matchingTypes( Number.class ) ); assertThat( number.size(), is( 2 ) ); assertThat( number.get( 0 ), equalTo( ValueType.of( Number.class ) ) ); assertThat( number.get( 1 ), equalTo( ValueType.of( Integer.class ) ) ); List<ValueType> integer = valueTypes.stream().collect( HasTypesCollectors.matchingTypes( Integer.class ) ); assertThat( integer.size(), is( 1 ) ); assertThat( integer.get( 0 ), equalTo( ValueType.of( Integer.class ) ) ); }
@Test public void selectMatchingValueTypes() { List<ValueType> valueTypes = Arrays.asList( ValueType.of( String.class ), ValueType.of( Number.class, Integer.class ), ValueType.of( Integer.class ), ValueType.of( Number.class ) ); List<ValueType> number = valueTypes.stream() .collect( HasTypesCollectors.matchingTypes( ValueType.of( Number.class ) ) ); System.out.println( number ); assertThat( number.size(), is( 2 ) ); assertThat( number.get( 0 ), equalTo( ValueType.of( Number.class ) ) ); assertThat( number.get( 1 ), equalTo( ValueType.of( Number.class, Integer.class ) ) ); List<ValueType> integer = valueTypes.stream() .collect( HasTypesCollectors.matchingTypes( ValueType.of( Integer.class ) ) ); assertThat( integer.size(), is( 2 ) ); assertThat( integer.get( 0 ), equalTo( ValueType.of( Integer.class ) ) ); assertThat( integer.get( 1 ), equalTo( ValueType.of( Number.class, Integer.class ) ) ); List<ValueType> both = valueTypes.stream() .collect( HasTypesCollectors.matchingTypes( ValueType.of( Number.class, Integer.class ) ) ); assertThat( both.size(), is( 1 ) ); assertThat( both.get( 0 ), equalTo( ValueType.of( Number.class, Integer.class ) ) ); }