1 package cz.cuni.amis.utils.flag.connective; 2 3 import java.util.Map; 4 import java.util.WeakHashMap; 5 6 import cz.cuni.amis.utils.flag.Flag; 7 8 public class Or extends Connective { 9 10 private static Map<Or, Or> ors = new WeakHashMap<Or, Or>(); 11 12 public static Or get(Flag<Boolean> flag1, Flag<Boolean> flag2) { 13 return get(new Flag[]{flag1, flag2}); 14 } 15 16 public static Or get(Flag<Boolean>[] flags) { 17 synchronized(ors) { 18 Or or = new Or(flags); 19 Or existingOr = ors.get(or); 20 if (existingOr != null) return existingOr; 21 ors.put(or, or); 22 return or; 23 } 24 } 25 26 private Or(Flag<Boolean>[] states) { 27 super(states); 28 } 29 30 @Override 31 protected void truthValueChanged() { 32 synchronized(truthValue) { 33 setFlag(truthValue[0] > 0); 34 } 35 36 } 37 38 } 39