package org.neurostruct.script.devel;

import java.util.HashSet;
import java.util.Iterator;
 
public class State {
   
      HashSet outActions = new HashSet();
      
      HashSet inActions = new HashSet();
    
      double value;
      
      boolean bdone = false;
      
      
      public State() {
         outActions.add(new Action(this, 0.));
         outActions.add(new Action(this, 90.));
         outActions.add(new Action(this, 180));
         outActions.add(new Action(this, 270.));
      }
     

      void remove(Action action) {
         outActions.remove(action);
      }
   
     
      void updateSource(Action a) {
         if (inActions.contains(a)) {
            // nothing to do;
         } else {
            inActions.add(a);
            a.setTo(this);
            if (inActions.size() > 4) {
     //          E.info("too many ways to get here? " + this);
            }
         }
      }
      
     
      void clearValue() {
          value = 0; 
          bdone = false;
      }
      public void setValue(double d) {
         value = d;
         bdone = true;
      }
      public boolean doneValue() {
          return bdone;
      }
      
      public double getValue() {
         return value;
      }





      
	public double[] getValueRange() {
		double vmin = 0.;
		double vmax = 1.;
	
	    for (Iterator it = outActions.iterator(); it.hasNext(); ) {
		     Action a = (Action)it.next();
	         double v = a.getValue();
	         if (v > vmax) {
	        	 vmax = v;
	         }
	         if (v < vmin) {
	        	 vmin = v;
	         }
	      }
	      double[] ret = {vmin, vmax};
		return ret;
	}





	public Iterator getInActionsIterator() {
		return inActions.iterator();
	}





	public Iterator getActionsIterator() {
		return outActions.iterator();
	}
       
      
}
