diff src/nabble/naml/compiler/Usage.java @ 0:7ecd1a4ef557

add content
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 21 Mar 2019 19:15:52 -0600
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/nabble/naml/compiler/Usage.java	Thu Mar 21 19:15:52 2019 -0600
@@ -0,0 +1,48 @@
+package nabble.naml.compiler;
+
+import java.util.Arrays;
+import java.util.List;
+import fschmidt.util.java.Interner;
+
+
+public final class Usage {
+	private final GenericNamespace[] base;
+	private final List<Macro> macroPath;
+
+	Usage(GenericNamespace[] base,List<Macro> macroPath) {
+		this.base = base;
+		this.macroPath = macroPath;
+	}
+
+	public String[] baseIds() {
+		String[] a = new String[base.length];
+		for( int i=0; i<base.length; i++ ) {
+			a[i] = base[i].getId();
+		}
+		return a;
+	}
+
+	public List<Macro> macroPath() {
+		return macroPath;
+	}
+
+	@Override public boolean equals(Object obj) {
+		if( !(obj instanceof Usage) )
+			return false;
+		Usage t = (Usage)obj;
+		return Arrays.equals(t.base,base) && t.macroPath.equals(macroPath);
+	}
+
+	@Override public int hashCode() {
+		int hash = Arrays.hashCode(base);
+		hash = 31*hash + macroPath.hashCode();
+		return hash;
+	}
+
+	private static final Interner<Usage> interner = new Interner<Usage>();
+
+	Usage intern() {
+		return interner.intern(this);
+	}
+
+}