KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > mdr > persistence > btreeimpl > btreeindex > EntryTypeInfo


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.mdr.persistence.btreeimpl.btreeindex;
20
21 import java.io.*;
22 import org.netbeans.mdr.persistence.*;
23
24 /**
25  * Encapsulates the behavior of an entry of a given type.
26  *
27  * @author Dana Bergen
28  * @version 1.0
29  */

30 public abstract class EntryTypeInfo extends Object JavaDoc {
31
32     static final byte EQUAL = 0;
33     static final byte GREATER = 1;
34     static final byte LESS = -1;
35
36     /**
37      * Returns an IntInfo, MOFIDInfo, or StringInfo.
38      *
39      * @param type type to return Info object for
40      *
41      * @return a new IntInfo, MOFIDInfo, or StringInfo
42      */

43     public static EntryTypeInfo getEntryTypeInfo(
44         Storage.EntryType type, Storage storage) {
45
46         if (type == Storage.EntryType.INT) {
47         return new IntInfo();
48     } else if (type == Storage.EntryType.MOFID) {
49         return new MOFIDInfo(storage);
50     } else if (type == Storage.EntryType.STRING) {
51         return new StringInfo();
52     } else {
53         return null;
54     }
55     }
56     
57     /**
58      * Store the value of the object in a byte array.
59      * @param object
60      * @return newly allocated byte array
61      */

62     public abstract byte[] toBuffer(Object JavaDoc object);
63     /**
64      * Create an object from the contents of the byte array.
65      * @param buffer
66      * @return new object
67      */

68     public abstract Object JavaDoc fromBuffer(byte[] buffer);
69     /**
70      * Like fromBuffer, except that if this type is a key, returns object
71      * associated with the key
72      * @param buffer
73      * @return new object
74      */

75     public Object JavaDoc objectFromBuffer(byte[] buffer, SinglevaluedIndex repos) {
76         return fromBuffer(buffer);
77     }
78     
79     /**
80      * Compare two items of this type which are stored in byte arrays.
81      *
82      * @param key
83      * @param key2
84      * @param offset offset into key2 of target key
85      * @param length length in key2 of target key
86      *
87      * @return Returns one of:
88      * <p>EQUAL if the two keys are equal
89      * <p>GREATER if key greater than key2
90      * <p>LESS if key less than key2
91      */

92     public abstract byte compare(byte[] key, byte[] key2, int offset, int length);
93     /**
94      * Returns the length of an item of this type, or 0 if variable length.
95      */

96     public abstract int getLength();
97     /**
98      * Returns true if this is a fixed length type, otherwise returns false;
99      */

100     public abstract boolean isFixedLength();
101     /**
102      * Returns the name of this type as a String.
103      */

104     public abstract String JavaDoc typeName();
105
106 }
107
Popular Tags