public String map(String name) {
        if (classes.containsKey(name)) {
            return classes.get(name);
        } else if (default_package != null && !name.contains("/")) {
            return default_package + "/" + name;
        } else {
            String best_match = "";

            for (String pkg : packages.keySet()) {
                if (pkg.length() > best_match.length()
                    && name.startsWith(pkg + "/")) {
                    best_match = pkg;
                }
            }

            if (best_match.length() > 0) {
                String mapping = packages.get(best_match);
                if (mapping.equals(".")) {
                    return name.substring(best_match.length() + 1);
                } else {
                    return mapping + name.substring(best_match.length());
                }
            }
        }

        return name;
    }