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

COVERAGE SUMMARY FOR SOURCE FILE [FamilyTiesEventStoreImpl.java]

nameclass, %method, %block, %line, %
FamilyTiesEventStoreImpl.java83%  (5/6)53%  (10/19)70%  (142/204)70%  (32/46)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class FamilyTiesEventStoreImpl$FamilyTiesEventLiveView0%   (0/1)0%   (0/3)0%   (0/16)0%   (0/4)
FamilyTiesEventStoreImpl$FamilyTiesEventLiveView (FamilyTiesEventStore, Predi... 0%   (0/1)0%   (0/5)0%   (0/2)
createUnmodifiableFacade (): FamilyTiesEventStore 0%   (0/1)0%   (0/5)0%   (0/1)
getRelatives (Person): Iterable 0%   (0/1)0%   (0/6)0%   (0/1)
     
class FamilyTiesEventStoreImpl$FamilyTiesEventDeputyStore100% (1/1)20%  (1/5)17%  (5/29)33%  (2/6)
createDeputy (): FamilyTiesEventStore 0%   (0/1)0%   (0/7)0%   (0/1)
createLiveView (Predicate): FamilyTiesEventStore 0%   (0/1)0%   (0/6)0%   (0/1)
createUnmodifiableFacade (): FamilyTiesEventStore 0%   (0/1)0%   (0/5)0%   (0/1)
getRelatives (Person): Iterable 0%   (0/1)0%   (0/6)0%   (0/1)
FamilyTiesEventStoreImpl$FamilyTiesEventDeputyStore (AbstractStore, ReadWrite... 100% (1/1)100% (5/5)100% (2/2)
     
class FamilyTiesEventStoreImpl$FamilyTiesEventUnmodifiableStore100% (1/1)50%  (1/2)40%  (4/10)67%  (2/3)
getRelatives (Person): Iterable 0%   (0/1)0%   (0/6)0%   (0/1)
FamilyTiesEventStoreImpl$FamilyTiesEventUnmodifiableStore (FamilyTiesEventSto... 100% (1/1)100% (4/4)100% (2/2)
     
class FamilyTiesEventStoreImpl100% (1/1)83%  (5/6)87%  (109/125)82%  (23/28)
createLiveView (Predicate): FamilyTiesEventStore 0%   (0/1)0%   (0/6)0%   (0/1)
supercedes (Relative, Relative): int 100% (1/1)74%  (25/34)62%  (5/8)
getRelatives (Person): Iterable 100% (1/1)98%  (50/51)92%  (12/13)
FamilyTiesEventStoreImpl (FamilyTiesEventStoreImpl$Config): void 100% (1/1)100% (22/22)100% (4/4)
createDeputy (): FamilyTiesEventStore 100% (1/1)100% (7/7)100% (1/1)
createUnmodifiableFacade (): FamilyTiesEventStore 100% (1/1)100% (5/5)100% (1/1)
     
class FamilyTiesEventStoreImpl$1100% (1/1)100% (2/2)100% (16/16)100% (3/3)
FamilyTiesEventStoreImpl$1 (FamilyTiesEventStoreImpl, double, TimeUnit, boole... 100% (1/1)100% (9/9)100% (2/2)
extractInternal (FamilyTiesEventStore, Map, AbstractEventBus$Handle []): Person 100% (1/1)100% (7/7)100% (1/1)
     
class FamilyTiesEventStoreImpl$Config100% (1/1)100% (1/1)100% (8/8)100% (3/3)
FamilyTiesEventStoreImpl$Config (): void 100% (1/1)100% (8/8)100% (3/3)

1package com.hammurapi.eventbus.tests.familyties;
2 
3import java.util.ArrayList;
4import java.util.Collection;
5import java.util.Iterator;
6import java.util.Map;
7import java.util.concurrent.locks.ReadWriteLock;
8 
9import com.hammurapi.eventbus.AbstractEventBus;
10import com.hammurapi.eventbus.HandleExtractor;
11import com.hammurapi.eventbus.tests.familyties.model.Person;
12import com.hammurapi.eventbus.tests.familyties.model.Relative;
13import com.hammurapi.eventbus.tests.familyties.rules.FamilyTiesRules;
14import com.hammurapi.extract.Extractor;
15import com.hammurapi.extract.Predicate;
16import com.hammurapi.store.AbstractStore;
17import com.hammurapi.store.DeputyStore;
18import com.hammurapi.store.Index;
19import com.hammurapi.store.LiveView;
20import com.hammurapi.store.MultiIndex;
21import com.hammurapi.store.UnmodifiableStore;
22import com.hammurapi.store.local.LocalStoreBase;
23 
24/**
25 * Implementation of event store.
26 * @author Pavel Vlasov
27 *
28 * @param <E>
29 * @param <P>
30 * @param <C>
31 */
32public class FamilyTiesEventStoreImpl extends LocalStoreBase<AbstractEventBus.Handle<com.hammurapi.eventbus.tests.familyties.model.Relative,java.lang.Integer,com.hammurapi.eventbus.tests.familyties.rules.FamilyTiesRules,Long>, com.hammurapi.eventbus.tests.familyties.model.Relative, FamilyTiesEventStore> implements FamilyTiesEventStore {
33 
34        /**
35         * Config class with bound generic parameters. 
36         * @author Pavel Vlasov
37         *
38         */
39        public static class Config extends LocalStoreBase.Config<AbstractEventBus.Handle<com.hammurapi.eventbus.tests.familyties.model.Relative,java.lang.Integer,com.hammurapi.eventbus.tests.familyties.rules.FamilyTiesRules,Long>, com.hammurapi.eventbus.tests.familyties.model.Relative, FamilyTiesEventStore> {
40                
41                public Config() {
42                        setPrimaryKeyExtractor(new HandleExtractor<com.hammurapi.eventbus.tests.familyties.model.Relative, java.lang.Integer, com.hammurapi.eventbus.tests.familyties.rules.FamilyTiesRules, Long, AbstractEventBus.Handle<com.hammurapi.eventbus.tests.familyties.model.Relative,java.lang.Integer,com.hammurapi.eventbus.tests.familyties.rules.FamilyTiesRules,Long>, FamilyTiesEventStore>());
43                }
44        }
45 
46        private MultiIndex<AbstractEventBus.Handle<Relative, Integer, FamilyTiesRules, Long>, Relative, Person, FamilyTiesEventStore> subjectIndex;
47 
48        public FamilyTiesEventStoreImpl(Config config) {
49                super(config);
50                
51                FamilyTiesEventStoreExtractor<Person> subjectExtractor = new FamilyTiesEventStoreAbstractExtractor<Person>(0, null, false) {
52 
53                        @Override
54                        protected Person extractInternal(
55                                        FamilyTiesEventStore context,
56                                        Map<FamilyTiesEventStore, Map<Extractor<com.hammurapi.eventbus.AbstractEventBus.Handle<Relative, Integer, FamilyTiesRules, Long>, ? super Person, FamilyTiesEventStore>, ? super Person>> cache,
57                                        com.hammurapi.eventbus.AbstractEventBus.Handle<Relative, Integer, FamilyTiesRules, Long>... obj) {
58                                
59                                return obj[0].getEvent().getSubject();
60                        }
61 
62                }; 
63                subjectIndex = (MultiIndex<com.hammurapi.eventbus.AbstractEventBus.Handle<Relative, Integer, FamilyTiesRules, Long>, Relative, Person, FamilyTiesEventStore>) addIndex(null, subjectExtractor, Index.Type.LAZY, false, null); 
64        }
65        
66        @Override
67        public Iterable<Relative> getRelatives(Person subject) {
68                Collection<Relative> ret = new ArrayList<Relative>();
69                Z: for (AbstractEventBus.Handle<Relative, Integer, FamilyTiesRules, Long> h: subjectIndex.find(subject)) {
70                        if (h.isValid()) {
71                                Relative newRelative = h.getEvent();
72                                Iterator<Relative> rit = ret.iterator();
73                                while (rit.hasNext()) {
74                                        Relative eRelative = rit.next();
75                                        switch (supercedes(eRelative, newRelative)) {
76                                        case 0:
77                                                // Unrelated - go further.
78                                                break;
79                                        case 1:
80                                                // No need to add this new relative, jump to next new relative
81                                                continue Z;
82                                        case -1:
83                                                // New relative supercedes this one.
84                                                rit.remove();
85                                                break;
86                                        }
87                                }
88                                ret.add(newRelative);
89                        }
90                }
91                return ret;
92        }
93        
94        /**
95         * 
96         * @param r0
97         * @param r1
98         * @return -1 - r1 is more specific (e.g. Daughter instead of Child) than r0, 0 - unrelated, 1 - r0 is more specific or equal. 
99         */
100        private int supercedes(Relative r0, Relative r1) {
101                if (r0.equals(r1)) {
102                        return 1;
103                }
104                if (r0.getSubject().equals(r1.getSubject()) && r0.getObject().equals(r1.getObject())) {
105                        if (r0.getClass().isInstance(r1)) { // r1 is more specific
106                                return -1;
107                        }
108                        
109                        if (r1.getClass().isInstance(r0)) { // r0 is more specific
110                                return 1;
111                        }
112                        
113                }
114                return 0;
115        }
116        
117        protected static class FamilyTiesEventDeputyStore extends DeputyStore<AbstractEventBus.Handle<com.hammurapi.eventbus.tests.familyties.model.Relative,java.lang.Integer,com.hammurapi.eventbus.tests.familyties.rules.FamilyTiesRules,Long>, com.hammurapi.eventbus.tests.familyties.model.Relative, FamilyTiesEventStore> implements FamilyTiesEventStore {
118 
119                public FamilyTiesEventDeputyStore(
120                                AbstractStore<AbstractEventBus.Handle<com.hammurapi.eventbus.tests.familyties.model.Relative, java.lang.Integer, com.hammurapi.eventbus.tests.familyties.rules.FamilyTiesRules, Long>, com.hammurapi.eventbus.tests.familyties.model.Relative, FamilyTiesEventStore> master,
121                                ReadWriteLock masterLock) {
122                        super(master, masterLock);
123                }
124 
125                @Override
126                protected FamilyTiesEventStore createDeputy() {
127                        return new FamilyTiesEventDeputyStore(this, createMasterLock());
128                }
129                
130                @Override
131                public FamilyTiesEventStore createUnmodifiableFacade() {
132                        return new FamilyTiesEventUnmodifiableStore(this);
133                }
134 
135                @Override
136                protected FamilyTiesEventStore createLiveView(Predicate<AbstractEventBus.Handle<com.hammurapi.eventbus.tests.familyties.model.Relative,java.lang.Integer,com.hammurapi.eventbus.tests.familyties.rules.FamilyTiesRules,Long>, FamilyTiesEventStore> selector) {
137                        return new FamilyTiesEventLiveView(this, selector);
138                }
139                
140                @Override
141                public Iterable<Relative> getRelatives(Person subject) {
142                        return ((FamilyTiesEventStore) master).getRelatives(subject);
143                }
144                
145        }
146        
147        protected static class FamilyTiesEventUnmodifiableStore extends UnmodifiableStore<AbstractEventBus.Handle<com.hammurapi.eventbus.tests.familyties.model.Relative,java.lang.Integer,com.hammurapi.eventbus.tests.familyties.rules.FamilyTiesRules,Long>, com.hammurapi.eventbus.tests.familyties.model.Relative, FamilyTiesEventStore> implements FamilyTiesEventStore {
148 
149                public FamilyTiesEventUnmodifiableStore(FamilyTiesEventStore master) {
150                        super(master);
151                }
152                
153                @Override
154                public Iterable<Relative> getRelatives(Person subject) {
155                        return ((FamilyTiesEventStore) master).getRelatives(subject);
156                }
157                
158        }
159        
160        protected static class FamilyTiesEventLiveView extends LiveView<AbstractEventBus.Handle<com.hammurapi.eventbus.tests.familyties.model.Relative,java.lang.Integer,com.hammurapi.eventbus.tests.familyties.rules.FamilyTiesRules,Long>, com.hammurapi.eventbus.tests.familyties.model.Relative, FamilyTiesEventStore> implements FamilyTiesEventStore {
161                
162                public FamilyTiesEventLiveView(
163                                FamilyTiesEventStore master,
164                                Predicate<AbstractEventBus.Handle<com.hammurapi.eventbus.tests.familyties.model.Relative, java.lang.Integer, com.hammurapi.eventbus.tests.familyties.rules.FamilyTiesRules, Long>, FamilyTiesEventStore> selector) {
165                        super(master, selector);
166                }
167 
168                @Override
169                public FamilyTiesEventStore createUnmodifiableFacade() {
170                        return new FamilyTiesEventUnmodifiableStore(this);
171                }
172                
173                @Override
174                public Iterable<Relative> getRelatives(Person subject) {
175                        return ((FamilyTiesEventStore) master).getRelatives(subject);
176                }
177                
178        }
179 
180        @Override
181        protected FamilyTiesEventStore createDeputy() {
182                return new FamilyTiesEventDeputyStore(this, createMasterLock());
183        }
184        
185        @Override
186        public FamilyTiesEventStore createUnmodifiableFacade() {
187                return new FamilyTiesEventUnmodifiableStore(this);
188        }
189 
190        @Override
191        protected FamilyTiesEventStore createLiveView(Predicate<AbstractEventBus.Handle<com.hammurapi.eventbus.tests.familyties.model.Relative,java.lang.Integer,com.hammurapi.eventbus.tests.familyties.rules.FamilyTiesRules,Long>, FamilyTiesEventStore> selector) {
192                return new FamilyTiesEventLiveView(this, selector);
193        }
194 
195}

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