Пример #1
0
 public static <V> Map<String, V> parseToMap(JsonObject jo) {
   Map<String, V> map = CollectionKit.newHashMap();
   if (jo != null) {
     List<String> names = jo.names();
     for (String name : names) {
       map.put(name, (V) jo.get(name));
     }
   }
   return map;
 }
Пример #2
0
  /** 集合交集 */
  public static final <T> Set<T> intersection(Set<T> set1, Set<T> set2) {
    if (set1 == null || set2 == null) {
      return null;
    }

    if (set1.isEmpty() || set2.isEmpty()) {
      return Collections.emptySet();
    }

    Set<T> result = CollectionKit.createHashSet();
    Set<T> smaller = (set1.size() > set2.size()) ? set2 : set1;
    Set<T> bigger = (smaller == set2) ? set1 : set2;

    for (T value : smaller) {
      if (bigger.contains(value)) {
        result.add(value);
      }
    }
    return result;
  }