1 package net.sf.jhunlang.jmorph; 2 3 import java.io.Serializable; 4 5 import java.util.HashMap; 6 import java.util.Map; 7 8 public class Conditionsmap implements Serializable 9 { 10 /*** 11 * The {@link Conditions#index} of the <code>Conditions</code> created next. 12 */ 13 protected int nextIndex; 14 /*** 15 * Stores different interned Conditions instances 16 */ 17 protected final Map conds = new HashMap(); 18 19 public int size() 20 { 21 return conds.size(); 22 } 23 24 /*** 25 * Return the <code>Conditions</code> instance wrapping 26 * <code>conditions</code>. Look for the instance in {@link #conds} 27 * and return it if found. Otherwise create a new <code>Conditions</code> 28 * instance and put it into {@link #conds} and return the new instance. 29 * @param conditions the {@link Condition} array to wrap 30 * @return the <code>Conditions</code> instance wrapping 31 * <code>conditions</code> 32 */ 33 public Conditions getConditions(Condition[] conditions) 34 { 35 Conditions c = new Conditions(conditions); 36 Conditions old = (Conditions)conds.get(c); 37 if (old == null) 38 { 39 c.setIndex(nextIndex++); 40 old = c; 41 conds.put(old, old); 42 } 43 return old; 44 } 45 }