Index: mdr/src/org/netbeans/mdr/persistence/Storage.java =================================================================== RCS file: /cvs/mdr/src/org/netbeans/mdr/persistence/Storage.java,v retrieving revision 1.8 diff -u -r1.8 Storage.java --- mdr/src/org/netbeans/mdr/persistence/Storage.java 6 Nov 2002 16:11:09 -0000 1.8 +++ mdr/src/org/netbeans/mdr/persistence/Storage.java 23 Aug 2004 08:06:31 -0000 @@ -12,6 +12,9 @@ */ package org.netbeans.mdr.persistence; +import java.util.Collections; +import java.util.Arrays; + /** Set of indexes (Singlevalued and Multivalued) that are all updated * in a single transaction. Every index holds keys and every key in the index * is connected with a value or an ordered/unordered values. @@ -23,61 +26,40 @@ public interface Storage { /** Type of values and keys stored in index. */ - public static class EntryType { - + public static final class EntryType { + private byte id; + private String textId; + private EntryType(byte id, String textId) { + this.id = id; + this.textId = textId; + } + + public String toString() { return textId; } + public byte encode() { return id; } + /** Values are fixed length alphanumeric strings */ - public static EntryType MOFID =new EntryType () { - public String toString() { - return "MOFID"; - } - public byte encode() { - return 1; - } - }; + public static final EntryType MOFID = new EntryType ((byte)1, "MOFID"); /** Values are objects that implement the Streamable interface. * This type of values may not be used by user to create a new index, * it is used only in the primary index created by the Storage. */ - public static EntryType STREAMABLE =new EntryType () { - public String toString() { - return "STREAMABLE"; - } - public byte encode() { - return 2; - } - }; + public static final EntryType STREAMABLE =new EntryType ((byte)2, "STREAMABLE"); /** Values are variable length Strings. */ - public static EntryType STRING =new EntryType () { - public String toString() { - return "STRING"; - } - public byte encode() { - return 3; - } - }; + public static final EntryType STRING =new EntryType ((byte)3, "STRING"); /** Values are integers. */ - public static EntryType INT =new EntryType () { - public String toString() { - return "INT"; - } - public byte encode() { - return 4; - } - }; + public static final EntryType INT =new EntryType ((byte)4, "INT"); + + private static final EntryType[] all = new EntryType[] { + MOFID, STREAMABLE, STRING, INT }; /** Returns list of all EntryTypes. * @return Collection view of all available EntryTypes. */ public static java.util.Collection getEntryTypes () { - java.util.ArrayList al = new java.util.ArrayList(); - al.add(MOFID); - al.add(STREAMABLE); - al.add(STRING); - al.add (INT); - return al; + return Collections.unmodifiableCollection(Arrays.asList(all)); } public static Storage.EntryType decodeEntryType (String name) { @@ -88,15 +70,8 @@ return null; } - public byte encode() { - return 0; - } - public static Storage.EntryType decodeEntryType (byte code) { - for (java.util.Iterator it = Storage.EntryType.getEntryTypes().iterator(); it.hasNext();){ - Storage.EntryType et = (Storage.EntryType) it.next(); - if (code == et.encode()) return et; - } + if (code > 0 && code <= 4) return all[code-1]; return null; } }