1 package jp.sourceforge.stigmata.result;
3 import java.text.SimpleDateFormat;
4 import java.util.Calendar;
5 import java.util.Iterator;
7 import jp.sourceforge.stigmata.BirthmarkContext;
8 import jp.sourceforge.stigmata.BirthmarkEnvironment;
9 import jp.sourceforge.stigmata.BirthmarkSet;
10 import jp.sourceforge.stigmata.BirthmarkStoreException;
11 import jp.sourceforge.stigmata.ExtractionResultSet;
12 import jp.sourceforge.stigmata.ExtractionTarget;
13 import jp.sourceforge.stigmata.ExtractionUnit;
16 * Abstract class for ExtractionResultSet.
18 * @author Haruaki Tamada
20 public abstract class AbstractExtractionResultSet implements ExtractionResultSet{
21 private BirthmarkContext context;
22 private boolean tableType = true;
28 public AbstractExtractionResultSet(BirthmarkContext context){
35 public AbstractExtractionResultSet(BirthmarkContext context, boolean tableType){
36 this.context = context;
40 void setId(String id){
45 public String getId(){
50 * returns a birthmark environment.
53 public BirthmarkEnvironment getEnvironment(){
54 return context.getEnvironment();
58 * returns a birthmark context.
61 public BirthmarkContext getContext(){
66 public abstract void addBirthmarkSet(ExtractionTarget target, BirthmarkSet set) throws BirthmarkStoreException;
69 public abstract void removeBirthmarkSet(ExtractionTarget target, BirthmarkSet set);
72 public abstract void removeAllBirthmarkSets(ExtractionTarget target);
75 public abstract int getBirthmarkSetSize(ExtractionTarget target);
78 public abstract Iterator<BirthmarkSet> birthmarkSets(ExtractionTarget target);
81 * returns the sum of birthmark set size this instance has.
82 * <code>getBirthmarkSetSize(ExtractionTarget.TARGET_BOTH)</code>
85 public int getBirthmarkSetSize(){
86 return getBirthmarkSetSize(ExtractionTarget.TARGET_BOTH);
90 * returns an iterator.
91 * <code>birthmarkSets(ExtractionTarget.TARGET_BOTH)</code>
94 public Iterator<BirthmarkSet> iterator(){
95 return birthmarkSets(ExtractionTarget.TARGET_BOTH);
99 * returns a birthmark set related of given index.
100 * <code>getBirthmarkSet(ExtractionTarget.TARGET_BOTH, index)</code>
103 public BirthmarkSet getBirthmarkSet(int index){
104 return getBirthmarkSet(ExtractionTarget.TARGET_BOTH, index);
108 * returns a birthmark set related with given name.
109 * <code>getBirthmarkSet(ExtractionTarget.TARGET_BOTH, name)</code>
112 public BirthmarkSet getBirthmarkSet(String name){
113 return getBirthmarkSet(ExtractionTarget.TARGET_BOTH, name);
117 * returns all of birthmark sets.
118 * <code>getBirthmarkSets(ExtractionTarget.TARGET_BOTH)</code>
121 public BirthmarkSet[] getBirthmarkSets(){
122 return getBirthmarkSets(ExtractionTarget.TARGET_BOTH);
126 * remove specified birthmark set from this instance.
127 * <code>removeBirthmarkSet(ExtractionTarget.TARGET_BOTH, bs)</code>
130 public void removeBirthmarkSet(BirthmarkSet bs){
131 removeBirthmarkSet(ExtractionTarget.TARGET_BOTH, bs);
135 * remove all of birthmark sets.
136 * <code>removeBirthmarkSet(ExtractionTarget.TARGET_BOTH)</code>
139 public void removeAllBirthmarkSets(){
140 removeAllBirthmarkSets(ExtractionTarget.TARGET_BOTH);
144 * returns an array of extracted birthmark types.
147 public String[] getBirthmarkTypes(){
148 return context.getBirthmarkTypes();
152 * returns an unit of extraction from.
155 public ExtractionUnit getExtractionUnit(){
156 return context.getExtractionUnit();
160 * returns the birthmark set at the specified position in the specified target.
163 public BirthmarkSet getBirthmarkSet(ExtractionTarget target, int index){
164 int currentIndex = 0;
165 for(Iterator<BirthmarkSet> i = birthmarkSets(target); i.hasNext(); ){
166 if(currentIndex == index){
176 * returns the birthmark set related with the specified name in the specified target.
179 public BirthmarkSet getBirthmarkSet(ExtractionTarget target, String setname){
180 for(Iterator<BirthmarkSet> i = birthmarkSets(target); i.hasNext(); ){
181 BirthmarkSet bs = i.next();
182 if(bs.getName().equals(setname)){
190 * @return all of BirthmarkSet this instance have. elements is obtained from birthmarkSet.
193 public synchronized BirthmarkSet[] getBirthmarkSets(ExtractionTarget target){
194 return AbstractComparisonResultSet.<BirthmarkSet>getArrays(birthmarkSets(target), new BirthmarkSet[0]);
198 public void setBirthmarkSets(ExtractionTarget target, BirthmarkSet[] sets) throws BirthmarkStoreException{
199 removeAllBirthmarkSets(target);
200 for(int i = 0; i < sets.length; i++){
201 addBirthmarkSet(target, sets[i]);
206 public boolean isTableType(){
211 public void setTableType(boolean flag){
212 this.tableType = flag;
215 protected static String generateId(){
216 SimpleDateFormat cdf = new SimpleDateFormat("yyyyMMdd-HHmmss.SSS");
217 return cdf.format(Calendar.getInstance().getTime());