]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/common/names/Name.java
(refs #7250) Merging master, minor CHR bugfixes
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / common / names / Name.java
1 package org.simantics.scl.compiler.common.names;
2
3 import org.simantics.scl.compiler.internal.types.HashConsing;
4
5 public final class Name {
6     public static final Name[] EMPTY_ARRAY = new Name[0];
7     
8     public final String module;
9     public final String name;
10     
11     private Name(String module, String name) {
12         this.module = module;
13         this.name = name;
14     }
15     
16     private static final HashConsing<Name> nameCache = 
17             new HashConsing<Name>() {
18         protected boolean equals(Name a, Name b) {
19             return a.name.equals(b.name) && a.module.equals(b.module);
20         }
21
22         protected int hashCode(Name obj) {
23             return obj.module.hashCode()*31 + obj.name.hashCode();
24         }
25     };
26     
27     public String toString() {
28         return module + "/" + name;
29     }
30     
31     public static Name create(String module, String name) {
32         return nameCache.canonical(new Name(module, name));
33     }
34 }