package com.censoredsoftware.censoredlib.util;

import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;

import java.util.Collection;

public class Strings
{
	/**
	 * Returns true if the <code>string</code> starts with a vowel.
	 * 
	 * @param string the string to check.
	 */
	public static boolean beginsWithVowel(String string)
	{
		String[] vowels = { "a", "e", "i", "o", "u" };
		return StringUtils.startsWithAny(string.toLowerCase(), vowels);
	}

	/**
	 * Returns true if the <code>string</code> starts with a consonant.
	 * 
	 * @param string the string to check.
	 */
	public static boolean beginsWithConsonant(String string)
	{
		return !beginsWithVowel(string);
	}

	/**
	 * Returns true if the <code>string</code> contains any of the strings held in the <code>collection</code>.
	 * 
	 * @param check the string to check.
	 * @param collection the collection given.
	 */
	public static boolean containsAnyInCollection(final String check, Collection<String> collection)
	{
		return Iterables.any(collection, new Predicate<String>()
		{
			@Override
			public boolean apply(String string)
			{
				return StringUtils.containsIgnoreCase(check, string);
			}
		});
	}

	/**
	 * Checks the <code>string</code> for <code>max</code> capital letters.
	 * 
	 * @param string the string to check.
	 * @param max the maximum allowed capital letters.
	 */
	public static boolean hasCapitalLetters(String string, int max)
	{
		// Define variables
		String allCaps = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		int count = 0;
		char[] characters = string.toCharArray();
		for(char character : characters)
		{
			if(allCaps.contains("" + character)) count++;
			if(count > max) return true;
		}
		return false;
	}

	/**
	 * Returns a color (red, yellow, green) based on the <code>value</code> and <code>max</code> passed in.
	 * 
	 * @param value the actual value.
	 * @param max the maximum value possible.
	 */
	public static ChatColor getColor(double value, double max)
	{
		ChatColor color = ChatColor.RESET;
		if(value < Math.ceil(0.33 * max)) color = ChatColor.RED;
		else if(value < Math.ceil(0.66 * max) && value > Math.ceil(0.33 * max)) color = ChatColor.YELLOW;
		if(value > Math.ceil(0.66 * max)) color = ChatColor.GREEN;
		return color;
	}

	/**
	 * Automatically removes underscores and returns a capitalized version of the given <code>string</code>.
	 * 
	 * @param string the string the beautify.
	 */
	public static String beautify(String string)
	{
		return StringUtils.capitalize(string.toLowerCase().replace("_", " "));
	}
}

@@ -170,16 +170,56 @@
 gUtils;%0A
+import org.atteo.evo.inflector.English;%0A
 import o
@@ -2368,24 +2368,122 @@
  color;%0A%09%7D%0A%0A
+%09public static String plural(String word, int count)%0A%09%7B%0A%09%09return English.plural(word, count);%0A%09%7D%0A%0A
 %09/**%0A%09 * Aut

Add new plural thing!