]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/common/names/Name.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / common / names / Name.java
diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/common/names/Name.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/common/names/Name.java
new file mode 100755 (executable)
index 0000000..04f2f91
--- /dev/null
@@ -0,0 +1,34 @@
+package org.simantics.scl.compiler.common.names;
+
+import org.simantics.scl.compiler.internal.types.HashConsing;
+
+public final class Name {
+    public static final Name[] EMPTY_ARRAY = new Name[0];
+    
+    public final String module;
+    public final String name;
+    
+    private Name(String module, String name) {
+        this.module = module;
+        this.name = name;
+    }
+    
+    private static final HashConsing<Name> nameCache = 
+            new HashConsing<Name>() {
+        protected boolean equals(Name a, Name b) {
+            return a.name.equals(b.name) && a.module.equals(b.module);
+        }
+
+        protected int hashCode(Name obj) {
+            return obj.module.hashCode()*31 + obj.name.hashCode();
+        }
+    };
+    
+    public String toString() {
+        return module + "/" + name;
+    }
+    
+    public static Name create(String module, String name) {
+        return nameCache.canonical(new Name(module, name));
+    }
+}