org.hibernate.boot.model.source.internal.hbm.CommaSeparatedStringHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hibernate-core Show documentation
Show all versions of hibernate-core Show documentation
JPMS Module-Info's for a few of the Jakarta Libraries just until they add them in themselves
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or .
*/
package org.hibernate.boot.model.source.internal.hbm;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.hibernate.internal.util.StringHelper;
/**
* @author Steve Ebersole
* @author Sanne Grinovero
*/
public final class CommaSeparatedStringHelper {
private static final Pattern COMMA_SEPARATED_PATTERN = Pattern.compile( "\\s*,\\s*" );
private CommaSeparatedStringHelper() {
}
public static Set split(String values) {
if ( values == null || values.isEmpty() ) {
return Collections.emptySet();
}
return COMMA_SEPARATED_PATTERN.splitAsStream( values ).collect( Collectors.toSet() );
}
public static Set splitAndCombine(Set x, String values) {
if ( x.isEmpty() && ( values == null || values.isEmpty() ) ) {
return Collections.emptySet();
}
HashSet set = new HashSet( x );
if ( values != null && !values.isEmpty() ) {
Collections.addAll( set, COMMA_SEPARATED_PATTERN.split( values ) );
}
return set;
}
public static List parseCommaSeparatedString(String incomingString) {
if ( StringHelper.isEmpty( incomingString ) ) {
return Collections.emptyList();
}
return COMMA_SEPARATED_PATTERN.splitAsStream( incomingString ).collect( Collectors.toList() );
}
}