class StringUtils {

	public static int countWords(String str, boolean all) {
		if (str == null || str.length() == 0) {
			return 0;
		}
		String[] words;
		if (all) {
			words = str.split("\\s+"); // Splits at whitespaces.
		} else {
			words = str.split("[\\s\\*\\#\\_\\|]+");
		}

		int count = 0;
		for (String word : words) {
			if (word.length() > 0) {
				count++;
			}
		}

		return count;
	}

}