![JAR search and dependency download from the Maven repository](/logo.png)
com.avaje.ebean.enhance.agent.DistillPackages Maven / Gradle / Ivy
package com.avaje.ebean.enhance.agent;
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 {
private TreeSet treeSet = new TreeSet();
/**
* Add packages that we want to distill.
*/
DistillPackages add(Collection packages) {
if (packages != null) {
treeSet.addAll(packages);
}
return this;
}
/**
* Add a raw entry splitting it into individual packages by delimiters.
*/
DistillPackages addRaw(String packages) {
if (packages != null) {
String[] split = packages.split(",|;| ");
for (int i = 0; i < split.length; i++) {
String pkg = split[i].trim();
if (!pkg.isEmpty()) {
treeSet.add(pkg);
}
}
}
return this;
}
/**
* Distill the list of packages into distinct top level packages.
*/
List distill() {
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 boolean notAlreadyContained(List distilled, String pack) {
for (int i = 0; i < distilled.size(); i++) {
if (pack.startsWith(distilled.get(i))) {
return false;
}
}
return true;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy