<commit_before>/**
 * Color names and their RGB color components.
 * A name to RGB value lookup table using colors read from a UNIX-style rgb.txt file.
 */

/*
 * $Id$
 */
 
import java.util.Hashtable;

public class ColorDatabase
{
	static private boolean mIsLoaded = false;
	static private Hashtable mColors;
	
	/*
	 * Load colors the first time a color is requested.
	 * Don't worry about race-condition -- two threads loading colors
	 * at same time is harmless.
	 */
	private static void loadColors()
	{
		mColors = new Hashtable();
		
		/*
		 * If user gave name of file as property then read that.
		 */
		 
		/*
		 * Otherwise try to read /usr/lib/X11/rgb.txt.
		 */
	}
	
	public static int []getRGBValues(String colorName)
	{
		if (mIsLoaded == false)
		{
			loadColors();
			mIsLoaded = true;
		}
		
 		int []retval = {255, 0, 0};
		
		return(retval);
	}
}<commit_msg>Implement it.  Now reads colors and then looks them up.<commit_after>/**
 * Color names and their RGB color components.
 * A name to RGB value lookup table using colors read from a UNIX-style rgb.txt file.
 */

/*
 * $Id$
 */
 
import java.util.Hashtable;
import java.awt.Color;
import java.lang.SecurityException;
import java.io.LineNumberReader;
import java.io.FileReader;
import java.util.StringTokenizer;
import java.lang.NumberFormatException;
import java.io.FileNotFoundException;
import java.io.IOException;

public class ColorDatabase
{
	static private Hashtable mColors;
	
	/**
	 * Load global color name database from a file.
	 */
	public static void initialise() throws MapyrusException, IOException
	{
		String filename, line;
		StringTokenizer st;
		LineNumberReader reader = null;
		
		mColors = new Hashtable();
		
		/*
		 * If user gave name of file as property then use that.
		 */
		try
		{
			filename = System.getProperty(Mapyrus.PROGRAM_NAME + ".rgbfile");
		}
		catch (SecurityException e)
		{
			filename = null;
		}
		
		try
		{
			/*
			 * Look for a rgb.txt file in current directory if no
			 * filename given.
			 */
			if (filename == null)
				filename = "rgb.txt";		
			reader = new LineNumberReader(new FileReader(filename));
		}
		catch (FileNotFoundException e)
		{
			filename = null;
		}
		
		try
		{
			/*
			 * Otherwise try to read operating system
			 * /usr/lib/X11/rgb.txt file.
			 */
			if (filename == null)
			{
				filename = "/usr/lib/X11/rgb.txt";
				reader = new LineNumberReader(new FileReader(filename));
			}
		}
		catch (FileNotFoundException e)
		{
			/*
			 * No color name database available.
			 */
			return;
		}

		while ((line = reader.readLine()) != null)
		{
			/*
			 * Parse RGB values and color name from each line.
			 */
			st = new StringTokenizer(line);
			if (st.countTokens() >= 4)
			{
				String red = st.nextToken();
				String green = st.nextToken();
				String blue = st.nextToken();
				
				/*
				 * Name may be a single word or multiple words.
				 * Both "green" and "dark green" are accepted.
				 */
				String name = st.nextToken();
				while (st.hasMoreTokens())
				{
					name = name.concat(st.nextToken());
				}
				
				/*
				 * Skip lines that begin with comment character.
				 */
				if (!red.startsWith("!"))
				{
					try
					{
						int r = Integer.parseInt(red);
						int g = Integer.parseInt(green);
						int b = Integer.parseInt(blue);
						mColors.put(name.toLowerCase(), new Color(r, g, b));
					}
					catch (NumberFormatException e)
					{
						throw new MapyrusException("Invalid color at line " +
							reader.getLineNumber() + " in " + filename);
					}
				}
			}
		}
	}

	/**
	 * Return color structure from named color.
	 * @param colorName is color to lookup.
	 * @return color definition, or null if color not known.
	 */	
	public static Color getColor(String colorName)
	{
		String s = colorName.toLowerCase();
		int nChars = s.length();
		char c;
		StringBuffer b = new StringBuffer(nChars);
		
		/*
		 * Remove whitespace from color name.
		 */
		for (int i = 0; i < nChars; i++)
		{
			c = s.charAt(i);
			if (!Character.isWhitespace(c))
			{
				b.append(c);
			}
		}
		
		Color retval = (Color)mColors.get(b.toString());
		return(retval);
	}
}
{'fraction_non_alphanumeric': 0.11812921890067503, 'fraction_numerical': 0.00313404050144648, 'mean_word_length': 2.5552699228791775, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1192959', 'n_tokens_mistral': 1627, 'n_tokens_neox': 1299, 'n_words': 404}