// Copyright (c) 1999 Brian Wellington (bwelling@xbill.org)
// Portions Copyright (c) 1999 Network Associates, Inc.

package org.xbill.DNS;

import org.xbill.DNS.utils.*;

/**
 * Constants and functions relating to DNS classes.  This is called DClass
 * since Class was already taken.
 *
 * @author Brian Wellington
 */

public final class DClass {

private static StringValueTable classes = new StringValueTable();

/** Internet */
public static final short IN		= 1;

/** Chaos network (MIT) */
public static final short CHAOS		= 3;

/** Hesiod name server (MIT) */
public static final short HESIOD	= 4;

/** Special value used in dynamic update messages */
public static final short NONE		= 254;

/** Matches any class */
public static final short ANY		= 255;

private static Short [] classcache = new Short [5];

static {
	for (short i = 0; i < classcache.length; i++)
		classcache[i] = new Short(i);
	classes.put2(IN, "IN");
	classes.put2(CHAOS, "CHAOS");
	classes.put2(HESIOD, "HESIOD");
	classes.put2(NONE, "NONE");
	classes.put2(ANY, "ANY");
}

private
DClass() {}

/** Converts a numeric Class into a String */
public static String
string(int i) {
	String s = classes.getString(i);
	return (s != null) ? s : ("CLASS" + i);
}

/** Converts a String representation of an Class into its numeric value */
public static short
value(String s) {
	short i = (short) classes.getValue(s.toUpperCase());
	if (i >= 0)
		return i;
	try {
		if (s.toUpperCase().startsWith("CLASS"))
			return (Short.parseShort(s.substring(5)));
		else
			return Short.parseShort(s);
	}
	catch (Exception e) {
		return (-1);
	}
}

/* Converts a class into a Short, for use in Hashmaps, etc. */
static Short
toShort(short dclass) {
	if (dclass < classcache.length)
		return (classcache[dclass]);
	return new Short(dclass);
}

}

@@ -481,32 +481,111 @@
 etwork (MIT) */%0A
+public static final short CH%09%09= 3;%0A%0A/** Chaos network (MIT, alternate name) */%0A
 public static fi
@@ -1028,24 +1028,49 @@
 , %22CHAOS%22);%0A
+%09classes.put2(CH, %22CH%22);%0A
 %09classes.put

The official name of class 3 is CH, not CHAOS.