EMMA Coverage Report (generated Thu Jan 20 11:39:44 EST 2011)
[all classes][com.hammurapi.extract.java]

COVERAGE SUMMARY FOR SOURCE FILE [JavaExtractor.java]

nameclass, %method, %block, %line, %
JavaExtractor.java100% (3/3)100% (20/20)81%  (324/398)80%  (58.7/73)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class JavaExtractor$1100% (1/1)100% (2/2)57%  (26/46)60%  (3/5)
initialValue (): ExpressionEvaluator 100% (1/1)50%  (20/40)33%  (1/3)
JavaExtractor$1 (JavaExtractor): void 100% (1/1)100% (6/6)100% (2/2)
     
class JavaExtractor100% (1/1)100% (13/13)82%  (242/296)80%  (48.7/61)
extractInternal (Object, Map, Object []): Object 100% (1/1)41%  (13/32)50%  (2/4)
map (int []): Extractor 100% (1/1)68%  (28/41)75%  (6/8)
compareTo (Extractor): ComparisonResult 100% (1/1)75%  (53/71)65%  (15/23)
hashCode (): int 100% (1/1)91%  (41/45)97%  (7.7/8)
JavaExtractor (double, TimeUnit, Params, Class, ClassLoader): void 100% (1/1)100% (20/20)100% (6/6)
access$1 (JavaExtractor): Params 100% (1/1)100% (3/3)100% (1/1)
access$2 (JavaExtractor): Class 100% (1/1)100% (3/3)100% (1/1)
getExpression (): String 100% (1/1)100% (5/5)100% (1/1)
getIdentity (): List 100% (1/1)100% (4/4)100% (1/1)
getParameters (): Iterable 100% (1/1)100% (37/37)100% (5/5)
isContextDependent (): boolean 100% (1/1)100% (4/4)100% (1/1)
parameterIndices (): Set 100% (1/1)100% (4/4)100% (1/1)
toString (): String 100% (1/1)100% (27/27)100% (1/1)
     
class JavaExtractor$1ParameterImpl100% (1/1)100% (5/5)100% (56/56)100% (8/8)
JavaExtractor$1ParameterImpl (JavaExtractor, int, Integer []): void 100% (1/1)100% (12/12)100% (3/3)
getIndex (): int 100% (1/1)100% (7/7)100% (1/1)
getName (): String 100% (1/1)100% (8/8)100% (1/1)
getType (): Class 100% (1/1)100% (8/8)100% (1/1)
toString (): String 100% (1/1)100% (21/21)100% (2/2)

1package com.hammurapi.extract.java;
2 
3import java.util.ArrayList;
4import java.util.Collection;
5import java.util.Collections;
6import java.util.List;
7import java.util.Map;
8import java.util.Set;
9import java.util.concurrent.TimeUnit;
10 
11import org.codehaus.commons.compiler.CompileException;
12import org.codehaus.janino.ExpressionEvaluator;
13 
14import com.hammurapi.common.Identifiable;
15import com.hammurapi.extract.ComparisonResult;
16import com.hammurapi.extract.Extractor;
17import com.hammurapi.extract.ExtractorBase;
18import com.hammurapi.extract.ExtractorException;
19import com.hammurapi.extract.Mappable;
20 
21public class JavaExtractor<T, V, C> extends ExtractorBase<T, V, C> implements Extractor<T, V, C> , Mappable<T,V,C>, Identifiable<List<Object>>  {
22 
23        private Params<T, C> params;
24        private Class<V> valueType;
25        private ClassLoader classLoader;
26 
27        public JavaExtractor(double initialCost, TimeUnit costUnit, Params<T, C> params, Class<V> valueType, ClassLoader classLoader) {
28                super(initialCost, costUnit);
29                this.params = params;
30                this.valueType = valueType;
31                this.classLoader = classLoader;
32        }
33        
34        private ThreadLocal<ExpressionEvaluator> eetl = new ThreadLocal<ExpressionEvaluator>() {
35                
36                protected ExpressionEvaluator initialValue() {                        
37                        try {
38                                // TODO - Pass classLoader?
39                                return new ExpressionEvaluator(params.expr.toString(), valueType, params.names, params.types);
40                        } catch (CompileException e) {
41                                throw new ExtractorException("Compile exception in code '"+params.expr+"': "+e, e);
42                        }
43                };
44        };
45 
46        @SuppressWarnings("unchecked")
47        @Override
48        protected V extractInternal(C context, Map<C, Map<Extractor<T, ? super V, C>, ? super V>> cache, T... obj) {
49                Object[] args = params.translate(obj, context);
50                try {
51                        return (V) eetl.get().evaluate(args);
52                } catch (Exception e) {
53                        throw new ExtractorException("Invocation exception in code '"+params.expr+"': "+e, e);
54                }
55        }
56 
57        @Override
58        public boolean isContextDependent() {
59                return params.isContextDependent();
60        }
61 
62        @Override
63        public Set<Integer> parameterIndices() {
64                return params.indices;
65        }
66        
67        @Override
68        public String toString() {
69                return getClass().getName()+"(code: '"+params.expr+"', parameter indices "+parameterIndices()+", cost: "+getCost()+")";
70        }
71 
72        @Override
73        public int hashCode() {
74                final int prime = 31;
75                int result = 1;
76                result = prime * result
77                                + ((classLoader == null) ? 0 : classLoader.hashCode());
78                result = prime * result + ((params == null) ? 0 : params.hashCode());
79                result = prime * result
80                                + ((valueType == null) ? 0 : valueType.hashCode());
81                return result;
82        }
83        
84        @Override
85        public ComparisonResult compareTo(Extractor<T, V, C> obj) {
86                if (this == obj) {
87                        return ComparisonResult.EQUAL_NM;
88                }
89                if (obj == null) {
90                        return ComparisonResult.NOT_EQUAL_NM;
91                }
92                        
93                if (getClass() != obj.getClass()) {
94                        return super.compareTo(obj); // For parenthesis, facades and other stuff.
95                }
96 
97                JavaExtractor other = (JavaExtractor) obj;
98                if (classLoader == null) {
99                        if (other.classLoader != null) {
100                                return ComparisonResult.NOT_EQUAL_NM;
101                        }
102                } else if (!classLoader.equals(other.classLoader)) {
103                        return ComparisonResult.NOT_EQUAL_NM;
104                }
105 
106                if (params == null) {
107                        if (other.params != null) {
108                                return ComparisonResult.NOT_EQUAL_NM;
109                        }
110                } else if (!params.equals(other.params)) {
111                        return ComparisonResult.NOT_EQUAL_NM;
112                }
113                if (valueType == null) {
114                        if (other.valueType != null){
115                                return ComparisonResult.NOT_EQUAL_NM;
116                        }
117                } else if (!valueType.equals(other.valueType)) {
118                        return ComparisonResult.NOT_EQUAL_NM;
119                }
120                return ComparisonResult.EQUAL_NM; 
121        }
122 
123        @SuppressWarnings("unchecked")
124        @Override
125        public Extractor<T, V, C> map(int[] map) {
126                if (ComparisonResult.isOneToOneMapping(map)) {
127                        return this;
128                }
129                
130                Params<T,C> newParams = params.map(map);
131                if (newParams==null) {
132                        return null;
133                }
134                
135                if (this instanceof JavaPredicate) {
136                        return (Extractor<T, V, C>) new JavaPredicate<T, C>(initialCost, costUnit, newParams, classLoader);                        
137                }
138                
139                return new JavaExtractor<T, V, C>(initialCost, costUnit, newParams, valueType, classLoader);
140        }
141        
142        public List<Object> getIdentity() {
143                return params.getIdentity();
144        }
145        
146        public interface Parameter {
147                int getIndex();
148                Class<?> getType();
149                String getName();
150        }
151 
152        public Iterable<Parameter> getParameters() {
153                Collection<Parameter> ret = new ArrayList<Parameter>();
154                final Integer[] ia = params.indices.toArray(new Integer[params.indices.size()]);
155                for (int i=0; i<params.names.length; ++i) {
156                        class ParameterImpl implements Parameter {
157                                
158                                private int idx;
159 
160                                public ParameterImpl(int idx) {
161                                        this.idx = idx;
162                                }
163 
164                                @Override
165                                public int getIndex() {
166                                        return ia[idx];
167                                }
168 
169                                @Override
170                                public Class<?> getType() {
171                                        return params.types[idx];
172                                }
173 
174                                @Override
175                                public String getName() {
176                                        return params.names[idx];
177                                }
178 
179                                @Override
180                                public String toString() {
181                                        return "Parameter[idx=" + idx + ", type="
182                                                        + getType() + ", name=" + getName() + "]";
183                                }                
184                                
185                                
186                        }
187                        
188                        ret.add(new ParameterImpl(i));
189                        
190                }
191                
192                return Collections.unmodifiableCollection(ret);
193        }
194 
195        public String getExpression() {
196                return params.expr.toString();
197        }
198}

[all classes][com.hammurapi.extract.java]
EMMA 2.0.5312 EclEmma Fix 2 (C) Vladimir Roubtsov