001package io.ebean.enhance.querybean;
002
003import java.util.Collection;
004
005/**
006 * Helper for parsing, merging and converting packages.
007 */
008public class Distill {
009
010  /**
011  * Convert the dot notation entity bean packages to slash notation.
012  *
013  * @param packages entity bean packages
014  */
015  public static DetectQueryBean convert(Collection<String> packages) {
016
017    String[] asArray = packages.toArray(new String[packages.size()]);
018    for (int i = 0; i < asArray.length; i++) {
019      asArray[i] = convert(asArray[i]);
020    }
021    return new DetectQueryBean(asArray);
022  }
023
024  /**
025  * Convert package to slash notation taking into account trailing wildcard.
026  */
027  private static String convert(String pkg) {
028
029    pkg = pkg.trim();
030    if (pkg.endsWith("*")) {
031      pkg = pkg.substring(0, pkg.length() - 1);
032    }
033    if (pkg.endsWith(".query")) {
034      // always work with entity bean packages so trim
035      pkg = pkg.substring(0, pkg.length() - 6);
036    }
037    pkg = pkg.replace('.', '/');
038    return pkg.endsWith("/") ? pkg : pkg + "/";
039  }
040}