Uploaded to www.rart.com/j2me-presentation/html_Source/ March 19, 2002

The uParameter Class

This class provides the basis for Observer interaction with a Rart universe in the AWT environment. It is virtually unchanged for the J2ME environment.

This version will be part of the RDK 2.0 release, Spring 2002. It is basically unchanged from RDK 1.0, and has been tested with JDK 1.1.8.

 
/* 
 * @uParameter   1.0  010915 
 * 
 * © A-Square, Inc.   
 * 1648 Waters Edge Lane, Reston Virginia, 20190, USA  
 */
package rartme;		// for J2ME
//package rartbase;		// for JDK 1.1.8 

public class uParameter {
/**
 * A class allowing observer interaction with a Rart universe
 *
 * @version 1.0  010915 
 *
 * @author Jan Aminoff
 *
 * This class provides the basic data structure to allow an observer to
 * modify the execution of any universe extending Universe.
 * Such modification is part of the Rart concept as implemented 
 * in Java and forms an integral part of the Rart Development Kit
 *
 * Released as part of RDK and is identical for the rartbasis and rartme 
 * packages. Documentation comments inserted for the rartme version.
 */
	 // Section 1	  Constructors
	 /**
	  * general constructor, internal version. * This version of the constructor 
	  * is only called from within the class.
	  * @param	index		index, selected from constants in Universe/ UniverseME
	  *						and used to index the array of uParameters in Universe
	  * @param	name		string, descriptive name
	  * @param	min	minimum value of parameter
	  * @param	cur	current value of parameter
	  * @param	max	maximum value of parameter
	  */
	 public uParameter(int indx, String name, int min, int cur, int max){
		 this.name = name;
		 index = indx;
		 this.max = max;		// maximum value
		 current = cur;		// current is current value of parameter
		 this.min = min;		// minimum value
		 step = (max-min)/10;		// ten steps between minimum and maximum value
		 step=(step>0)? step : 1;	// with 1, smallest stepsize
		 description=null;
		 choicearray=null;
	}	//end uParameter internal version
	
	 /**
  	  * Constructor for a uPparameter, where the current value is an integer 
	  * no smaller than min and smaller than max.
	  * @param	indx		index, selected from constants in Universe/UniverseME
	  *						and used to index the array of uParameters in Universe
	  * @param	name		string, descriptive name
	  * @param	min		minimum value of parameter
	  * @param	cur		current value of parameter
	  * @param	max		maximum value of parameter
	  * @param	desc		string, short (max 70 for ME, 300 for SE) description
	  */
	public uParameter( int indx, String name, 
				int min, int cur, int max, String desc){
		 this(indx, name, min, cur, max);
		 description = desc;	// desc describes the uParameter
	 }	// end of constructor for integer valued parameter

	/** 
	 * Constructor for a uParameter, where the current value is integer index
	 * to an array of strings of choices. The integer value is within the 
	 * range 0 to length-1, where length is the length of the choices array.
  	 * 
	 * @param	indx	index, selected from constants in Universe/ UniverseME
	 *						and used to index the array of uParameters in Universe
	 * @param	name		string, descriptive name
	 * @param	cur		current value of parameter as index to choices array
	 * @param	choices	an array of strings describing the choices
	 * @param	desc		string, short (max 70 for ME, 300 for SE) description
	 */
	public uParameter( int indx, String name, 
			int cur , String[] choices, String desc){
		this(indx, name, 0, cur, choices.length);
		description = desc; // desc descries the uParameter
		// The array gives the alternatives as an array of strings
		choicearray = choices;
	}	// end constructor for choice valued uParameter
	 
	// Section 2	  Getters and Setters
	
	/**	 
	 * @return 	String name, the name of the uParameter
	 */
	 public String getName(){ return name;}

	/**
	 * @return index, the index of the uParameter in the uParameter array
	 * 					in Universe (or UniverseME).
	 */
	 public int getIndex(){return index;}

	/**
	 * @return current, the current value of the uParameter
	 */
	 public int getCur(){ return current;}

	/**
	 * @return max, the maximum value of the uParameter 
	 */
	 public int getMax() {return max;}

	/**
	 * @return min, the minimum value of the uParameter 
	 */ 
	 public int getMin() {return min;}
	 
	/**
	 * @return step, approximately one tenth of the interval 
	 * 			max-min. Used to  step the value of the uParameter
	 */
	 public int getStep() {return step;}

	/**
	 * @return description, rartist provided string describing
  	 * 		the use of the uParameter 
	 */
	 public String getDescr(){return description;}
	 
	/**
	 * @return choicearray, the array of strings describing the choices.
	 */
	 public String[] getChoices(){return choicearray;}
	
	/**
	 * Used to reset the value of the uParameter
	 * @param cur, the proposed new value of the uParameter
	 */
	 public void setCur(int cur){
		  // if cur is below range, set val to min
			int val=(cur < min )	 ? min : cur;
			// if cur is above range, set val to max	 
			val=(cur > max)? max : cur;			 
			// step is the interval max-min divided by 10. If the proposed value val
			// is exactly max + step, then we set current to min. This has the effect
			// of cycling the parameter in the range min to max in 10 steps.
			current=((max+step) == cur)? min : val;
	 }
	 
	 // Section 3	Private variables	 
	 private String name;	 
	 private int index, min, current, max, step; 
	 private String description;
	 private String[] choicearray;
}	// End of uParameter class