1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package net.sourceforge.plantumldependency.common.utils.system;
26
27 import static java.lang.System.getProperties;
28 import static java.util.logging.Level.FINE;
29 import static java.util.logging.Level.INFO;
30 import static java.util.logging.Logger.getLogger;
31 import static net.sourceforge.plantumldependency.common.constants.CharacterConstants.COLON_CHAR;
32 import static net.sourceforge.plantumldependency.common.constants.CharacterConstants.SPACE_CHAR;
33 import static net.sourceforge.plantumldependency.common.constants.log.FineConstants.SYSTEM_PROPERTY_NOT_TO_DISPLAY_FINE;
34 import static net.sourceforge.plantumldependency.common.utils.log.LogUtils.buildLogString;
35 import static net.sourceforge.plantumldependency.common.utils.string.StringUtils.convertObjectSetIntoStringSet;
36
37 import java.io.PrintStream;
38 import java.util.Map;
39 import java.util.Set;
40 import java.util.TreeSet;
41 import java.util.logging.Level;
42 import java.util.logging.Logger;
43
44
45
46
47
48
49
50
51 public abstract class SystemUtils {
52
53
54 private static final transient Logger LOGGER = getLogger(SystemUtils.class.getName());
55
56
57
58
59
60
61
62 public static Set < String > getSystemPropertiesSetToDisplay() {
63 return getSystemPropertiesSetToDisplay(convertObjectSetIntoStringSet(getProperties().keySet()));
64 }
65
66
67
68
69
70
71
72
73
74
75 public static Set < String > getSystemPropertiesSetToDisplay(final Set < String > propertiesSet) {
76 final Set < String > systemPropertiesSetToDisplay = new TreeSet < String >();
77
78 for (final Map.Entry < Object, Object > property : getProperties().entrySet()) {
79 if (propertiesSet.contains(property.getKey())) {
80 final String propertyStr = property.getKey() + SPACE_CHAR + COLON_CHAR + SPACE_CHAR
81 + property.getValue();
82 systemPropertiesSetToDisplay.add(propertyStr);
83 } else {
84 LOGGER.log(FINE, buildLogString(SYSTEM_PROPERTY_NOT_TO_DISPLAY_FINE, property));
85 }
86 }
87
88 return systemPropertiesSetToDisplay;
89 }
90
91
92
93
94
95
96
97
98 public static void printSystemProperties() {
99 printSystemProperties(LOGGER, INFO, convertObjectSetIntoStringSet(getProperties().keySet()));
100 }
101
102
103
104
105
106
107
108
109
110
111 public static void printSystemProperties(final Logger logger) {
112 printSystemProperties(logger, INFO, convertObjectSetIntoStringSet(getProperties().keySet()));
113 }
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129 public static void printSystemProperties(final Logger logger, final Level level, final Set < String > propertiesSet) {
130 final Set < String > systemPropertiesSetToDisplay = getSystemPropertiesSetToDisplay(propertiesSet);
131
132 for (final String propertyStr : systemPropertiesSetToDisplay) {
133 logger.log(level, propertyStr);
134 }
135 }
136
137
138
139
140
141
142
143
144
145
146
147
148
149 public static void printSystemProperties(final Logger logger, final Set < String > propertiesSet) {
150 printSystemProperties(logger, INFO, propertiesSet);
151 }
152
153
154
155
156
157
158
159
160
161
162 public static void printSystemProperties(final PrintStream printStream) {
163 printSystemProperties(printStream, convertObjectSetIntoStringSet(getProperties().keySet()));
164 }
165
166
167
168
169
170
171
172
173
174
175
176
177
178 public static void printSystemProperties(final PrintStream printStream, final Set < String > propertiesSet) {
179 final Set < String > systemPropertiesSetToDisplay = getSystemPropertiesSetToDisplay(propertiesSet);
180
181 for (final String propertyStr : systemPropertiesSetToDisplay) {
182 printStream.println(propertyStr);
183 }
184 }
185
186
187
188
189
190
191
192
193
194
195 public static void printSystemProperties(final Set < String > propertiesSet) {
196 printSystemProperties(LOGGER, INFO, propertiesSet);
197 }
198
199
200
201
202
203
204 private SystemUtils() {
205 super();
206 }
207 }