From d533eb4a55baa9e03850801c30071af33bb9cbc8 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Tue, 5 Jul 2022 14:10:33 +0200 Subject: [PATCH] Use Set.of() in StringToBooleanConverter --- .../support/StringToBooleanConverter.java | 22 +++++-------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/StringToBooleanConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/StringToBooleanConverter.java index 4b1c0fd7b2..e54534705f 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/StringToBooleanConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/StringToBooleanConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,36 +16,24 @@ package org.springframework.core.convert.support; -import java.util.HashSet; import java.util.Set; import org.springframework.core.convert.converter.Converter; import org.springframework.lang.Nullable; /** - * Converts String to a Boolean. + * Converts a String to a Boolean. * * @author Keith Donald * @author Juergen Hoeller + * @author Sam Brannen * @since 3.0 */ final class StringToBooleanConverter implements Converter { - private static final Set trueValues = new HashSet<>(8); + private static final Set trueValues = Set.of("true", "on", "yes", "1"); - private static final Set falseValues = new HashSet<>(8); - - static { - trueValues.add("true"); - trueValues.add("on"); - trueValues.add("yes"); - trueValues.add("1"); - - falseValues.add("false"); - falseValues.add("off"); - falseValues.add("no"); - falseValues.add("0"); - } + private static final Set falseValues = Set.of("false", "off", "no", "0"); @Override