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

net.amygdalum.util.text.CharAlphabet Maven / Gradle / Ivy

Go to download

Searching and Matching Strings with efficient algorithms: - Knuth-Morris-Pratt - Shift-And/Or - Boyer-Moore-Horspool - Sunday (QuickSearch) - BNDM - BOM - Aho-Corasick - Set-Horspool - Wu-Manber - Set-BOM

There is a newer version: 0.4.4
Show newest version
package net.amygdalum.util.text;

public class CharAlphabet {

	private char minChar;
	private char maxChar;

	private CharAlphabet() {
		this.minChar = Character.MAX_VALUE;
		this.maxChar = Character.MIN_VALUE;
	}

	public static CharAlphabet ranged(char[] pattern, CharMapping mapping) {
		CharAlphabet charAlphabet = new CharAlphabet();
		for (char pc : pattern) {
			for (char c : mapping.map(pc)) {
				charAlphabet.add(c);
			}
		}
		return charAlphabet;
	}

	public static CharAlphabet ranged(char[] pattern) {
		CharAlphabet charAlphabet = new CharAlphabet();
		for (char c : pattern) {
			charAlphabet.add(c);
		}
		return charAlphabet;
	}

	private void add(char c) {
		if (c < minChar) {
			minChar = c;
		}
		if (c > maxChar) {
			maxChar = c;
		}
	}

	public int getRange() {
		if (maxChar <= minChar) {
			return 0;
		}
		return maxChar - minChar + 1;
	}

	public char minChar() {
		return minChar;
	}

	public char maxChar() {
		return maxChar;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy