Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

Cut.java

Go to the documentation of this file.
00001 package cedar.jetweb.job;
00002 
00003 import cedar.jetweb.util.Match;
00004 import cedar.jetweb.db.DBJobManager;
00005 import cedar.jetweb.Storeable;
00006 import cedar.jetweb.JetWebException;
00007 import java.util.Vector;
00008 
00009 public class Cut implements Storeable{
00010 
00011     private Integer id_=-1;
00012     private String name_="";
00013     private Double value_=null;
00014 
00015     public Cut(Integer id){
00016     id_ = id;
00017     try{
00018         DBJobManager.selectFromDB(this);
00019     }catch(JetWebException err){
00020         System.out.println(err.getMessage());
00021         err.printStackTrace();
00022     }
00023     }
00024 
00025     public Cut(String name, Double value){
00026     name_ = name;
00027     value_ = value;
00028     try{
00029         DBJobManager.selectFromDB(this);
00030     }catch(JetWebException err){
00031         System.out.println(err.getMessage());
00032         err.printStackTrace();
00033     }
00034     }
00035 
00036     public int getId(){
00037     return id_;
00038     }
00039 
00040     public Cut setId(Integer id){
00041     id_ = id;
00042     return this;
00043     }
00044 
00045     public String getName(){
00046     if(id_>0 && name_.equals("")) {
00047         try{
00048         retrieve();
00049         }catch(JetWebException err){
00050         System.out.println("unable to retrieve cut from data base");
00051         err.printStackTrace();
00052         }
00053     }
00054     return name_;
00055     }
00056 
00057     public Cut setName(String name){
00058     name_ = name;
00059     return this;
00060     }
00061 
00062     public Double getValue(){
00063     if(id_>0 && value_==null) {
00064         try{
00065         retrieve();
00066         }catch(JetWebException err){
00067         System.out.println
00068             ("Cut.getValue(): unable to retrvieve cut from data base");
00069         err.printStackTrace();
00070         }
00071     }
00072 
00073     return value_;
00074     }
00075 
00076     public Cut setValue(Double value){
00077     value_ = value;
00078     return this;
00079     }
00080 
00081     public boolean store()
00082     throws JetWebException{
00083 
00084     //if no id and value/name present then nothing to store
00085     if(id_<0 && (value_==null || name_.equals(""))) return false;
00086     DBJobManager.addToDB(this);
00087     return true;
00088     }
00089 
00090     public boolean retrieve()
00091     throws JetWebException{
00092     if(id_<0 &&(value_==null || name_.equals("")))return false;
00093     return DBJobManager.selectFromDB(this);
00094     }
00095 
00096     //less than operator
00097     // No operator overloading in java :( 
00098     public boolean lt(Cut cut){
00099     if(cut.getValue()==null ||
00100        value_==null)return false;
00101     if (!cut.getName().equals(name_))return false;
00102     return(value_ < cut.getValue());
00103     }
00104 
00105     //greater than operator
00106     public boolean gt(Cut cut){
00107     if (!cut.getName().equals(name_))return false;
00108     return(value_ > cut.getValue());
00109     }
00110 
00111     //equals operator
00112     public boolean equals(Cut cut){
00113     if (!cut.getName().equals(name_))return false;
00114     return Match.compareDouble(value_, cut.getValue());
00115     }
00116 }

Generated Wed Jan 17 09:14:27 GMT 2007