Пример #1
0
 public static HashMap<Long, Long> factorization(long num) {
   if (num == 1) {
     return HashMap.empty();
   } else {
     return primeFactors(num)
         .map(p -> HashMap.of(Tuple.of(p, 1L)).merge(factorization(num / p), (a, b) -> a + b))
         .orElseGet(HashMap::empty);
   }
 }
Пример #2
0
 @Test
 public void shouldConvertToMap() {
   final Value<Integer> value = of(1, 2, 3);
   final Map<Integer, Integer> map = value.toMap(v -> Tuple.of(v, v));
   if (value.isSingleValued()) {
     assertThat(map).isEqualTo(HashMap.of(1, 1));
   } else {
     assertThat(map).isEqualTo(HashMap.empty().put(1, 1).put(2, 2).put(3, 3));
   }
 }
Пример #3
0
 @Override
 public <C> Map<C, HashMap<K, V>> groupBy(Function<? super Tuple2<K, V>, ? extends C> classifier) {
   Objects.requireNonNull(classifier, "classifier is null");
   return foldLeft(
       HashMap.empty(),
       (map, entry) -> {
         final C key = classifier.apply(entry);
         final HashMap<K, V> values =
             map.get(key).map(entries -> entries.put(entry)).orElse(HashMap.of(entry));
         return map.put(key, values);
       });
 }
Пример #4
0
 public Map<String, String> getResponseHeaders(Request request) {
   String fallbackAllowOriginValue = allowedOrigins.mkString(",");
   return HashMap.of(
       ACCESS_CONTROL_ALLOW_ORIGIN_HEADER,
           isAllowed(request)
               ? request.getHeader(ORIGIN_HEADER).getOrElse(fallbackAllowOriginValue)
               : fallbackAllowOriginValue,
       ACCESS_CONTROL_ALLOW_CREDENTIALS_HEADER, "true",
       ACCESS_CONTROL_EXPOSE_HEADERS_HEADER, "*",
       ACCESS_CONTROL_ALLOW_HEADERS_HEADER, "*",
       ACCESS_CONTROL_MAX_AGE_HEADER, "1800",
       ACCESS_CONTROL_ALLOW_METHODS_HEADER, "*");
 }