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

COVERAGE SUMMARY FOR SOURCE FILE [SimpleMutableContext.java]

nameclass, %method, %block, %line, %
SimpleMutableContext.java0%   (0/1)0%   (0/9)0%   (0/138)0%   (0/38)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SimpleMutableContext0%   (0/1)0%   (0/9)0%   (0/138)0%   (0/38)
SimpleMutableContext (): void 0%   (0/1)0%   (0/13)0%   (0/4)
SimpleMutableContext (Map, Map): void 0%   (0/1)0%   (0/25)0%   (0/8)
bind (String, Object): void 0%   (0/1)0%   (0/7)0%   (0/2)
lookup (Class): Object 0%   (0/1)0%   (0/19)0%   (0/6)
lookup (String): Object 0%   (0/1)0%   (0/5)0%   (0/1)
lookupAll (Class): Iterator 0%   (0/1)0%   (0/20)0%   (0/6)
register (Class, Object): void 0%   (0/1)0%   (0/23)0%   (0/6)
unbind (String): Object 0%   (0/1)0%   (0/5)0%   (0/1)
unregister (Class, Object): void 0%   (0/1)0%   (0/21)0%   (0/6)

1package com.hammurapi.common;
2 
3import java.util.ArrayList;
4import java.util.Collection;
5import java.util.Collections;
6import java.util.HashMap;
7import java.util.Iterator;
8import java.util.Map;
9 
10/**
11 * Simple context implementation.
12 * @author Pavel Vlasov
13 *
14 */
15public class SimpleMutableContext implements MutableContext {
16        
17        private Map<String, Object> bindings = new HashMap<String, Object>();
18        private Map<Class<?>, Collection<?>> services = new HashMap<Class<?>, Collection<?>>();
19 
20        public SimpleMutableContext() {
21                
22        }
23        
24        /**
25         * @param classLoader ClassLoader for services. Can be null.
26         * @param bindings Name bindings. Can be null.
27         */
28        public SimpleMutableContext(Map<Class<?>, Collection<?>> services, Map<String, ?> bindings) {
29                if (services!=null) {
30                        this.services.putAll(services);
31                }
32                
33                if (bindings!=null) {
34                        this.bindings.putAll(bindings);
35                }
36        }
37        
38        public synchronized void bind(String name, Object value) {
39                bindings.put(name, value);
40        }
41 
42        public synchronized Object unbind(String name) {
43                return bindings.remove(name);
44        }
45 
46        @SuppressWarnings("unchecked")
47        public synchronized <T> void register(Class<? super T> serviceType, T service) {
48                Collection<Object> sl = (Collection<Object>) services.get(serviceType);
49                if (sl==null) {
50                        sl = new ArrayList<Object>();
51                        services.put(serviceType, sl);
52                }
53                sl.add(service);
54        }
55 
56        public synchronized <T> void unregister(Class<? super T> serviceType, T service) {
57                Collection<?> sl = services.get(serviceType);
58                if (sl!=null) {
59                        sl.remove(service);
60                        if (sl.isEmpty()) {
61                                services.remove(serviceType);
62                        }
63                }
64        }
65        
66        public Object lookup(String name) {
67                return bindings.get(name);
68        }
69 
70        @SuppressWarnings("unchecked")
71        public <T> T lookup(Class<T> serviceClass) {
72                Collection<?> sl = services.get(serviceClass);
73                if (sl==null) {
74                        return null;
75                }
76                
77                if (sl.isEmpty()) {
78                        return null;
79                }
80                
81                return (T) sl.iterator().next();
82        }
83 
84        @SuppressWarnings("unchecked")
85        public <T> Iterator<T> lookupAll(Class<T> serviceClass) {
86                Collection<?> sl = services.get(serviceClass);
87                if (sl==null) {
88                        return (Iterator<T>) Collections.emptyList().iterator();
89                }
90                
91                if (sl.isEmpty()) {
92                        return (Iterator<T>) Collections.emptyList().iterator();
93                }
94                
95                return (Iterator<T>) sl.iterator();
96        }
97 
98}

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