00001 package cedar.jetweb.model; 00002 00003 import java.util.Enumeration; 00004 import java.util.Vector; 00005 import java.util.Date; 00006 00007 import cedar.jetweb.*; 00008 import cedar.jetweb.model.plots.DataPlot; 00009 import cedar.jetweb.db.DBManager; 00010 import cedar.jetweb.job.CutCollection; 00011 import cedar.jetweb.JetWebException; 00012 00018 public class RunSeriesCollection implements Storeable { 00019 00020 private Vector<RunSeries> runSeriesList; 00021 private int id = -1; 00022 00026 public RunSeriesCollection(){ 00027 runSeriesList = new Vector<RunSeries>(); 00028 } 00029 00036 public RunSeriesCollection(int id) throws JetWebException { 00037 runSeriesList = new Vector<RunSeries>(); 00038 this.id = id; 00039 retrieve(); 00040 } 00041 00042 00043 public boolean retrieve() throws JetWebException { 00044 00045 if (id < 0) { 00046 throw new JetWebException("Tried to retrieve RunSeriesCollection with no id","error"); 00047 } 00048 try { 00049 DBManager.selectFromDB(this); 00050 } catch (Exception e) { 00051 throw new JetWebException(e,"Error retrieving RunSeriesCollection"); 00052 } 00053 return true; 00054 } 00055 00056 public boolean store() throws JetWebException { 00057 00058 if (id>=0) { 00059 return DBManager.updateDB(this); 00060 } else { 00061 return DBManager.addToDB(this); 00062 } 00063 } 00064 00065 00070 public RunSeries getRunSeries(DataPlot plot) throws JetWebException { 00071 Enumeration<RunSeries> en = runSeriesList.elements(); 00072 while (en.hasMoreElements()){ 00073 RunSeries rs = en.nextElement(); 00074 if (plot.isPredictedBy(rs)) {return rs;} 00075 } 00076 JetWebException j = 00077 new JetWebException("RunSeriesCollection: No prediction for this plot", 00078 "ID:"+plot.getId()); 00079 throw j; 00080 } 00081 00085 public Vector<RunSeries> getRunSeriesList(){ 00086 return runSeriesList; 00087 } 00088 00093 public Vector<RunSeries> getRunSeriesList(MCProcessType proc){ 00094 Vector<RunSeries> list = new Vector<RunSeries>(); 00095 Enumeration<RunSeries> en = runSeriesList.elements(); 00096 while (en.hasMoreElements()){ 00097 RunSeries rs = en.nextElement(); 00098 try{ 00099 if (rs.getMCProcessType().matches(proc)) { 00100 add(rs); 00101 } 00102 }catch (Throwable err){ 00103 System.out.println(err.getMessage()); 00104 } 00105 } 00106 return list; 00107 } 00108 00112 public int getId(){ 00113 return id; 00114 } 00118 public void setId(int id){ 00119 this.id=id; 00120 } 00121 00126 public boolean contains(DataPlot plot){ 00127 00128 Enumeration<RunSeries> list = runSeriesList.elements(); 00129 while (list.hasMoreElements()){ 00130 RunSeries rs = (RunSeries)list.nextElement(); 00131 if (plot.isPredictedBy(rs)){ 00132 return true; 00133 } 00134 } 00135 return false; 00136 } 00137 00147 public boolean add(RunSeries runSeries) throws JetWebException { 00148 00149 System.out.println("CCC Called RunSeriesCollection.add"); 00150 00151 boolean found = false; 00152 00153 int ptid = runSeries.getMCProcessType().getId(); 00154 00155 System.out.println("ptid = "+ptid); 00156 00157 CutCollection cuts = runSeries.getCutCollection(); 00158 00159 Enumeration<RunSeries> list = runSeriesList.elements(); 00160 while (list.hasMoreElements() && !found){ 00161 RunSeries rs = list.nextElement(); 00162 System.out.println("existing proc id = " +rs.getMCProcessType().getId()); 00163 00164 //Do check on cuts both being empty here!! 00165 00166 if (rs.getMCProcessType().getId()==ptid && 00167 (cuts.equals(rs.getCutCollection())||cuts.getId()==rs.getCutCollection().getId())){ 00168 found=true; 00169 } 00170 } 00171 00172 if (!found){ 00173 runSeriesList.add(runSeries); 00174 //need to update runseriescollection in db 00175 //this seems a sensible place to do it 00176 if(id>0){ 00177 DBManager.updateDB(this, runSeries); 00178 } 00179 } else { 00180 System.out.println("RunSeries not added: already one matching this MCProcessType"); 00181 } 00182 return !found; 00183 } 00184 00189 public Date getDate(){ 00190 00191 Date d = new Date(0); 00192 00193 Enumeration<RunSeries> list = runSeriesList.elements(); 00194 while (list.hasMoreElements()){ 00195 RunSeries rs = list.nextElement(); 00196 if (rs.getDate().after(d)) { d=rs.getDate(); } 00197 } 00198 return d; 00199 } 00200 }
Generated Wed Jan 17 09:14:27 GMT 2007