package com.alexrnl.commons.utils;

import java.util.Objects;
import java.util.logging.Logger;

/**
 * Represent a word in a {@link String}.<br />
 * @author Alex
 */
public final class Word {
	/** Logger */
	private static Logger	lg	= Logger.getLogger(Word.class.getName());
	
	/** The word it self */
	private final String	word;
	/** The index of the beginning of the word */
	private final int		begin;
	/** The index of the end of the word */
	private final int		end;
	
	/**
	 * Constructor #.<br />
	 * @param word
	 *        the word represented.
	 * @param begin
	 *        the index of the beginning of the word.
	 * @param end
	 *        the index of the end of the word.
	 */
	private Word (final String word, final int begin, final int end) {
		super();
		this.word = word;
		this.begin = begin;
		this.end = end;
	}

	/**
	 * Return the attribute word.
	 * @return the attribute word.
	 */
	public String getWord () {
		return word;
	}

	/**
	 * Return the attribute begin.
	 * @return the attribute begin.
	 */
	public int getBegin () {
		return begin;
	}

	/**
	 * Return the attribute end.
	 * @return the attribute end.
	 */
	public int getEnd () {
		return end;
	}
	
	/**
	 * Return the next word in the {@link String}.<br />
	 * @param string
	 *        the string to parse.
	 * @return the next word.
	 */
	public static Word getNextWord (final String string) {
		Objects.requireNonNull(string);
		
		int begin = 0;
		int end = string.length();
		
		boolean beginFound = false;
		int currentIndex = begin;
		while (currentIndex < end) {
			if (!beginFound && allowedInWord(string.charAt(currentIndex))) {
				begin = currentIndex;
				beginFound = true;
			} else if (beginFound && !allowedInWord(string.charAt(currentIndex))) {
				end = currentIndex;
			}
			currentIndex++;
		}
		
		return new Word(string.substring(begin, end), begin, end);
	}
	
	/**
	 * Check if a {@link Character} is allowed in a word.<br />
	 * <code>true</code> if this is a letter from the alphabet or a dash <code>-</code>.
	 * @param c
	 *        the character to check.
	 * @return <code>true</code> if the character can be found in a word.
	 */
	public static boolean allowedInWord (final char c) {
		return Character.isAlphabetic(c) || c == '-';
	}
}

@@ -55,16 +55,48 @@
 bjects;%0A
+import java.util.logging.Level;%0A
 import j
@@ -520,16 +520,17 @@
 ructor #
+1
 .%3Cbr /%3E%0A
@@ -576,16 +576,33 @@
 resented
+ (cannot be null)
 .%0A%09 * @p
@@ -730,22 +730,21 @@
 %0A%09 */%0A%09p
-rivate
+ublic
  Word (f
@@ -806,16 +806,201 @@
 uper();%0A
+%09%09Objects.requireNonNull(word);%0A%09%09if (word.length() != end - begin) %7B%0A%09%09%09throw new IllegalArgumentException(%22Word %22 + word + %22 does not fit between %22%0A%09%09%09%09%09+ begin + %22 and %22 + end);%0A%09%09%7D%0A
 %09%09this.w
@@ -2035,24 +2035,28 @@
 %09%0A%09%09
-return new Word(
+final String word = 
 stri
@@ -2079,16 +2079,146 @@
 in, end)
+;%0A%09%09if (lg.isLoggable(Level.FINE)) %7B%0A%09%09%09lg.fine(%22The next word in '%22 + string + %22' is '%22 + word + %22'%22);%0A%09%09%7D%0A%09%09return new Word(word
 , begin,

Check the difference between begin and end in the constructor of Word and add logging information