// Copyright 2000-2005 the Contributors, as shown in the revision logs. // Licensed under the Apache Public Source License 2.0 ("the License"). // You may not use this file except in compliance with the License. package org.ibex.js; import org.ibex.util.*; import java.util.*; public class JSString extends JSPrimitive { final String s; public JSString(String s) { this.s = s; } public int hashCode() { return s.hashCode(); } public boolean equals(Object o) { if(o == this) return true; if(o instanceof JSString) { return ((JSString)o).s.equals(s); } else if(o instanceof JSNumber) { return o.equals(this); } else { return false; } } private final static Map internHash = new HashMap(); static synchronized JS intern(String s) { synchronized(internHash) { JS js = (JS)internHash.get(s); if(js == null) internHash.put(s,js = new Intern(s)); return js; } } static class Intern extends JSString { public Intern(String s) { super(s); } protected void finalize() { synchronized(internHash) { internHash.put(s,null); } } } public String coerceToString() { return s; } }