Skip to content

Commit 71d922f

Browse files
committed
improvement on pull request
1) prefer slf4j for logging. we do not use log4j directly 2) trim and warn optional properties, too
1 parent c138720 commit 71d922f

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

src/main/java/de/rwth/idsg/steve/utils/PropertiesFileLoader.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package de.rwth.idsg.steve.utils;
22

33
import com.google.common.base.Strings;
4-
import lombok.extern.log4j.Log4j2;
4+
import lombok.extern.slf4j.Slf4j;
55

66
import java.io.FileNotFoundException;
77
import java.io.InputStream;
@@ -13,7 +13,7 @@
1313
* @author Sevket Goekay <goekay@dbis.rwth-aachen.de>
1414
* @since 01.10.2015
1515
*/
16-
@Log4j2
16+
@Slf4j
1717
public class PropertiesFileLoader {
1818

1919
private Properties prop;
@@ -45,12 +45,7 @@ public String getString(String key) {
4545
throw new IllegalArgumentException("The property '" + key + "' has no value set");
4646
}
4747

48-
String trimmed = s.trim();
49-
if (!trimmed.equals(s)) {
50-
log.warn("The property '{}' has leading or trailing spaces which were removed!", key);
51-
}
52-
53-
return trimmed;
48+
return trim(key, s);
5449
}
5550

5651
public boolean getBoolean(String key) {
@@ -70,7 +65,7 @@ public String getOptionalString(String key) {
7065
if (Strings.isNullOrEmpty(s)) {
7166
return null;
7267
}
73-
return s;
68+
return trim(key, s);
7469
}
7570

7671
public Boolean getOptionalBoolean(String key) {
@@ -90,4 +85,16 @@ public Integer getOptionalInt(String key) {
9085
return Integer.parseInt(s);
9186
}
9287
}
88+
89+
// -------------------------------------------------------------------------
90+
// Private helpers
91+
// -------------------------------------------------------------------------
92+
93+
private static String trim(String key, String value) {
94+
String trimmed = value.trim();
95+
if (!trimmed.equals(value)) {
96+
log.warn("The property '{}' has leading or trailing spaces which were removed!", key);
97+
}
98+
return trimmed;
99+
}
93100
}

0 commit comments

Comments
 (0)