package cc;



import java.util.Hashtable;



public class Parameters {

	private static String[] args;

	private static java.util.Hashtable hashArgs = new Hashtable();



	private static String getString(String par) {

		if (hashArgs.containsKey(par))

			return ((String) hashArgs.get(par));

		else

			return null;

	}



	private static int getInt(String par) {

		return (new Integer(getString(par)).intValue());

	}



	public static boolean getPair() {

		if (getString("Pair").equals("on"))

			return true;

			else

		return false;

	}

	public static String getHost() {

		return getString("Host");

	}

	public static int getPort() {

		return getInt("Port");

	}

	public static int getPairType() {

		if (getString("PairType").equals("cp"))

			return 1;

		else

			return 2;

	}

	public static int getInterPair() {

		return getInt("InterPair");

	}

	public static int getIntraPair() {

		return getInt("IntraPair");

	}

	public static int getMaxSize() {

		return getInt("MaxSize");

	}

	public static int getMinSize() {

		return getInt("MinSize");

	}

	public static int getMaxDelay() {

		return getInt("MaxDelay");

	}

	public static int getMinDelay() {

		return getInt("MinDelay");

	}

	public static int getSize() {

		return getInt("Size");

	}

	public static int getDelay() {

		return getInt("Delay");

	}

	public static String getProfile() {

		return getString("Profile");

	}

	public static int getInterval() {

		return getInt("Interval");

	}

	public static int getNumber() {

		return getInt("Number");

	}

	public static int getDuration() {

		return getInt("Duration");

	}

	public static int getTimeout() {

		return getInt("Timeout");

	}

	public static int getMaxBucket() {

		return getInt("MaxBucket");

	}

	public static String getResend() {

		return getString("Resend");

	}



	public static String getBucket() {

		return getString("Resend");

	}



	public static void printUsage() {

		System.out.println(

			"java cc.Client -ORBIntialHost <host> -ORBIntialPort <port> Diretive <value>");

		System.out.println(

			"java cc.Server -ORBIntialHost <host> -ORBIntialPort <port> Diretive <value>");

		System.out.println();

		System.out.println(

			"Example: java cc.Client -ORBIntialHost localhost -ORBIntialPort 1050 Size 2000 Delay 40 ");

		System.out.println();

		System.out.println(

			"Default Values for Diretives: " + hashArgs.toString());

	}



	public static void parseArgs(String Args[]) {

		setArgs(Args);



		//Fill default values

		hashArgs.put("Bucket", "off");

		hashArgs.put("Delay", "30");

		hashArgs.put("Duration", "0");

		hashArgs.put("Interval", "2");

		hashArgs.put("LogInterval", "2");

		hashArgs.put("MaxBucket", "25");

		hashArgs.put("MaxDelay", "120");

		hashArgs.put("MaxSize", "65507");

		hashArgs.put("MinDelay", "1");

		hashArgs.put("MinSize", "100");

		hashArgs.put("Number", "0");

		hashArgs.put("Profile", "hard");

		hashArgs.put("Resend", "off");

		hashArgs.put("Size", "7500");

		hashArgs.put("Timeout", "60");

		hashArgs.put("Pair", "off");

		hashArgs.put("PairType", "pp");

		hashArgs.put("InterPair", "500");

		hashArgs.put("IntraPair", "0");

		hashArgs.put("Host", "localhost");

		hashArgs.put("Port", "1057");



		//Verify Args size zero or odd

		if ((Args.length == 0)

			|| ((float) Args.length / 2) > (Args.length / 2)) {

			//Impar

			printUsage();

			System.exit(0);

		} else {

			for (int i = 0; i < Args.length; i += 2) {

				hashArgs.put(Args[i], Args[i + 1]);

			}

		}

	}



	private static void setArgs(String[] args) {

		Parameters.args = args;

	}



	public static String[] getArgs() {

		return args;

	}

}