import java.util.Arrays;
import java.util.Iterator;
-import java.util.Map.Entry;
import gnu.trove.map.hash.THashMap;
public class ModuleNameTreeEntry implements Comparable<ModuleNameTreeEntry> {
+ public static final String STANDARD_LIBRARY = "StandardLibrary";
+ public static final String HTTP_PREFIX = "http://";
+
public final ModuleNameTreeEntry parent;
public final String fullName;
public final String name;
public void addModule(String moduleFullName) {
int startingPos = fullName.isEmpty() ? 0 : fullName.length()+1;
- int p = moduleFullName.indexOf('/', startingPos);
+ int p;
+ if(parent == null && moduleFullName.startsWith(HTTP_PREFIX))
+ p = moduleFullName.indexOf('/', HTTP_PREFIX.length());
+ else
+ p = moduleFullName.indexOf('/', startingPos);
if(p == -1) {
- String name = moduleFullName.substring(startingPos);
- ModuleNameTreeEntry entry = getOrCreateChildMapEntry(name);
- entry.isModule = true;
+ if(parent == null) {
+ getOrCreateChildMapEntry(STANDARD_LIBRARY).addModule(name);
+ }
+ else {
+ String name = moduleFullName.substring(startingPos);
+ ModuleNameTreeEntry entry = getOrCreateChildMapEntry(name);
+ entry.isModule = true;
+ }
}
else {
String name = moduleFullName.substring(startingPos, p);
private ModuleNameTreeEntry getOrCreateChildMapEntry(String name) {
ModuleNameTreeEntry entry = childMap.get(name);
if(entry == null) {
- String newFullName = fullName.isEmpty() ? name : fullName + "/" + name;
+ String newFullName;
+ if(parent == null) {
+ if(name.equals(STANDARD_LIBRARY))
+ newFullName = "";
+ else
+ newFullName = name;
+ }
+ else
+ newFullName = fullName + "/" + name;
entry = new ModuleNameTreeEntry(this, newFullName, name);
childMap.put(name, entry);
}