1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.puppycrawl.tools.checkstyle.bdd;
21
22 import java.util.Collections;
23 import java.util.HashMap;
24 import java.util.Map;
25
26 import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
27
28 public final class ModuleInputConfiguration {
29
30
31 private final String moduleName;
32
33
34 private final Map<String, String> defaultProperties;
35
36
37 private final Map<String, String> nonDefaultProperties;
38
39
40 private final Map<String, String> moduleMessages;
41
42 private ModuleInputConfiguration(String moduleName,
43 Map<String, String> defaultProperties,
44 Map<String, String> nonDefaultProperties,
45 Map<String, String> moduleMessages) {
46 this.moduleName = moduleName;
47 this.defaultProperties = defaultProperties;
48 this.nonDefaultProperties = nonDefaultProperties;
49 this.moduleMessages = moduleMessages;
50 }
51
52 public String getModuleName() {
53 return moduleName;
54 }
55
56 public Map<String, String> getAllProperties() {
57 final Map<String, String> properties = new HashMap<>();
58 properties.putAll(defaultProperties);
59 properties.putAll(nonDefaultProperties);
60 return Collections.unmodifiableMap(properties);
61 }
62
63 public Map<String, String> getDefaultProperties() {
64 return Collections.unmodifiableMap(defaultProperties);
65 }
66
67 public Map<String, String> getNonDefaultProperties() {
68 return Collections.unmodifiableMap(nonDefaultProperties);
69 }
70
71 public Map<String, String> getModuleMessages() {
72 return Collections.unmodifiableMap(moduleMessages);
73 }
74
75 public DefaultConfiguration createConfiguration() {
76 final DefaultConfiguration parsedConfig = new DefaultConfiguration(moduleName);
77 nonDefaultProperties.forEach(parsedConfig::addProperty);
78 moduleMessages.forEach(parsedConfig::addMessage);
79 return parsedConfig;
80 }
81
82 public String getDefaultPropertyValue(String key) {
83 return defaultProperties.get(key);
84 }
85
86 public static final class Builder {
87
88 private final Map<String, String> defaultProperties = new HashMap<>();
89
90 private final Map<String, String> nonDefaultProperties = new HashMap<>();
91
92 private final Map<String, String> moduleMessages = new HashMap<>();
93
94 private String moduleName;
95
96 public void setModuleName(String moduleName) {
97 this.moduleName = moduleName;
98 }
99
100 public void addDefaultProperty(String propertyName, String defaultPropertyValue) {
101 defaultProperties.put(propertyName, defaultPropertyValue);
102 }
103
104 public void addNonDefaultProperty(String propertyName, String nonDefaultPropertyValue) {
105 nonDefaultProperties.put(propertyName, nonDefaultPropertyValue);
106 }
107
108 public void addModuleMessage(String messageKey, String messageString) {
109 moduleMessages.put(messageKey, messageString);
110 }
111
112 public ModuleInputConfiguration build() {
113 return new ModuleInputConfiguration(
114 moduleName,
115 defaultProperties,
116 nonDefaultProperties,
117 moduleMessages
118 );
119 }
120 }
121 }