Skip to content

Commit 1a85057

Browse files
committed
refactor: propagate constants from StringUtils class.
1 parent 3e4aa03 commit 1a85057

File tree

7 files changed

+31
-20
lines changed

7 files changed

+31
-20
lines changed

src/main/java/ru/mystamps/web/common/SlugUtils.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
import java.util.Locale;
2323

24+
import static org.apache.commons.lang3.StringUtils.EMPTY;
25+
2426
public final class SlugUtils {
2527

2628
private SlugUtils() {
@@ -35,9 +37,9 @@ public static String slugify(String text) {
3537
// replace multiple hyphens by one
3638
.replaceAll("-{2,}", "-")
3739
// remove leading hyphen
38-
.replaceAll("^-", "")
40+
.replaceAll("^-", EMPTY)
3941
// remove ending hyphen
40-
.replaceAll("-$", "");
42+
.replaceAll("-$", EMPTY);
4143
}
4244

4345
}

src/main/java/ru/mystamps/web/feature/series/JdbcStampsCatalogDao.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import java.util.Map;
2929
import java.util.Set;
3030

31+
import static org.apache.commons.lang3.StringUtils.EMPTY;
32+
3133
@RequiredArgsConstructor
3234
public class JdbcStampsCatalogDao implements StampsCatalogDao {
3335

@@ -39,7 +41,7 @@ public class JdbcStampsCatalogDao implements StampsCatalogDao {
3941

4042
@Override
4143
public List<String> add(Set<String> catalogNumbers) {
42-
Validate.validState(!"".equals(addCatalogNumberSql), "Query must be non empty");
44+
Validate.validState(!EMPTY.equals(addCatalogNumberSql), "Query must be non empty");
4345

4446
List<String> inserted = new ArrayList<>();
4547
for (String number : catalogNumbers) {
@@ -59,7 +61,7 @@ public List<String> add(Set<String> catalogNumbers) {
5961
public void addToSeries(Integer seriesId, Set<String> catalogNumbers) {
6062
Validate.validState(seriesId != null, "Series id must be non null");
6163
Validate.validState(!catalogNumbers.isEmpty(), "Catalog numbers must be non empty");
62-
Validate.validState(!"".equals(addCatalogNumbersToSeriesSql), "Query must be non empty");
64+
Validate.validState(!EMPTY.equals(addCatalogNumbersToSeriesSql), "Query must be non empty");
6365

6466
Map<String, Object> params = new HashMap<>();
6567
params.put("series_id", seriesId);

src/main/java/ru/mystamps/web/feature/series/SeriesController.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@
7777
import java.util.Objects;
7878
import java.util.stream.Collectors;
7979

80+
import static org.apache.commons.lang3.StringUtils.EMPTY;
81+
import static org.apache.commons.lang3.StringUtils.SPACE;
8082
import static ru.mystamps.web.common.ControllerUtils.redirectTo;
8183

8284
@Controller
@@ -107,7 +109,7 @@ public class SeriesController {
107109

108110
@InitBinder("addSeriesForm")
109111
protected void initSeriesFormBinder(WebDataBinder binder) {
110-
StringTrimmerEditor editor = new StringTrimmerEditor(" ", true);
112+
StringTrimmerEditor editor = new StringTrimmerEditor(SPACE, true);
111113
binder.registerCustomEditor(String.class, "michelNumbers", editor);
112114
binder.registerCustomEditor(String.class, "scottNumbers", editor);
113115
binder.registerCustomEditor(String.class, "yvertNumbers", editor);
@@ -555,8 +557,8 @@ public String processAskForm(
555557

556558
@GetMapping(SeriesUrl.SEARCH_SERIES_BY_CATALOG)
557559
public String searchSeriesByCatalog(
558-
@RequestParam(name = "catalogNumber", defaultValue = "") String catalogNumber,
559-
@RequestParam(name = "catalogName", defaultValue = "") String catalogName,
560+
@RequestParam(name = "catalogNumber", defaultValue = EMPTY) String catalogNumber,
561+
@RequestParam(name = "catalogName", defaultValue = EMPTY) String catalogName,
560562
@RequestParam(name = "inCollection", defaultValue = "false") Boolean inCollection,
561563
@CurrentUser Integer currentUserId,
562564
Model model,

src/main/java/ru/mystamps/web/feature/series/importing/ExpandCatalogNumbersEditor.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
import java.beans.PropertyEditorSupport;
2525
import java.util.Set;
2626

27+
import static org.apache.commons.lang3.StringUtils.EMPTY;
28+
import static org.apache.commons.lang3.StringUtils.SPACE;
29+
2730
/**
2831
* Expands range of catalog numbers (1-3) into a comma-separated list (1,2,3).
2932
*
@@ -33,10 +36,6 @@
3336
@RequiredArgsConstructor
3437
public class ExpandCatalogNumbersEditor extends PropertyEditorSupport {
3538

36-
// We can't use StringUtils.EMPTY constant from commons-lang because
37-
// we are using StringUtils from Spring.
38-
private static final String EMPTY = "";
39-
4039
@Override
4140
public void setAsText(String text) {
4241
String result = null;
@@ -50,7 +49,7 @@ public void setAsText(String text) {
5049
//
5150
// @todo #694 ExpandCatalogNumbersEditor: find a better way of editors composition
5251
String value = text.trim();
53-
value = StringUtils.deleteAny(value, " ");
52+
value = StringUtils.deleteAny(value, SPACE);
5453

5554
if (!value.equals(EMPTY)) {
5655
try {

src/main/java/ru/mystamps/web/support/spring/mvc/ReplaceRepeatingSpacesEditor.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
import java.beans.PropertyEditorSupport;
2323
import java.util.regex.Pattern;
2424

25+
import static org.apache.commons.lang3.StringUtils.EMPTY;
26+
import static org.apache.commons.lang3.StringUtils.SPACE;
27+
2528
/**
2629
* @author Maxim Shestakov
2730
* @author Slava Semushin
@@ -36,10 +39,10 @@ public void setAsText(String name) throws IllegalArgumentException {
3639
String text = name.trim();
3740

3841
if (text.contains(" ")) {
39-
text = REPEATING_SPACES.matcher(text).replaceAll(" ");
42+
text = REPEATING_SPACES.matcher(text).replaceAll(SPACE);
4043
}
4144

42-
if (emptyAsNull && "".equals(text)) { // NOPMD: AvoidLiteralsInIfCondition (it's ok for me)
45+
if (emptyAsNull && EMPTY.equals(text)) {
4346
text = null; // NOPMD: NullAssignment (we need it)
4447
}
4548

src/main/java/ru/mystamps/web/support/spring/security/ContentSecurityPolicyHeaderWriter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030
import java.util.regex.Pattern;
3131

32+
import static org.apache.commons.lang3.StringUtils.EMPTY;
33+
3234
/**
3335
* Implementation of {@link HeaderWriter} that is adding CSP header depending on the current URL.
3436
*/
@@ -39,7 +41,7 @@ class ContentSecurityPolicyHeaderWriter implements HeaderWriter {
3941
private static final String CSP_REPORT_ONLY_HEADER = "Content-Security-Policy-Report-Only";
4042

4143
private static final String COLLECTION_INFO_PAGE_PATTERN =
42-
CollectionUrl.INFO_COLLECTION_PAGE.replace("{slug}", "");
44+
CollectionUrl.INFO_COLLECTION_PAGE.replace("{slug}", EMPTY);
4345

4446
private static final Pattern SERIES_INFO_PAGE_PATTERN =
4547
Pattern.compile(SeriesUrl.SERIES_INFO_PAGE_REGEXP);

src/test/java/ru/mystamps/web/tests/Random.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import static io.qala.datagen.RandomValue.between;
5656
import static io.qala.datagen.StringModifier.Impls.multipleOf;
5757
import static io.qala.datagen.StringModifier.Impls.oneOf;
58+
import static org.apache.commons.lang3.StringUtils.SPACE;
5859

5960
public final class Random {
6061

@@ -104,7 +105,7 @@ public static String login() {
104105
.with(multipleOf(" -_"))
105106
.alphanumeric();
106107

107-
if (StringUtils.containsAny(login, " ", "--", "__")) {
108+
if (StringUtils.containsAny(login, SPACE, "--", "__")) {
108109
return login();
109110
}
110111

@@ -147,8 +148,8 @@ public static String categoryName() {
147148
.with(oneOf(" -"))
148149
.english();
149150

150-
if (StringUtils.startsWithAny(name, " ", "-")
151-
|| StringUtils.endsWithAny(name, " ", "-")) {
151+
if (StringUtils.startsWithAny(name, SPACE, "-")
152+
|| StringUtils.endsWithAny(name, SPACE, "-")) {
152153
return countryName();
153154
}
154155

@@ -167,8 +168,8 @@ public static String countryName() {
167168
.with(oneOf(" -"))
168169
.english();
169170

170-
if (StringUtils.startsWithAny(name, " ", "-")
171-
|| StringUtils.endsWithAny(name, " ", "-")) {
171+
if (StringUtils.startsWithAny(name, SPACE, "-")
172+
|| StringUtils.endsWithAny(name, SPACE, "-")) {
172173
return countryName();
173174
}
174175

0 commit comments

Comments
 (0)