KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > utils > field > FieldStringLiteral


1 package com.daffodilwoods.daffodildb.utils.field;
2
3 import com.daffodilwoods.database.resource.DException;
4 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.Datatype;
5 import com.daffodilwoods.daffodildb.utils.BufferRange;
6 import com.daffodilwoods.daffodildb.utils.byteconverter.CCzufDpowfsufs;
7 import com.daffodilwoods.daffodildb.utils.FieldUtility;
8
9 public class FieldStringLiteral extends FieldBase {
10
11   private int dataSize = -1;
12
13   public FieldStringLiteral() {
14   }
15   public FieldStringLiteral(Object JavaDoc object0,int datatype0) {
16       super(object0,datatype0);
17   }
18
19   public FieldStringLiteral(BufferRange bufferRange0,int datatype0) {
20       super(bufferRange0,datatype0);
21   }
22
23   public Object JavaDoc getObject() throws DException{
24       return object;
25   }
26
27   public int getDatatype() {
28       return datatype;
29   }
30
31   public void setDatatype(int type) throws DException{
32     if (bufferRange == null)
33       setSize(-1);
34   }
35
36   public boolean equals(Object JavaDoc fieldBase){
37       try {
38           Object JavaDoc o1 = getObject();
39           Object JavaDoc o2 = ((FieldBase)fieldBase).getObject();
40           if(o1 == null && o2 == null)
41               return true;
42           return o1 != null && o2 != null ? o1.equals(o2) : false;
43       }
44       catch (DException ex) {
45           return false;
46       }
47   }
48
49   public int compareTo(Object JavaDoc fieldBase){
50     try {
51        Object JavaDoc o1 = getObject();
52        Object JavaDoc o2 = ((FieldBase)fieldBase).getObject();
53        if(o1 == null && o2 == null)
54            return 0;
55         else if(o1 == null && o2 !=null)
56           return -1;
57         else if(o1!=null && o2==null)
58           return 1;
59         else
60           return ((Comparable JavaDoc)o1).compareTo(o2);
61       }
62       catch (DException ex) {
63           return -1;
64       }
65
66    }
67
68
69   public boolean isNull() {
70       return object == null;
71   }
72
73   public boolean getNull(){
74       return object == null;
75   }
76
77   public void setSize(int size) throws DException{
78     if(object==null)
79     {
80       bufferRange = FieldUtility.NULLBUFFERRANGE;
81       return;
82     }
83     if(size != -1){
84       String JavaDoc str = (String JavaDoc) object;
85       int length = str.length();
86       if (size > length) {
87         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(str);
88         for (int i = size; i > length; i--) {
89           buffer.append(" ");
90         }
91         object = buffer.toString();
92       }
93       else if (size < length) {
94         char[] array = str.toCharArray();
95         int i;
96         for (i = size; i < length; i++) {
97           if (array[i] != ' ')
98             break;
99         }
100         object = i == length ? str.substring(0, size) : object;
101       }
102     }
103     dataSize = ((String JavaDoc)object).length();
104     bufferRange = new BufferRange(CCzufDpowfsufs.getBytes((String JavaDoc)object,-1,false));
105   }
106
107   public int getSize()throws DException{
108     return dataSize;
109   }
110
111   public String JavaDoc toString(){
112       String JavaDoc str = "FieldStringLiteral = [Object [" + object + "]";
113       str += "dataType = "+datatype+"]BufferRange = " + bufferRange + " ]";
114       return str;
115   }
116
117   public BufferRange getBufferRange() {
118     try {
119       if (bufferRange == null)
120         setSize(-1);
121     }
122     catch (DException ex) {
123     }
124     return bufferRange;
125   }
126
127   public int getLength(){
128      return getBufferRange().getLength();
129   }
130 }
131
Popular Tags