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

COVERAGE SUMMARY FOR SOURCE FILE [IndexedExtractor.java]

nameclass, %method, %block, %line, %
IndexedExtractor.java100% (1/1)73%  (8/11)63%  (80/127)51%  (18/35)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class IndexedExtractor100% (1/1)73%  (8/11)63%  (80/127)51%  (18/35)
equals (Object): boolean 0%   (0/1)0%   (0/28)0%   (0/10)
hashCode (): int 0%   (0/1)0%   (0/13)0%   (0/4)
isContextDependent (): boolean 0%   (0/1)0%   (0/2)0%   (0/1)
map (int []): Extractor 100% (1/1)90%  (19/21)75%  (3/4)
compareTo (Extractor): ComparisonResult 100% (1/1)94%  (29/31)88%  (7/8)
IndexedExtractor (int): void 100% (1/1)100% (6/6)100% (3/3)
extract (Object, Map, Object []): Object 100% (1/1)100% (5/5)100% (1/1)
getCost (): double 100% (1/1)100% (2/2)100% (1/1)
getIndex (): int 100% (1/1)100% (3/3)100% (1/1)
parameterIndices (): Set 100% (1/1)100% (5/5)100% (1/1)
toString (): String 100% (1/1)100% (11/11)100% (1/1)

1package com.hammurapi.extract;
2 
3import java.util.Collections;
4import java.util.Map;
5import java.util.Set;
6 
7import com.hammurapi.extract.ComparisonResult.Type;
8 
9/**
10 * Extracts value at index.
11 * @author Pavel Vlasov.
12 *
13 * @param <T>
14 */
15public class IndexedExtractor<T, C> implements Extractor<T, T, C>, Mappable<T,T,C> {
16        
17        private int idx;
18 
19        public IndexedExtractor(int idx) {
20                this.idx = idx;
21        }
22 
23        public Set<Integer> parameterIndices() {
24                return Collections.singleton(idx);
25        }
26 
27        @Override
28        public int hashCode() {
29                final int prime = 31;
30                int result = 1;
31                result = prime * result + idx;
32                return result;
33        }
34 
35        @SuppressWarnings("unchecked")
36        @Override
37        public boolean equals(Object obj) {
38                if (this == obj)
39                        return true;
40                if (obj == null)
41                        return false;
42                if (getClass() != obj.getClass())
43                        return false;
44                IndexedExtractor other = (IndexedExtractor) obj;
45                if (idx != other.idx)
46                        return false;
47                return true;
48        }
49 
50 
51        public T extract(C context, Map<C, Map<Extractor<T, ? super T, C>, ? super T>> cache, T... obj) {
52                return obj[idx];
53        }
54 
55        public boolean isContextDependent() {
56                return false;
57        }
58 
59        @Override
60        public String toString() {
61                return "IndexedExtractor [idx=" + idx + "]";
62        }
63 
64        @Override
65        public ComparisonResult compareTo(Extractor<T, T, C> other) {
66                if (other instanceof IndexedExtractor) {
67                        int otherIdx = ((IndexedExtractor<T, C>) other).idx;
68                        if (otherIdx==idx) {
69                                return ComparisonResult.EQUAL_NM;
70                        }
71                        int[] map = new int[otherIdx+1];
72                        map[otherIdx]= idx;
73                        return new ComparisonResult(Type.EQUAL, map);
74                }
75                return ComparisonResult.NOT_EQUAL_NM;
76        }                        
77 
78        @Override
79        public double getCost() {
80                return 0;
81        }
82 
83        @Override
84        public Extractor<T, T, C> map(int[] map) {
85                for (int i=0; i<map.length; ++i) {
86                        if (map[i]==idx) {
87                                return new IndexedExtractor<T, C>(i);
88                        }
89                }
90                return null;
91        }
92        
93        public int getIndex() {
94                return idx;
95        }
96}

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