All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.ebeaninternal.server.core.bootup.DistillPackages Maven / Gradle / Ivy

There is a newer version: 15.8.1
Show newest version
package io.ebeaninternal.server.core.bootup;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.TreeSet;

/**
 * Distill packages into distinct top level packages for searching.
 */
class DistillPackages {


  /**
   * Distill the list of packages into distinct top level packages.
   */
  static List distill(Collection packages, Collection mfPackages) {

    // sort into natural order
    TreeSet treeSet = new TreeSet<>();
    treeSet.addAll(packages);
    treeSet.addAll(mfPackages);

    List distilled = new ArrayList<>();

    // build the distilled list
    for (String pack : treeSet) {
      if (notAlreadyContained(distilled, pack)) {
        distilled.add(pack);
      }
    }

    return distilled;
  }

  /**
   * Return true if the package is not already contained in the distilled list.
   */
  private static boolean notAlreadyContained(List distilled, String pack) {

    for (String aDistilled : distilled) {
      if (pack.startsWith(aDistilled)) {
        return false;
      }
    }
    return true;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy