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

com.softicar.platform.common.string.normalizer.DiacriticNormalizationCache Maven / Gradle / Ivy

Go to download

The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.

There is a newer version: 50.0.0
Show newest version
package com.softicar.platform.common.string.normalizer;

import java.util.HashMap;
import java.util.Map;

/**
 * A cache for {@link DiacriticNormalizer}.
 *
 * @author Alexander Schmidt
 */
public class DiacriticNormalizationCache {

	private final DiacriticNormalizer normalizer;
	private final Map normalizedTextMap;

	/**
	 * Constructs a new {@link DiacriticNormalizationCache}.
	 */
	public DiacriticNormalizationCache() {

		this.normalizer = new DiacriticNormalizer();
		this.normalizedTextMap = new HashMap<>();
	}

	/**
	 * Uses {@link DiacriticNormalizer#normalize(String)} to remove diacritics
	 * from the characters in the given text.
	 * 

* The result is cached, so that {@link DiacriticNormalizer} will not be * invoked again for the same text. * * @param text * the text to strip of diacritical marks (never null) * @return the given text, stripped of diacritical marks (never null) */ public String normalize(String text) { return normalizedTextMap.computeIfAbsent(text, normalizer::normalize); } /** * Clears all previously cached normalized texts. */ public void clear() { normalizedTextMap.clear(); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy