All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hibernate.boot.model.source.internal.hbm.CommaSeparatedStringHelper Maven / Gradle / Ivy

There is a newer version: 7.0.0.Alpha1
Show newest version
/*
 * 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() );
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy