1 package jp.sourceforge.stigmata.result;
7 import java.text.SimpleDateFormat;
8 import java.util.Calendar;
9 import java.util.Iterator;
11 import jp.sourceforge.stigmata.BirthmarkContext;
12 import jp.sourceforge.stigmata.BirthmarkEnvironment;
13 import jp.sourceforge.stigmata.BirthmarkSet;
14 import jp.sourceforge.stigmata.BirthmarkStoreException;
15 import jp.sourceforge.stigmata.ExtractionResultSet;
16 import jp.sourceforge.stigmata.ExtractionTarget;
17 import jp.sourceforge.stigmata.ExtractionUnit;
20 * Abstract class for ExtractionResultSet.
22 * @author Haruaki Tamada
25 public abstract class AbstractExtractionResultSet implements ExtractionResultSet{
26 private BirthmarkContext context;
27 private boolean tableType = true;
33 public AbstractExtractionResultSet(BirthmarkContext context){
40 public AbstractExtractionResultSet(BirthmarkContext context, boolean tableType){
41 this.context = context;
45 void setId(String id){
50 public String getId(){
55 * returns a birthmark environment.
58 public BirthmarkEnvironment getEnvironment(){
59 return context.getEnvironment();
63 * returns a birthmark context.
66 public BirthmarkContext getContext(){
71 public abstract void addBirthmarkSet(ExtractionTarget target, BirthmarkSet set) throws BirthmarkStoreException;
74 public abstract void removeBirthmarkSet(ExtractionTarget target, BirthmarkSet set);
77 public abstract void removeAllBirthmarkSets(ExtractionTarget target);
80 public abstract int getBirthmarkSetSize(ExtractionTarget target);
83 public abstract Iterator<BirthmarkSet> birthmarkSets(ExtractionTarget target);
86 * returns the sum of birthmark set size this instance has.
87 * <code>getBirthmarkSetSize(ExtractionTarget.TARGET_BOTH)</code>
90 public int getBirthmarkSetSize(){
91 return getBirthmarkSetSize(ExtractionTarget.TARGET_BOTH);
95 * returns an iterator.
96 * <code>birthmarkSets(ExtractionTarget.TARGET_BOTH)</code>
99 public Iterator<BirthmarkSet> iterator(){
100 return birthmarkSets(ExtractionTarget.TARGET_BOTH);
104 * returns a birthmark set related of given index.
105 * <code>getBirthmarkSet(ExtractionTarget.TARGET_BOTH, index)</code>
108 public BirthmarkSet getBirthmarkSet(int index){
109 return getBirthmarkSet(ExtractionTarget.TARGET_BOTH, index);
113 * returns a birthmark set related with given name.
114 * <code>getBirthmarkSet(ExtractionTarget.TARGET_BOTH, name)</code>
117 public BirthmarkSet getBirthmarkSet(String name){
118 return getBirthmarkSet(ExtractionTarget.TARGET_BOTH, name);
122 * returns all of birthmark sets.
123 * <code>getBirthmarkSets(ExtractionTarget.TARGET_BOTH)</code>
126 public BirthmarkSet[] getBirthmarkSets(){
127 return getBirthmarkSets(ExtractionTarget.TARGET_BOTH);
131 * remove specified birthmark set from this instance.
132 * <code>removeBirthmarkSet(ExtractionTarget.TARGET_BOTH, bs)</code>
135 public void removeBirthmarkSet(BirthmarkSet bs){
136 removeBirthmarkSet(ExtractionTarget.TARGET_BOTH, bs);
140 * remove all of birthmark sets.
141 * <code>removeBirthmarkSet(ExtractionTarget.TARGET_BOTH)</code>
144 public void removeAllBirthmarkSets(){
145 removeAllBirthmarkSets(ExtractionTarget.TARGET_BOTH);
149 * returns an array of extracted birthmark types.
152 public String[] getBirthmarkTypes(){
153 return context.getBirthmarkTypes();
157 * returns an unit of extraction from.
160 public ExtractionUnit getExtractionUnit(){
161 return context.getExtractionUnit();
165 * returns the birthmark set at the specified position in the specified target.
168 public BirthmarkSet getBirthmarkSet(ExtractionTarget target, int index){
169 int currentIndex = 0;
170 for(Iterator<BirthmarkSet> i = birthmarkSets(target); i.hasNext(); ){
171 if(currentIndex == index){
181 * returns the birthmark set related with the specified name in the specified target.
184 public BirthmarkSet getBirthmarkSet(ExtractionTarget target, String setname){
185 for(Iterator<BirthmarkSet> i = birthmarkSets(target); i.hasNext(); ){
186 BirthmarkSet bs = i.next();
187 if(bs.getName().equals(setname)){
195 * @return all of BirthmarkSet this instance have. elements is obtained from birthmarkSet.
198 public synchronized BirthmarkSet[] getBirthmarkSets(ExtractionTarget target){
199 return AbstractComparisonResultSet.<BirthmarkSet>getArrays(birthmarkSets(target), new BirthmarkSet[0]);
203 public void setBirthmarkSets(ExtractionTarget target, BirthmarkSet[] sets) throws BirthmarkStoreException{
204 removeAllBirthmarkSets(target);
205 for(int i = 0; i < sets.length; i++){
206 addBirthmarkSet(target, sets[i]);
211 public boolean isTableType(){
216 public void setTableType(boolean flag){
217 this.tableType = flag;
220 protected static String generateId(){
221 SimpleDateFormat cdf = new SimpleDateFormat("yyyyMMdd-HHmmss.SSS");
222 return cdf.format(Calendar.getInstance().getTime());