Clover icon

sunshower-base

  1. Project Clover database Fri Apr 6 2018 03:41:27 UTC
  2. Package io.sunshower.reflect.incant

File TrieServiceRegistry.java

 

Coverage histogram

../../../../img/srcFileCovDistChart9.png
16% of files have more coverage

Code metrics

0
12
6
1
50
41
6
0.5
2
6
1

Classes

Class Line # Actions
TrieServiceRegistry 7 12 6
0.888888988.9%
 

Contributing tests

This file is covered by 2 tests. .

Source view

1    package io.sunshower.reflect.incant;
2   
3    import java.util.HashMap;
4    import java.util.Map;
5    import java.util.Set;
6   
 
7    public class TrieServiceRegistry implements InvocationContext {
8   
9    private final OperationScanner scanner;
10    private final ServiceResolver serviceResolver;
11    private final Map<String, ServiceDescriptor<?>> serviceDescriptors;
12   
 
13  2 toggle public TrieServiceRegistry(
14    final OperationScanner scanner, final ServiceResolver serviceResolver) {
15  2 this.scanner = scanner;
16  2 this.serviceResolver = serviceResolver;
17  2 this.serviceDescriptors = new HashMap<>();
18    }
19   
 
20  2 toggle @Override
21    @SuppressWarnings("unchecked")
22    public <T> ServiceDescriptor<T> resolve(String name) {
23  2 return (ServiceDescriptor<T>) this.serviceDescriptors.get(name);
24    }
25   
 
26  0 toggle @Override
27    @SuppressWarnings("unchecked")
28    public <T> ServiceDescriptor<T> resolve(Class<T> type, String name) {
29  0 return (ServiceDescriptor<T>) this.serviceDescriptors.get(name);
30    }
31   
 
32  2 toggle private void scan() {
33  2 final Set<Class<?>> serviceTypes = serviceResolver.resolveServiceTypes();
34  2 for (Class<?> serviceType : serviceTypes) {
35  2 register(serviceType);
36    }
37    }
38   
 
39  2 toggle private void register(Class<?> serviceType) {
40  2 final Set<ServiceDescriptor<?>> registeredServices = scanner.scan(serviceType);
41  2 for (ServiceDescriptor<?> descriptor : registeredServices) {
42  2 this.serviceDescriptors.put(descriptor.getIdentifier(), descriptor);
43    }
44    }
45   
 
46  2 toggle @Override
47    public void refresh() {
48  2 scan();
49    }
50    }