1 package com.daffodilwoods.daffodildb.utils.field; 2 3 import com.daffodilwoods.daffodildb.utils.BufferRange; 4 import java.io.*; 5 import com.daffodilwoods.daffodildb.utils.GetByteComparator; 6 import com.daffodilwoods.database.resource.DException; 7 import java.text.Collator ; 8 import java.util.*; 9 10 public class FieldString extends FieldBase implements Comparable { 11 12 public FieldString(BufferRange bufferRange0,int datatype0,Collator collator0) { 13 14 bufferRange = bufferRange0; 15 datatype = datatype0; 16 collator = collator0; 17 } 18 19 20 public Object getObject() { 21 if (bufferRange.getNull()) 22 return null; 23 if (object != null) 24 return object; 25 try { 26 object = new String (bufferRange.getFulBytes(), bufferRange.getOffSet(), 27 bufferRange.getLength(), 28 collator != null ? "UTF16" : "ISO-8859-1"); 29 } 30 catch (UnsupportedEncodingException ex) { 31 return null; 32 } 33 return object; 34 } 35 36 public boolean equals(Object fieldBase){ 37 try { 38 return (getDatatype() != ((FieldBase)fieldBase).getDatatype()) ? false : 39 collator == null ? GetByteComparator.stringComparator.compare(this,fieldBase) == 0 40 : collator.compare(((FieldBase)fieldBase).getObject(),getObject()) == 0; 41 } 42 catch (DException ex) { 43 return false; 44 } 45 } 46 47 public int compareTo(Object fieldBase){ 48 try { 49 return (collator == null) ? GetByteComparator.stringComparator.compare(this,fieldBase) 50 : collator.compare(((FieldBase)fieldBase).getObject(),getObject()) ; 51 } 52 catch (DException ex) { 53 return -1; 54 } 55 } 56 57 58 public String toString() { 59 return (String )getObject() ; 60 61 } 62 63 public int getSize()throws DException{ 64 return bufferRange.getLength(); 65 } 66 67 } 68 | Popular Tags |