From 8e090c179e3486dc91a16952e1f4a946c371ecd9 Mon Sep 17 00:00:00 2001 From: Robert Greene Date: Tue, 17 Jun 2008 02:47:48 +0000 Subject: [PATCH] ThreadFormat now knows its code; changed logic of find to use the coding instead of a switch statement. --- src/com/webcodepro/shrinkit/ThreadFormat.java | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/com/webcodepro/shrinkit/ThreadFormat.java b/src/com/webcodepro/shrinkit/ThreadFormat.java index f9cfe1b..97f9f82 100644 --- a/src/com/webcodepro/shrinkit/ThreadFormat.java +++ b/src/com/webcodepro/shrinkit/ThreadFormat.java @@ -5,23 +5,28 @@ package com.webcodepro.shrinkit; * @author robgreene@users.sourceforge.net */ public enum ThreadFormat { - UNCOMPRESSED, HUFFMAN_SQUEEZE, DYNAMIC_LZW1, DYNAMIC_LZW2, - UNIX_12BIT_COMPRESS, UNIX_16BIT_COMPRESS; + UNCOMPRESSED(0x0000), HUFFMAN_SQUEEZE(0x0001), DYNAMIC_LZW1(0x0002), DYNAMIC_LZW2(0x0003), + 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. * @throws IllegalArgumentException if the thread_format is unknown */ public static ThreadFormat find(int threadFormat) { - switch (threadFormat) { - case 0x0000: return UNCOMPRESSED; - 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); + for (ThreadFormat f : values()) { + if (threadFormat == f.getThreadFormat()) return f; } + throw new IllegalArgumentException("Unknown thread_format of " + threadFormat); } }