24h-payday

Posts Tagged ‘enumerations’

Refactoring, refactoring…

Saturday, April 11th, 2009

Yep. Old code was … old, and kind of ugly. Okay, just plain ugly. So refactoring was in order, like on the Ping Factory class which looks much cleaner now:

import java.lang.management.ManagementFactory;
import java.util.Set;
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.prefs.Preferences;
import java.util.ResourceBundle;

import javax.management.MBeanServer;
import javax.management.ObjectName;

/**
 * Factory class to return the proper Ping instance
 * @author undead@stupidzombie.com
 */
public final class PingFactory {
	
	/**
	 * Supported ping types
	 */
	public static enum PingTypes {
		
		UNKNOWN("", ""), 
		TO2BLOGS("To2Blogs", "PINGBLOG_TO2BLOGS_UNIQUEID"), 
		BLOGALAXIA("Blogalaxia", "PINGBLOG_BLOGALAXIA_UNIQUEID"), 
		VENEBLOGS("Venblogs", ""), 
		WEBLOGS("Weblogs", ""), 
		TECHNORATI("Technorati", ""), 
		BITACORASCOM("Bitacoras.com", ""), 
		PINGOMATIC("PingOMatic", "");
		
		public String desc;
		public String id;
		private PingTypes(final String aDesc, final String aId) {
			desc = aDesc;
			id = aId;
		}
	}
	
	private static PingFactory factory;
       // Rest of the code ommited :)

it is amazing how simple Enumerations simplified the code on this class. Now working on the ping controller, that section is long overdue 🙂