Browse Source

Implement StringToRegexConverter in Java

This commit implements StringToRegexConverter in Java
in order to avoid circular dependencies between Java
and Kotlin codes that can break IDE support, and for
consistency with the rest of the codebase.

See gh-24311
pull/31113/head
Sébastien Deleuze 2 years ago
parent
commit
f161bc798e
  1. 39
      spring-core/src/main/java/org/springframework/core/convert/support/StringToRegexConverter.java
  2. 19
      spring-core/src/main/kotlin/org/springframework/core/convert/support/StringToRegexConverter.kt

39
spring-core/src/main/java/org/springframework/core/convert/support/StringToRegexConverter.java

@ -0,0 +1,39 @@ @@ -0,0 +1,39 @@
/*
* 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.core.convert.support;
import kotlin.text.Regex;
import org.springframework.core.convert.converter.Converter;
/**
* Converts from a String to a {@link Regex}.
*
* @author Stephane Nicoll
* @author Sebastien Deleuze
*/
class StringToRegexConverter implements Converter<String, Regex> {
@Override
public Regex convert(String source) {
if (source.isEmpty()) {
return null;
}
return new Regex(source);
}
}

19
spring-core/src/main/kotlin/org/springframework/core/convert/support/StringToRegexConverter.kt

@ -1,19 +0,0 @@ @@ -1,19 +0,0 @@
package org.springframework.core.convert.support
import org.springframework.core.convert.converter.Converter
/**
* Converts from a String to a [Regex].
*
* @author Stephane Nicoll
*/
class StringToRegexConverter : Converter<String, Regex> {
override fun convert(source: String): Regex? {
if (source.isEmpty()) {
return null
}
return source.toRegex()
}
}
Loading…
Cancel
Save