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
This commit is contained in:
Sébastien Deleuze 2023-08-23 18:53:32 +02:00
parent 471e4d2b20
commit f161bc798e
2 changed files with 39 additions and 19 deletions

View File

@ -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);
}
}

View File

@ -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()
}
}