KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mckoi > util > IntegerListBlockInterface


1 /**
2  * com.mckoi.util.IntegerListBlockInterface 20 Sep 2001
3  *
4  * Mckoi SQL Database ( http://www.mckoi.com/database )
5  * Copyright (C) 2000, 2001, 2002 Diehl and Associates, Inc.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * Version 2 as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License Version 2 for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * Version 2 along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  *
20  * Change Log:
21  *
22  *
23  */

24
25 package com.mckoi.util;
26
27 /**
28  * A block of an AbstractBlockIntegerList. This exposes the contents of a
29  * block of the list.
30  * <p>
31  * An IntegerListBlockInterface is a single element of a block of integers
32  * that make up some complete list of integers. A block integer list
33  * encapsulates a set of integers making up the block, and a chain to the
34  * next and previous block in the set.
35  *
36  * @author Tobias Downer
37  */

38
39 public abstract class IntegerListBlockInterface {
40
41   /**
42    * The next block in the chain.
43    */

44   public IntegerListBlockInterface next;
45
46   /**
47    * The previous block in the chain.
48    */

49   public IntegerListBlockInterface previous;
50
51   /**
52    * Set to true whenever the integers of this block are changed via the
53    * mutation methods.
54    */

55   boolean has_changed;
56
57
58   /**
59    * Returns true if this store has been modified. The purpose of this
60    * method is to determine if any updates need to be made to any
61    * persistant representation of this store.
62    */

63   public final boolean hasChanged() {
64     return has_changed;
65   }
66
67   /**
68    * Returns the number of entries in this block.
69    */

70   public abstract int size();
71
72   /**
73    * Returns true if the block is full.
74    */

75   public abstract boolean isFull();
76
77   /**
78    * Returns true if the block is empty.
79    */

80   public abstract boolean isEmpty();
81
82   /**
83    * Returns true if the block has enough room to fill with the given number
84    * of integers.
85    */

86   public abstract boolean canContain(int number);
87
88   /**
89    * The top int in the list.
90    */

91   public abstract int topInt();
92
93   /**
94    * The bottom int in the list.
95    */

96   public abstract int bottomInt();
97
98   /**
99    * Returns the int at the given position in the array.
100    */

101   public abstract int intAt(int pos);
102
103   /**
104    * Adds an int to the block.
105    */

106   public abstract void addInt(int val);
107
108   /**
109    * Removes an Int from the specified position in the block.
110    */

111   public abstract int removeIntAt(int pos);
112
113   /**
114    * Inserts an int at the given position.
115    */

116   public abstract void insertIntAt(int val, int pos);
117
118   /**
119    * Sets an int at the given position, overwriting anything that was
120    * previously there. It returns the value that was previously at the
121    * element.
122    */

123   public abstract int setIntAt(int val, int pos);
124
125   /**
126    * Moves a set of values from the end of this block and inserts it into the
127    * given block at the destination index specified. Assumes the
128    * destination block has enough room to store the set. Assumes
129    * 'dest_block' is the same class as this.
130    */

131   public abstract void moveTo(IntegerListBlockInterface dest_block,
132                               int dest_index, int length);
133
134   /**
135    * Copies all the data from this block into the given destination block.
136    * Assumes 'dest_block' is the same class as this.
137    */

138   public abstract void copyTo(IntegerListBlockInterface dest_block);
139
140   /**
141    * Copies all the data from this block into the given int[] array. Returns
142    * the number of 'int' values copied.
143    */

144   public abstract int copyTo(int[] to, int offset);
145
146   /**
147    * Clears the object to be re-used.
148    */

149   public abstract void clear();
150
151   /**
152    * Performs an iterative search through the int values in the list.
153    * If it's found the index of the value is returned, else it returns
154    * -1.
155    */

156   public abstract int iterativeSearch(int val);
157
158   /**
159    * Performs an iterative search from the given position to the end of
160    * the list in the block.
161    * If it's found the index of the value is returned, else it returns
162    * -1.
163    */

164   public abstract int iterativeSearch(int val, int position);
165
166
167
168   // ---------- Sort algorithms ----------
169

170   /**
171    * Considers each int a reference to another structure, and the block
172    * sorted by these structures. The method performs a binary search.
173    */

174   public abstract int binarySearch(Object JavaDoc key, IndexComparator c);
175
176   /**
177    * Considers each int a reference to another structure, and the block
178    * sorted by these structures. Finds the first index in the block that
179    * equals the given key.
180    */

181   public abstract int searchFirst(Object JavaDoc key, IndexComparator c);
182
183   /**
184    * Considers each int a reference to another structure, and the block
185    * sorted by these structures. Finds the first index in the block that
186    * equals the given key.
187    */

188   public abstract int searchLast(Object JavaDoc key, IndexComparator c);
189
190   /**
191    * Assuming a sorted block, finds the first index in the block that
192    * equals the given value.
193    */

194   public abstract int searchFirst(int val);
195
196   /**
197    * Assuming a sorted block, finds the first index in the block that
198    * equals the given value.
199    */

200   public abstract int searchLast(int val);
201
202 }
203
Popular Tags