com.partnersoft.data
Class DataBuffer

java.lang.Object
  extended by com.partnersoft.data.DataBuffer
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
ByteBuffer, CharBuffer, DoubleBuffer, FloatBuffer, IntBuffer, LongBuffer, ObjectBuffer, PolylineArray, ShortBuffer, StringDataBuffer, StringTable

public abstract class DataBuffer
extends java.lang.Object
implements java.io.Serializable

Abstract superclass for fast, unsafe arrays or buffers of things that need to grow.

Author:
Paul Reavis Copyright 2002 Partner Software, Inc.
See Also:
Serialized Form

Field Summary
 java.lang.Object arrayObject
           
 int capacity
           
 int end
           
 int growthCap
           
 int growthMin
           
 int start
          Extents of valid data.
 
Constructor Summary
DataBuffer()
           
DataBuffer(int size)
          Creates a char buffer of the given size.
 
Method Summary
 void append(DataBuffer nother)
           
 void clear()
           
 java.lang.Object clone()
           
 void copy(int oldIndex, int newIndex, int size)
          Copies range of contents to new spot in array.
 void copyTo(java.lang.Object notherArray)
           
 int getSize()
           
 void insert(int whereAt)
          Inserts a slot in the array, copying contents up one.
 boolean isEmpty()
           
 void makeRoomFor(int roomNeeded)
          This method ensures that there is enough space in the array to fill with the given number of items.
 void makeRoomFor(int roomNeeded, int minimumIncrease)
          Same as shorter makeRoomFor, except that it will increase the capacity at least as much as the given minimum - this prevents constant microgrowage.
abstract  void newArray(int size)
          Allocates a new, empty array of the given size and assign it to the arrayObject property.
 void pack()
           
 void remove(int whereAt)
           
 void setToMatch(DataBuffer nother)
           
 DataBuffer subsection(int sectionStart, int sectionEnd)
          Returns a subsection of the array.
 void tidy()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

start

public int start
Extents of valid data. Valid data is in range [start, end], inclusive. Capacity is size of actual array. The actual array, since it may consist of primitives, is subclass dependent.


end

public int end

capacity

public int capacity

arrayObject

public java.lang.Object arrayObject

growthMin

public int growthMin

growthCap

public int growthCap
Constructor Detail

DataBuffer

public DataBuffer()

DataBuffer

public DataBuffer(int size)
Creates a char buffer of the given size.

Method Detail

newArray

public abstract void newArray(int size)
Allocates a new, empty array of the given size and assign it to the arrayObject property. It is assumed that subclasses will also set it to a variable of the correct class (e.g. char[]) for ease of access as well. Copying of existing contents is managed by this superclass.


makeRoomFor

public void makeRoomFor(int roomNeeded)
This method ensures that there is enough space in the array to fill with the given number of items. The current contents are preserved, though they are moved to the beginning of the buffer if necessary. If there is already enough room (capacity - end - 1 > roomNeeded) nothing is done. Otherwise, it tries to make enough room by moving the contents to the beginning and enlarging the buffer if necessary.


makeRoomFor

public void makeRoomFor(int roomNeeded,
                        int minimumIncrease)
Same as shorter makeRoomFor, except that it will increase the capacity at least as much as the given minimum - this prevents constant microgrowage.


pack

public void pack()

tidy

public void tidy()

clear

public void clear()

getSize

public int getSize()

isEmpty

public boolean isEmpty()

copy

public void copy(int oldIndex,
                 int newIndex,
                 int size)
Copies range of contents to new spot in array. Increases capacity if needed but does not change start or end.


insert

public void insert(int whereAt)
Inserts a slot in the array, copying contents up one. Increments end but does not blank out slot.


remove

public void remove(int whereAt)

subsection

public DataBuffer subsection(int sectionStart,
                             int sectionEnd)
Returns a subsection of the array. Start and end indices are as counted from this.start, not absolute.


setToMatch

public void setToMatch(DataBuffer nother)

append

public void append(DataBuffer nother)

copyTo

public void copyTo(java.lang.Object notherArray)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object