| 1 | package com.hammurapi.extract; |
| 2 | |
| 3 | import java.util.concurrent.TimeUnit; |
| 4 | |
| 5 | /** |
| 6 | * Base class for composite extractors like +, *, / operations. |
| 7 | * @author Pavel Vlasov. |
| 8 | * |
| 9 | * @param <T> |
| 10 | * @param <V> |
| 11 | */ |
| 12 | public abstract class CompositeExtractorBase<T, V, C> extends ExtractorBase<T, V, C> { |
| 13 | |
| 14 | protected Extractor<T, V, C>[] operands; |
| 15 | |
| 16 | public CompositeExtractorBase(double initialCost, TimeUnit costUnit, Extractor<T, V, C>... operands) { |
| 17 | super(initialCost, costUnit); |
| 18 | this.operands = operands; |
| 19 | } |
| 20 | |
| 21 | @Override |
| 22 | public double getCost() { |
| 23 | if (cost==-1 && costUnit==null) { |
| 24 | double ret = 0; |
| 25 | for (Extractor<T,V,C> e : operands) { |
| 26 | ret+=e.getCost(); |
| 27 | } |
| 28 | return ret; |
| 29 | } |
| 30 | return super.getCost(); |
| 31 | } |
| 32 | |
| 33 | } |