public static <T> List<Set<T>> split(Set<T> original, int subsetSize) {

    if(subsetSize <= 0) {
      throw new IllegalArgumentException("Incorrect max size");
    }

    if(original == null || original.isEmpty()) {
      return Collections.emptyList();
    }

    int subsetCount = (int) (Math.ceil((double)original.size() / subsetSize));
    ArrayList<Set<T>> subsets = new ArrayList<>(subsetCount);
    Iterator<T> iterator = original.iterator();

    for(int i = 0; i < subsetCount; i++) {
      Set<T> subset = new LinkedHashSet<>(subsetSize);
      for(int j = 0; j < subsetSize && iterator.hasNext(); j++) {
        subset.add(iterator.next());
      }
      subsets.add(subset);
    }
    return subsets;
  }
Split a set into subsets
@param original The original set to be split
@param subsetSize Size of the subset (except for final subset)
@param <T> Data type of set elements
@return List of subsets
ambari-server/src/main/java/org/apache/ambari/server/utils/SetUtils.java