1.1 --- a/mdr/src/org/netbeans/mdr/persistence/Storage.java Wed Aug 18 12:22:30 2004 +0000
1.2 +++ b/mdr/src/org/netbeans/mdr/persistence/Storage.java Mon Aug 23 08:51:22 2004 +0000
1.3 @@ -12,6 +12,9 @@
1.4 */
1.5 package org.netbeans.mdr.persistence;
1.6
1.7 +import java.util.Collections;
1.8 +import java.util.Arrays;
1.9 +
1.10 /** Set of indexes (Singlevalued and Multivalued) that are all updated
1.11 * in a single transaction. Every index holds keys and every key in the index
1.12 * is connected with a value or an ordered/unordered values.
1.13 @@ -23,81 +26,59 @@
1.14 public interface Storage {
1.15 /** Type of values and keys stored in index.
1.16 */
1.17 - public static class EntryType {
1.18 -
1.19 + public static final class EntryType {
1.20 /** Values are fixed length alphanumeric strings */
1.21 - public static EntryType MOFID =new EntryType () {
1.22 - public String toString() {
1.23 - return "MOFID";
1.24 - }
1.25 - public byte encode() {
1.26 - return 1;
1.27 - }
1.28 - };
1.29 + public static final EntryType MOFID = new EntryType ((byte) 1, "MOFID");
1.30
1.31 /** Values are objects that implement the Streamable interface.
1.32 * This type of values may not be used by user to create a new index,
1.33 * it is used only in the primary index created by the Storage.
1.34 */
1.35 - public static EntryType STREAMABLE =new EntryType () {
1.36 - public String toString() {
1.37 - return "STREAMABLE";
1.38 - }
1.39 - public byte encode() {
1.40 - return 2;
1.41 - }
1.42 - };
1.43 + public static final EntryType STREAMABLE =new EntryType ((byte) 2, "STREAMABLE");
1.44
1.45 /** Values are variable length Strings. */
1.46 - public static EntryType STRING =new EntryType () {
1.47 - public String toString() {
1.48 - return "STRING";
1.49 - }
1.50 - public byte encode() {
1.51 - return 3;
1.52 - }
1.53 - };
1.54 + public static final EntryType STRING =new EntryType ((byte) 3, "STRING");
1.55
1.56 /** Values are integers. */
1.57 - public static EntryType INT =new EntryType () {
1.58 - public String toString() {
1.59 - return "INT";
1.60 - }
1.61 - public byte encode() {
1.62 - return 4;
1.63 - }
1.64 - };
1.65 + public static final EntryType INT =new EntryType ((byte) 4, "INT");
1.66
1.67 + private static final EntryType[] all = new EntryType[] {MOFID, STREAMABLE, STRING, INT};
1.68 +
1.69 + private final byte id;
1.70 + private final String textId;
1.71 +
1.72 + private EntryType(byte id, String textId) {
1.73 + this.id = id;
1.74 + this.textId = textId;
1.75 + }
1.76 +
1.77 /** Returns list of all EntryTypes.
1.78 * @return Collection view of all available EntryTypes.
1.79 */
1.80 public static java.util.Collection getEntryTypes () {
1.81 - java.util.ArrayList al = new java.util.ArrayList();
1.82 - al.add(MOFID);
1.83 - al.add(STREAMABLE);
1.84 - al.add(STRING);
1.85 - al.add (INT);
1.86 - return al;
1.87 + return Collections.unmodifiableCollection(Arrays.asList(all));
1.88 }
1.89
1.90 public static Storage.EntryType decodeEntryType (String name) {
1.91 - for (java.util.Iterator it = Storage.EntryType.getEntryTypes().iterator(); it.hasNext();){
1.92 - Storage.EntryType et = (Storage.EntryType) it.next();
1.93 - if (name.equals(et.toString())) return et;
1.94 + for (int i = 0; i < all.length; i++){
1.95 + if (all[i].textId.equals(name)) {
1.96 + return all[i];
1.97 + }
1.98 }
1.99 return null;
1.100 }
1.101
1.102 + public static Storage.EntryType decodeEntryType (byte code) {
1.103 + if (code > 0 && code <= 4) return all[code-1];
1.104 + return null;
1.105 + }
1.106 +
1.107 + public String toString() {
1.108 + return textId;
1.109 + }
1.110 +
1.111 public byte encode() {
1.112 - return 0;
1.113 - }
1.114 -
1.115 - public static Storage.EntryType decodeEntryType (byte code) {
1.116 - for (java.util.Iterator it = Storage.EntryType.getEntryTypes().iterator(); it.hasNext();){
1.117 - Storage.EntryType et = (Storage.EntryType) it.next();
1.118 - if (code == et.encode()) return et;
1.119 - }
1.120 - return null;
1.121 + return id;
1.122 }
1.123 }
1.124