ThreadFormat now knows its code; changed logic of find to use the coding instead of a switch statement.

This commit is contained in:
Robert Greene 2008-06-17 02:47:48 +00:00
parent c0c6a6a55a
commit 8e090c179e

View File

@ -5,23 +5,28 @@ package com.webcodepro.shrinkit;
* @author robgreene@users.sourceforge.net * @author robgreene@users.sourceforge.net
*/ */
public enum ThreadFormat { public enum ThreadFormat {
UNCOMPRESSED, HUFFMAN_SQUEEZE, DYNAMIC_LZW1, DYNAMIC_LZW2, UNCOMPRESSED(0x0000), HUFFMAN_SQUEEZE(0x0001), DYNAMIC_LZW1(0x0002), DYNAMIC_LZW2(0x0003),
UNIX_12BIT_COMPRESS, UNIX_16BIT_COMPRESS; UNIX_12BIT_COMPRESS(0x0004), UNIX_16BIT_COMPRESS(0x0005);
/** Associate the hex codes with the enum */
private int threadFormat;
private ThreadFormat(int threadFormat) {
this.threadFormat = threadFormat;
}
public int getThreadFormat() {
return threadFormat;
}
/** /**
* Find the ThreadFormat. * Find the ThreadFormat.
* @throws IllegalArgumentException if the thread_format is unknown * @throws IllegalArgumentException if the thread_format is unknown
*/ */
public static ThreadFormat find(int threadFormat) { public static ThreadFormat find(int threadFormat) {
switch (threadFormat) { for (ThreadFormat f : values()) {
case 0x0000: return UNCOMPRESSED; if (threadFormat == f.getThreadFormat()) return f;
case 0x0001: return HUFFMAN_SQUEEZE;
case 0x0002: return DYNAMIC_LZW1;
case 0x0003: return DYNAMIC_LZW2;
case 0x0004: return UNIX_12BIT_COMPRESS;
case 0x0005: return UNIX_16BIT_COMPRESS;
default:
throw new IllegalArgumentException("Unknown thread_format of " + threadFormat);
} }
throw new IllegalArgumentException("Unknown thread_format of " + threadFormat);
} }
} }