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

com.teamscale.commons.utils.StringPool Maven / Gradle / Ivy

/*
 * Copyright (c) CQSE GmbH
 *
 * 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
 *
 *     http://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 com.teamscale.commons.utils;

/**
 * Custom string pool which performs consistently faster when interning a lot of strings.
 * 
 * @link http://java-performance.info/string-intern-in-java-6-7-8/
 */
public class StringPool {

	private static final ObjectPool pool = new ObjectPool<>();

	/**
	 * Checks whether we already have a string in the StringPool that is equal to the given String. If
	 * such a String already exists it returns this String otherwise
	 */
	public static String intern(String str) {
		return pool.intern(str);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy