Add Honeynode emulator for device221
[transportpce.git] / tests / honeynode221 / minimal-distribution-core / src / main / java / io / fd / honeycomb / infra / distro / activation / ActiveModules.java
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package io.fd.honeycomb.infra.distro.activation;
18
19 import com.google.inject.Module;
20
21 import java.util.Set;
22 import java.util.stream.Collectors;
23
24 import static java.lang.String.format;
25
26 /**
27  * Provides static set of active activeModulesClasses
28  */
29 public class ActiveModules {
30     private final Set<Class<? extends Module>> activeModulesClasses;
31
32     public ActiveModules(final Set<Class<? extends Module>> activeModulesClasses) {
33         this.activeModulesClasses = activeModulesClasses;
34     }
35
36     public Set<Class<? extends Module>> getActiveModulesClasses() {
37         return activeModulesClasses;
38     }
39
40     public Set<? extends Module> createModuleInstances() {
41         return activeModulesClasses.stream()
42                 .map(moduleClass -> {
43                     try {
44                         return moduleClass.newInstance();
45                     } catch (InstantiationException | IllegalAccessException e) {
46                         throw new IllegalStateException(format("Unable to create instance of module %s", moduleClass),
47                                 e);
48                     }
49                 }).collect(Collectors.toSet());
50     }
51
52     @Override
53     public String toString() {
54         return "ActiveModules{" +
55                 "activeModulesClasses=" + activeModulesClasses +
56                 '}';
57     }
58 }