package wol.scnr;

//Author: Guangming He
//Begins: Sept 29 2005.
//Thinning scenario

/*
USAGE:
	only be used by Class Stand to calculate fuelwood production of a Japanese larch stand
	parameters need to be initialized first
*/

 import java.sql.SQLException;
 import java.sql.Connection;
 import oracle.sql.ORAData;
 import oracle.sql.ORADataFactory;
 import oracle.sql.Datum;
 import oracle.sql.STRUCT;
 import oracle.sql.StructDescriptor;
 import oracle.sql.NUMBER;

public class ThinScnr implements ORAData, ORADataFactory {
    
    //these 3 parameters to define a thinning scenario
    
 	static final ThinScnr _thinscnrFactory = new ThinScnr();
 	public static ORADataFactory getFactory()
 	{
 		return _thinscnrFactory;
 	}
 	
 	//Constructors
 	public ThinScnr() {};
 	public ThinScnr(NUMBER cycle2,  NUMBER startgAge2,  NUMBER endAge2, NUMBER intensity2) throws SQLException
 	{
 		System.out.println("StructDescriptor: new called ");
 		this.cycle = cycle2;
 		this.startAge = startAge2;
 		this.endAge = endAge2;
 		this.intensity = intensity2;
 	}
 	

 	//ORADATA interface
 	public Datum toDatum(Connection c ) throws SQLException
 	{
 		StructDescriptor sd = StructDescriptor.createDescriptor("HEGUANGM.THINSCNR", c);
 		
 		Object [] attributes = { cycle, startAge, endAge, intensity };
 		
 		return new STRUCT(sd, c, attributes);
 		
 	}

 	//ORADATAFactory interface
 	public ORAData create(Datum d, int sqlType) throws SQLException
 	{
 		if (d==null) return null;
 		System.out.println("Creating: ");
 		System.out.println(d);
 		
 		Object [] attributes = ((STRUCT) d).getAttributes();
 		
 		System.out.println(" Desc Type: " + ((STRUCT) d).getDescriptor().descType());
		System.out.println(" Desc Len: " + ((STRUCT) d).getDescriptor().getLength());
		
 		System.out.println(attributes[0]);
 		System.out.println(attributes[1]);
 		System.out.println(attributes[2]);
 		System.out.println(attributes[3]);
 		
 		return new ThinScnr( new NUMBER( attributes[0]), new NUMBER( attributes[1] ), 
 							 new NUMBER( attributes[2]), new NUMBER( attributes[3] ) );
 		 
 	}
 	public boolean isEqualTo(ThinScnr pThinScnr)
 	{
 		return (this.cycle.compareTo(pThinScnr.cycle)==0 
 					&& this.startAge.compareTo(pThinScnr.startAge)==0
 					&& this.endAge.compareTo(pThinScnr.endAge)==0 
 					&& this.intensity.compareTo(pThinScnr.intensity)==0);
 	}

 	public String toString()
 	{
 		String s = " ";
 		try{
 		
	 		s = new String(" cycle: " + cycle.intValue() +
	 						  " startAge: " + startAge.intValue() +
	 						  " endAge: " + endAge.intValue() +
	 						  " intensity: " + intensity.doubleValue()
	 						 );
	 	}
	 	catch  (SQLException sqle)
	 	{
	 		System.out.println(sqle.toString());
	 	}
 		return s;
 	}
 	
 	public int getCycle() throws SQLException { return cycle.intValue(); }
 	public int getStartAge() throws SQLException { return startAge.intValue();}
 	public int getEndAge() throws SQLException { return endAge.intValue();}
 	public double getIntensity() throws SQLException {return intensity.doubleValue(); }

	//cycle startAge intensity
    public NUMBER cycle; 
    public NUMBER startAge; 
    public NUMBER endAge;
    public NUMBER intensity;
	
}
