private static Set<HttpMethod> initAllowedHttpMethods(Set<HttpMethod> declaredMethods) { if (declaredMethods.isEmpty()) { return EnumSet.allOf(HttpMethod.class).stream() .filter(method -> method != HttpMethod.TRACE) .collect(Collectors.toSet()); } else { Set<HttpMethod> result = new LinkedHashSet<>(declaredMethods); if (result.contains(HttpMethod.GET)) { result.add(HttpMethod.HEAD); } result.add(HttpMethod.OPTIONS); return result; } }
private static void verifyBroadcastPartitioning(List<Tuple2<Integer, String>> broadcastPartitionResult) { final Set<Tuple2<Integer, String>> expectedResult = INPUT.stream().flatMap( input -> IntStream.range(0, PARALLELISM).mapToObj( i -> Tuple2.of(i, input))) .collect(Collectors.toSet()); assertEquals( expectedResult, new HashSet<>(broadcastPartitionResult)); }
private static Set<Field> findAnnotatedFields(Class<?> testClass, boolean isStaticMember) { final Set<Field> set = Arrays.stream(testClass.getDeclaredFields()). filter(m -> isStaticMember == Modifier.isStatic(m.getModifiers())). filter(m -> DropwizardExtension.class.isAssignableFrom(m.getType())). collect(Collectors.toSet()); if (!testClass.getSuperclass().equals(Object.class)) { set.addAll(findAnnotatedFields(testClass.getSuperclass(), isStaticMember)); } return set; }
public Set<String> getAllTables(String schema) throws SchemaNotFoundException { ImmutableSet.Builder<String> builder = ImmutableSet.builder(); builder.addAll(ImmutableList.copyOf(client.getDatabase(schema).listCollectionNames()).stream() .filter(name -> !name.equals(schemaCollection)) .filter(name -> !SYSTEM_TABLES.contains(name)) .collect(toSet())); builder.addAll(getTableMetadataNames(schema)); return builder.build(); }
@Test public void selectByKeys_throws_IAE_when_keys_contains_empty_string() { Random random = new Random(); Set<String> keysIncludingAnEmptyString = Stream.of( IntStream.range(0, random.nextInt(10)).mapToObj(i -> "b_" + i), Stream.of(""), IntStream.range(0, random.nextInt(10)).mapToObj(i -> "a_" + i)) .flatMap(s -> s) .collect(Collectors.toSet()); expectKeyNullOrEmptyIAE(); underTest.selectByKeys(dbSession, keysIncludingAnEmptyString); }