net.sf.mmm.util.text.base
Class HyphenationState

java.lang.Object
  extended by net.sf.mmm.util.text.base.HyphenationState

public class HyphenationState
extends Object

This class represents the current state of the hyphenation of a specific word.

Since:
2.0.0
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)
See Also:
Hyphenator.hyphenate(String, int, int)

Field Summary
private  StringHasher hasher
          The StringHasher to use.
private  int[][] hashes
          The hashes of all substrings of normalizedWord.
private  char hyphen
           
private static int MIN_PATTERN_LENGTH
          The minimum length of a pattern.
private  char[] normalizedWord
          The normalized word.
private  int offset
          The offset where to start hyphenation in word.
private  int[] rankings
          The HyphenationPatternPosition.rankings
private  StringUtil stringUtil
          The StringUtil to use.
private  String word
           
 
Constructor Summary
HyphenationState(String word, String normalizedWord, char hyphen, int maxPatternLength, int offset, StringHasher hasher, StringUtil stringUtil)
          The constructor.
 
Method Summary
 void apply(HyphenationPattern pattern)
          This is the heart of the hyphenation algorithm.
private  void apply(HyphenationPattern pattern, int pos)
          This method applies the pattern matching at the given offset.
private  int[] getHashes(int length)
          This method gets the hashes of all substrings of the normalized word that have the given length.
protected  char[] getNormalizedWord()
          This method gets the normalized word.
 String getWord()
          This method gets the word to hyphenate.
 Hyphenation toHyphenation()
          This method gets the Hyphenation from this state.
protected  int[] toHyphenationPoints()
          This method creates the hyphenationPoints of a hyphenated word.
 String toString()
          This method generates a string with the given word including the ranked hyphenation points.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MIN_PATTERN_LENGTH

private static final int MIN_PATTERN_LENGTH
The minimum length of a pattern.

See Also:
Constant Field Values

hasher

private final StringHasher hasher
The StringHasher to use.


stringUtil

private final StringUtil stringUtil
The StringUtil to use.


word

private final String word
See Also:
getWord()

normalizedWord

private final char[] normalizedWord
The normalized word.


hashes

private int[][] hashes
The hashes of all substrings of normalizedWord. The first index indicates the substring-length - 2, the second is the offset in normalizedWord.


rankings

private final int[] rankings
The HyphenationPatternPosition.rankings


offset

private final int offset
The offset where to start hyphenation in word.


hyphen

private final char hyphen
See Also:
Hyphenator.getHyphen()
Constructor Detail

HyphenationState

public HyphenationState(String word,
                        String normalizedWord,
                        char hyphen,
                        int maxPatternLength,
                        int offset,
                        StringHasher hasher,
                        StringUtil stringUtil)
The constructor.

Parameters:
word - is the word to hyphenate.
normalizedWord - is the normalized word.
hyphen - is the hyphen.
maxPatternLength - is the maximum length of all patterns.
offset - is the start-position in word. Typically 0.
hasher - is the hash-algorithm. It should be fast. The same StringHasher needs to be used for HyphenationPattern.getWordPartHash().
stringUtil - is the StringUtil to use.
Method Detail

getHashes

private int[] getHashes(int length)
This method gets the hashes of all substrings of the normalized word that have the given length.

Parameters:
length - is the length of the substrings to get hashes for.
Returns:
the array with the hashes.

apply

public void apply(HyphenationPattern pattern)
This is the heart of the hyphenation algorithm. It checks if the pattern is a substring of the

Parameters:
pattern - is the pattern to check and potentially apply.

apply

private void apply(HyphenationPattern pattern,
                   int pos)
This method applies the pattern matching at the given offset.

Parameters:
pattern - is the matching pattern.
pos - is the offset in the word to hyphenate.

toHyphenationPoints

protected int[] toHyphenationPoints()
This method creates the hyphenationPoints of a hyphenated word.

Returns:
the hyphenation points.
See Also:
toHyphenation()

toHyphenation

public Hyphenation toHyphenation()
This method gets the Hyphenation from this state.

Returns:
the Hyphenation.

getWord

public String getWord()
This method gets the word to hyphenate.

Returns:
the word to hyphenate.

getNormalizedWord

protected char[] getNormalizedWord()
This method gets the normalized word. This is the word in normalized form (lower case) and surrounded by HyphenationPattern.TERMINATOR.

Returns:
the normalizedWord.

toString

public String toString()
This method generates a string with the given word including the ranked hyphenation points. It is intended for debugging purposes.

Overrides:
toString in class Object
Returns:
the word with hyphenation ranks.


Copyright © 2001-2010 mmm-Team. All Rights Reserved.