1 28 29 package org.jruby.ast.visitor.rewriter.utils; 30 31 import java.util.EmptyStackException ; 32 import java.util.Stack ; 33 34 public class BooleanStateStack { 35 36 private final Stack states = new Stack (); 37 private final boolean defaultValue; 38 39 40 public BooleanStateStack(boolean b, boolean defaultValue) { 41 set(b); 42 this.defaultValue = defaultValue; 43 } 44 45 public void set(boolean b) { 46 states.push(Boolean.valueOf(b)); 47 } 48 49 public void revert() { 50 states.pop(); 51 } 52 53 public boolean isTrue() { 54 try { 55 return ((Boolean ) states.peek()).booleanValue(); 56 } catch (EmptyStackException e) { 57 return defaultValue; 58 } 59 } 60 } 61 | Popular Tags |