1 // Copyright 2000-2005 the Contributors, as shown in the revision logs.
2 // Licensed under the Apache Public Source License 2.0 ("the License").
3 // You may not use this file except in compliance with the License.
7 import org.ibex.util.*;
10 public class JSString extends JSPrimitive {
12 public JSString(String s) { this.s = s; }
13 public int hashCode() { return s.hashCode(); }
15 public boolean equals(Object o) {
16 if(o == this) return true;
17 if(o instanceof JSString) {
18 return ((JSString)o).s.equals(s);
19 } else if(o instanceof JSNumber) {
20 return o.equals(this);
26 private final static Map internHash = new HashMap();
27 static synchronized JS intern(String s) {
28 synchronized(internHash) {
29 JS js = (JS)internHash.get(s);
30 if(js == null) internHash.put(s,js = new Intern(s));
34 static class Intern extends JSString {
35 public Intern(String s) { super(s); }
36 protected void finalize() { synchronized(internHash) { internHash.put(s,null); } }
39 public String coerceToString() { return s; }