How to execute class method in a Java program? [closed] - java

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 10 months ago.
Improve this question
In this code, we have to add a method set() which will take two parameters, an int index, and an Integer value, which will set the array element at the specified index to the specified value and the array will grow if an attempt is made to set a value beyond the end of the array by using the method resize().
This is the code I currently have:
public class MyVector {
protected Integer[] internalArray;
public MyVector( int initialSize )
{
internalArray = new Integer[initialSize];
}
public void resize( int newSize )
{
if ( newSize != internalArray.length ) {
Integer[] newArray = new Integer[newSize];
for (int i=0; i < Math.min(newSize,internalArray.length); i++)
newArray[i] = internalArray[i];
internalArray = newArray;
}
}
public Integer get( int index )
{
if ( index < internalArray.length )
return internalArray[index];
return null;
}
public static void main(String[] args)
{
MyVector vec = new MyVector(5);
for ( int i = 0 ; i < 20 ; i++ )
vec.set(i, i*i );
for ( int i = 0 ; i < 20 ; i++ )
System.out.println( "Element" + i + "=" + vec.get(i) );
}
}
This is the current set()-method I have made. I am not quite sure how to use or execute the set() method. How should I proceed?
public int set(int a, int b){
a = b;
if (b>19){
resize(b);
}
return a;
}

Welcome to stackoverflow! I have a feeling this is a homework question, if it is - please try to do your homework on your own since it will greatly assist you in the future.
As you can see in the code you have provided there is currently no function set() for your MyVector class.
In order to make a set() function you have to declare it. This w3schools guide will most likely explain the basics for you: https://www.w3schools.com/java/java_encapsulation.asp
For your code that could be:
public void set(int index, int value) {}
Assuming you don't want a return value from the function.
Then you can just change the value of the array to what you want it to be:
public void set( int index, int value ) {
internalArray[index] = value;
}
More information if you are interested:
What is an interesting point is that many people discuss the reasoning behind why we in OOP should need a use for setters and getters. In your example it seems like you only want your list to be of size = initialSize which you set to 5. What if someone inputs an index higher than 5? What if they input 10 instead? What will your list look like? If you want to limit those things you can in your set() function add limits to the values and indexes acceptable (which from an OOP standpoint) might be a better idea.
As I tried to explain there might be occasions where you would want to handle events when the index goes beyond. This is an example of what set() can look like if you want to increase the array size if the index is out of bounds. I really suggest you look into array and deep copying though.
public void set( int index, int value ) {
if (index > internalArray.length - 1) {
Integer[] newInternalArray = new Integer[internalArray.length + 1];
for(int i = 0; i < internalArray.length; i++) {
newInternalArray[i] = internalArray[i];
}
newInternalArray[newInternalArray.length-1] = value;
internalArray = newInternalArray;
} else {
internalArray[index] = value;
}
}
Or by using the resize() function:
public void set( int index, int value ) {
if (index > internalArray.length -1) {
resize(index + 1);
}
internalArray[index] = value;
}
With this solution you may consider to make the resize() private unless you want others to call it publicly. This is what can be so interesting and what I tried to tell you. By making it private and using it in the set-method you allow for setting values but you are in charge of how the values are changed.

Your vector class contains an internal array. There you have to modify the value at the given position. If the given position is outside of the array then you can use the resize method to enlarge the internal array:
public class MyVector {
protected Integer[] internalArray;
public MyVector( int initialSize )
{
internalArray = new Integer[initialSize];
}
public void resize( int newSize )
{
if ( newSize != internalArray.length ) {
Integer[] newArray = new Integer[newSize];
for (int i=0; i < Math.min(newSize, internalArray.length); i++)
newArray[i] = internalArray[i];
internalArray = newArray;
}
}
public Integer get( int index )
{
if ( index < internalArray.length )
return internalArray[index];
return null;
}
public void set( int index, int value )
{
if (index > internalArray.length -1) {
resize(index + 1);
}
internalArray[index] = value;
}
public static void main(String[] args)
{
MyVector vec = new MyVector(5);
for ( int i = 0 ; i < 20 ; i++ )
vec.set(i, i*i );
for ( int i = 0 ; i < 20 ; i++ )
System.out.println( "Element" + i + "=" + vec.get(i) );
}
}
$ java MyVector.java
Element0=0
Element1=1
Element2=4
Element3=9
Element4=16
...
Element17=289
Element18=324
Element19=361

Related

Sort object in ArrayList using Quick Sort without Comparable

I am trying to sort an object within an ArrayList in descending order using Quick Sort. I don't want to use the Comparable interface that java provides for classes. In the object, there is an average method, in the Team class, that I'd like to use to sort the objects by.
Below I have a Bubble Sort algorithm that I implemented within the main method, and it ended up working fine. The reason that I've gotten this to work rather than the Quick Sort is that it requires methods like partition and sort, for example. The primary issue that I am having is accessing the methods that I need from the Team class into the BubbleSort class. I have tried BubbleSort extends Team, but then the issue that I run into is it requires me to feed arguments to the BubbleSort class that originated from the Team class. Is there a way around me supplying those arguments in? What other approaches can I take?
for (int i = 0; i < team.size() - 1; i++) {
for (int j = 0; j < team.size() - i - 1; j++) {
if (team.get(j).getAverage() < team.get(j + 1).getAverage()) {
Team temp = team.get(j);
team.set(j, team.get(j + 1));
team.set(j + 1, temp);
}
}
}
Here is a repl.it of the program thus far.
You can use Comparator for custom sorting which is what you want by comparing getAverage() methods
Check out this QuickSort implementation: https://pdfbox.apache.org/docs/1.8.13/javadocs/org/apache/pdfbox/util/QuickSort.html
It takes list and Comparator as parameters for sorting. You could just use that.
QuickSort.sort(team, (t1, t2) -> Double.compare(t1.getAverage(), t2.getAverage());
I think this is the logic you are looking for, go through the code , have commented what you need to modify!! note that it sorts item in ascending order!!
public class QuickSort
{
int[] nums = null; //this should be the arrayList of Team class in your case, say ArrayList<Team>() teams = null;
/*this piece of code can be any where in your project, just placed it here in main function so that you could easily compile and run it*/
public static void main(String[] args)
{
int[] nums = {1,5,9,2,7,8,4,2,5,8,9,12,35,21,34,22,1,45};
QuickSort qs = new QuickSort(nums);
qs.quickSort(0,nums.length-1);
qs.print();
}
QuickSort(int[] nums)//this should be the arrayList of Team class in your case, say ArrayList<Team>() teams
{
this.nums = nums;
}
/**
* left and right are indices in array whereas
* pivot is one of the values stored in array; in your case,it should be averageValue of Team stored in the arrayList
* also, nums[leftIndex],nums[rightIndex],nums[right] should be replaced by
* teams.get(leftIndex).getAverage(),teams.get(rightIndex).getAverage(),teams.get(right).getAverage!!
*/
int partition(int left, int right , int pivot)
{
int leftIndex = left -1;
int rightIndex = right;
int temp = 0;
while(true)
{
while( nums[++leftIndex] < pivot );
while( rightIndex>0 && nums[--rightIndex] > pivot );
if( leftIndex >= rightIndex ) break;
else//swap value at leftIndex and rightIndex
{
temp = nums[leftIndex];
nums[leftIndex]= nums[rightIndex];
nums[rightIndex] = temp;
}
}
//swap value at leftIndex and initial right index
temp = nums[leftIndex];
nums[leftIndex]= nums[right];
nums[right] = temp;
return leftIndex;
}
void quickSort( int leftIndex , int rightIndex)
{
if( rightIndex-leftIndex <= 0 ) return;
else
{
int pivot = nums[rightIndex];
int partitionIndex = partition(leftIndex, rightIndex , pivot);
quickSort(leftIndex,partitionIndex-1);
quickSort(partitionIndex+1,rightIndex);
}
}
void print()
{
for( int i = 0 ; i < nums.length ; i++ )
{
System.out.print(nums[i]+", ");
}
}
}

How to merge two sorted arrays in Java?

I'm trying to create a third sorted array, c, from the two previously created arrays, a and b; however, I'm getting several errors within the merge method that say "The type of the expression must be an array type but it resolved to OrdArray". I've been at it for hours already, and feel like my brain is mush now. Can someone help me out?
class OrdArray
{
private long[] a; // ref to array a
private int nElems; // number of data items
//-----------------------------------------------------------
public OrdArray(int max) // constructor
{
a = new long[max]; // create array a
nElems = 0;
}
//-----------------------------------------------------------
public int size()
{ return nElems; }
//-----------------------------------------------------------
public int find(long searchKey)
{
int lowerBound = 0;
int upperBound = nElems-1;
int curIn;
while (true)
{
curIn = (lowerBound + upperBound ) / 2;
if (a[curIn] == searchKey)
return curIn; // found it
else if (lowerBound > upperBound)
return nElems; // can't find it
else // divide range
{
if (a[curIn] < searchKey)
lowerBound = curIn + 1; // it's in upper half
else
upperBound = curIn - 1; // it's in lower half
} // end else divide range
} // end while
} // end find()
//-----------------------------------------------------------
public void insert(long value) // put element into array
{
int j;
for (j = 0; j < nElems; j++) // find where it goes
if (a[j] > value) // (linear search)
break;
for (int k = nElems; k > j; k--) // move bigger ones up
a[k] = a[k-1];
a[j] = value; // insert it
nElems++; // increment size
} // end insert()
//-----------------------------------------------------------
public boolean delete(long value)
{
int j = find(value);
if (j == nElems) // can't find it
return false;
else // found it
{
for (int k = j; k < nElems; k++) // move bigger ones down
a[k] = a[k+1];
nElems--; // decrement size
return true;
}
} // end delete()
//-----------------------------------------------------------
public void display() // displays array contents
{
for (int j = 0; j < nElems; j++) // for each element,
System.out.print(a[j] + " "); // display it
System.out.println("");
}
//-----------------------------------------------------------
public static long[] merge(OrdArray a, OrdArray b)
{
long[] c = new long[a.nElems + b.nElems];
int i = 0, j = 0, k = 0;
while (i < a.nElems && j < b.nElems)
{
if (a.data[i] < b.data[j])
c[k++] = a.data[i++];
else
c[k++] = b.data[j++];
}
while (i < a.nElems)
c[k++] = a.data[i++];
while (j < b.nElems)
c[k++] = b.data[j++];
return c;
}
} // end class OrdArray
////////////////////////////////////////////////////////////////
class OrderedApp
{
public static void main(String[] args)
{
int maxSize = 100; // array size
OrdArray a, b, c; // reference to array
a = new OrdArray(maxSize); // create the array
b = new OrdArray(maxSize);
c = new OrdArray(maxSize);
a.insert(11);
a.insert(13);
a.insert(15);
a.insert(17);
a.insert(19);
a.insert(21);
a.insert(23);
a.insert(25);
a.insert(27);
a.insert(29);
b.insert(12);
b.insert(14);
b.insert(16);
b.insert(18);
b.insert(20);
b.insert(32);
b.insert(24);
b.insert(26);
b.insert(28);
b.insert(30);
OrdArray.merge(a,b);
System.out.print("Array a: ");
a.display();
System.out.println();
System.out.print("Array b: ");
b.display();
System.out.println();
System.out.print("Array c: ");
c.display();
System.out.println();
} // end main()
}// end class OrderedApp
OrdArray is not an array type (despite the name); therefore, you can't index it like an array. This expression
a[i++]
where a is an OrdArray, will have no meaning. Java doesn't give you a way to define your own [] operator for classes (unlike C++). Therefore, you'll have to add a method to OrdArray to return the element at a given index, something like
public long get(int index) { ...write the code... }
a.get(i++) // will then get the element at that index
Although I'm not sure this is what you want, since you've declared c to be an int[] and the array in OrdArray to be a long[], so I'm not sure what you're trying to do.
EDIT: After reading your comment, I realized that the merge method is inside the OrdArray class. I missed that before. Since that's the case, you don't need to add a get method; you can access the private fields of your OrdArray parameters directly. In your method:
public void merge(OrdArray a, OrdArray b)
you want to get at the private array a that you declare for each OrdArray. If you just use a, the variable will refer to the OrdArray, which isn't an array (as described above); to get at the long[] a belonging to the OrdArray a, you need to say
a.a[i++]
and likewise, for b,
b.a[i++]
This can look confusing to a reader, so I suggest coming up with a better name so that you're not calling two things a. Perhaps data?
A couple other things: You use merge like this: c.merge(a,b), which means that merge is an instance method and c is the instance you're operating on. But your method doesn't do anything with the current instance. (The c you declare in merge is a local variable that has nothing to do with the c you use when calling merge.) Right now, your method is going to a lot of trouble to construct the local array c, but then it just throws it away. You either need to (1) fix the method so that it sets up the a (or data) array in the current instance; or (2) make it a static method and make the method return the new array as a function result. I'm not sure which one your instructor wants you to do.
I'm not exactly sure what you are trying to do. But to resolve error, i have corrected the articular block.
To note, OrdArray class is not an array. It's a class that has a long[] a. So you need to get the array like any other property from the object.
For betterment, please change the method signature like this:
public void merge(OrdArray ordArr1, OrdArray ordArr2) {//Note parameters' name change
.
.
.
while (i < ordArr1.nElems && j < ordArr2.nElems)
{
if (ordArr1.a[i] < ordArr2.a[j]) //should resolve
c[k++] = ordArr1.a[i++];
else
c[k++] = ordArr2.a[j++];
}
while (i < a.nElems)
c[k++] = ordArr1.a[i++];
while (j < b.nElems)
c[k++] = ordArr2.a[j++];
}
If you accept solution wit Lists it would be:
List<Integer> result = new ArrayList<Integer>(Arrays.asList(sourceArray));
result.addAll(Arrays.asList(secondSourceArray));
Collections.sort(result);
You can optionally convert it back to array with
result.toArray();
I am confused why you are using binary search. Simple way is to insert two arrays using two insert methods or one. Using a merge method, just merge those two already sorted arrays by comparing the least element among two sorted arrays.
Remove delete, search etc methods, they are not required.
This is my code. I have inserted two integer arrays(elements) into inserta() and insertb() sorted them and merged them using insert() method. Finally I have this sorted array after merging them. Please see my code here:
package sample;
/**
*
* #author Shivasai
*/
public class Merge {
int i;
int j;
int k;
int n;
int m;
int p;
private long[] a;
private long[] b;
private long[] c;
public Merge()
{
a=new long[10];
b=new long[10];
c=new long[100];
n=0;
m=0;
p=0;
}
void inserta(long key)
{
for(i=0;i<n;i++)
{
if(a[i]>key)
break;
}
for(j=n;j>i;j--)
{
a[j]=a[j-1];
}
a[j]=key;
n++;
}
void insertb(long value)
{
for(i=0;i<m;i++)
{
if(b[i]>value)
break;
}
for(j=m;j>i;j--)
{
b[j]=b[j-1];
}
b[j]=value;
m++;
}
void insert()
{
i=0;
j=0;
while(i>n || j<m)
{
if(a[j]<b[i])
{
c[p]=a[j];
j++;
p++;
}
else
{
c[p]=b[i];
i++;
p++;
}
}
}
void displaya()
{
for(k=0;k<10;k++)
{
System.out.print("," +a[k]);
}
System.out.println();
}
void displayb()
{
for(k=0;k<10;k++)
{
System.out.print("," +b[k]);
}
System.out.println();
}
void displayc()
{
for(k=0;k<20;k++)
{
System.out.print("," +c[k]);
}
}
public static void main(String[] args)
{
Merge obj = new Merge();
obj.inserta(25);
obj.inserta(12);
obj.inserta(1800);
obj.inserta(9);
obj.inserta(10);
obj.inserta(15);
obj.inserta(18);
obj.inserta(19);
obj.inserta(0);
obj.inserta(1500);
obj.insertb(36);
obj.displaya();
obj.insertb(2);
obj.insertb(3);
obj.insertb(2000);
obj.insertb(5);
obj.insertb(6);
obj.insertb(7);
obj.insertb(8);
obj.insertb(21);
obj.insertb(85);
obj.displayb();
obj.insert();
obj.displayc();
}
}

toString method with adjustable Array size

Every source I've looked at I either don't understand, doesn't seem to apply, or uses something like an Array list. I'm not familiar with those. So I'd like to use a basic toString method that prints out the index of the array as well as the number held when compared to the variable 'length' -- num.length could be different as that's the physical size of the underlying array. The for loop at the bottom has the gist of it. I'm trying to print out the index (0-infinite) with int's that are held in the resizeable array. The variable 'length' is not the actual size of the array but a working size that contains 0 until another cell is added. The 'strang' variable is just something I've tried. I don't think it will work, but anything else I doesn't seem to help as I'm stuck.
public class XArray
{
private int[] nums;
private int length;
public XArray()
{
nums = new int[10];
length = 0;
}
public void add(int value)
{
if (length == nums.length)
{
int[] nums2 = new int[(int)(nums.length * 1.2)];
for ( int i = length - 1; i >= 0; i-- )
{
nums2[i] = nums[i];
}
nums = nums2;
}
nums[length] = value;
length++;
}
public void set(int index, int value)
{
if (index < length)
{
nums[index] = value;
}
}
public int get(int index)
{
return nums[index];
}
public int size()
{
return length;
}
public void remove()
{
nums[length - 1] = 0;
length--;
}
public String toString(int[] nums)
{
String strang = "l";
for ( int i = 0 ; i < length; i++ )
{
strang = "Index: " + i + " Number: " + nums[i] + ", ";
}
return strang;
}
}
You need to concatenate the values on each iteration of the loop...something like...
public String toString(int[] nums)
{
StringBuilder strang = new StringBuilder(length);
for ( int i = 0 ; i < length; i++ )
{
strang.append("Index: ").append(i).append(" Number: ").append(nums[i]).append(", ");
}
return strang.toString();
}
Generally speaking, toString should't take parameters, there would a difference between nums and length which could cause issues
#Override
public String toString() {...
This way, you will be printing the contents of the objects num array, which is contextually associated with length
You probably meant to use += instead of = in that method (though many people will tell you to use a StringBuilder because successive concatenations, if not optimized by a compiler` will generate a lot of garbage).
Also, don't pass in nums! You want to use the field nums; passing in an argument will use the argument. The real toString has no parameters (and should have an #Override annotation).

Converting pseudocode for array minimum into Java code, using recursion

I am blanking on this exam review question, can anyone help me get started? In findMinPos, I am confused by the three parameters, how do I access the nodes in data array? Can I use a loop even though it's a recursive method?
public class ArraySwapMin
{
public static void swapMin( int[] data, int cur )
{
int min = findMinPos( data, cur, cur );
/////////////////////////////////////////////////////////////
// swap the min position value with the one in the cur position
////////////////////////////////////////////////////////////////
}
/**
* Check the nodes in "data" from position "start" to the end of the array.
* to see if any value in this part of the array is less than the min
* value found so far (up to the "cur" position).
*/
private static int findMinPos( int[] data, int cur, int minPosSoFar )
{
//////////////////////////////////////////////////////////////
// Compare this entry's value (if it is a valid entry) with the
// value in the entry "minPosSoFar". If this value is less, then
// this entry is now the "minPosSoFar".
// Recurse for the rest of the array.
///////////////////////////////////////////////////////////////
return minPosSoFar;
}
/**
* unit tester
*/
public static void main( String[] args )
{
int[] data = { 12, 3, 10, 5, 1, 8 };
int count = 0;
System.out.println( "++++++++++++++++ ArraySwapMin ++++++++++++++++" );
printArray( "starting array ", data );
for ( int i = 0; i < data.length - 1; i++ )
{
swapMin( data, i );
printArray( "swap Min with " + i, data );
}
}
public static void printArray( String label, int[] data )
{
System.out.print( label + ": [ " );
for ( int i = 0; i < data.length - 1; i++ )
System.out.print( data[ i ] + ", " );
System.out.println( data[ data.length - 1 ] + " ]" );
}
}
In swapMin() you have to switch the current position with the one with the minimum.
public static void swapMin( int[] data, int cur )
{
int min = findMinPos( data, cur, cur );
int minValue = data[min];
data[min] = data[cur];
data[cur] = minValue;
}
The minimum will recursively determined in findMinPos(). The whole idea of recurseiv programming is to use the returnvalues of an inner method call instead of using a loop. What you need is an overall break condition (in your case the length of the array) and usually multiple return statements.
This one here will do the trick:
private static int findMinPos( int[] data, int cur, int minPosSoFar )
{
if(cur < data.length)
{
if(data[cur] < data[minPosSoFar]) // set new minimum to position cur
{
return findMinPos(data, cur + 1, cur);
}
else // keep old minimum
{
return findMinPos(data, cur + 1, minPosSoFar);
}
}
return minPosSoFar;
}
And since the multiple return statements in the if-else block makes the code long and messy you can shorten it like this
private static int findMinPos( int[] data, int cur, int minPosSoFar )
{
if(cur < data.length)
{
return (data[cur] < data[minPosSoFar]) ?
findMinPos(data, cur + 1, cur) :
findMinPos(data, cur + 1, minPosSoFar);
}
return minPosSoFar;
}
They have given you pseudocode. Just do exactly what it says. First change the instructions to step by step.
Compare this entry's value (if it is a valid entry) with the value in the entry "minPosSoFar".
If this value is less, then this entry is now the "minPosSoFar".
Recurse for the rest of the array.
So:
private static int findMinPos( int[] data, int cur, int minPosSoFar )
{
if (cur < data.length) { // Needed for stopping at the end of the array
if (data[cur] < data[minPosSoFar]) { // 1.
minPosSoFar = cur; // 2.
}
return findMinPos(data, cur+1, minPosSoFar); // 3.
}
return minPosSoFar;
}
Since this is for school, I don't want to do the whole thing for you, hopefully this will give you a good idea what to do.

Ways of encapsulating choice of Java primitive; Avoiding "magic" primitives

I'm writing a program which creates a large number of large arrays to store data. All of this data has to held in RAM, so I'm avoiding objects and currently using shorts to save space. These shorts serve as ID numbers which can be put into a lookup class to get the corresponding object on demand. I have recently questioned whether I'll need the whole 2 bytes of a short, and so I'm now wondering if there's anyway to define the data type being stored in one place in my code so that I can change it easily without having to hunt down every cast, return type, etc. that is currently set to short.
If I were willing to use objects I could easily just do
class MySmallNumber extends Short{}
and change the parent class if necessary.
If this were C/C++, i could use
#define small short
for the effect I'm looking for.
I'm searching for a way to do something like this in java that won't require storing 64-bit object references in my arrays. Any help is greatly appreciated. Right now I'm looking at a really messy IDE replace all in order to do this.
You can incapsulate you array in some custom class. It shouldn't add considerable space overhead because you work with large arrays.
In all other places in your code you can use long. When you pass these longs to you array custom class you can convert it to the one you use inside it.
Finally you have to make changes in this one class only.
I would suggest factoring out all code that depends on the type of your ID values into a separate class. Let that class handle all the operations (including lookup) that depend on whether the ID values are short, byte, or something else. You can pass individual values in and out as short or even int values, even if internally they are converted to byte. (This is, for instance, how java.io.DataOutputStream.writeByte(int) was written—it takes an int argument and treats it as a byte value.)
not quite sure what you are after here, but this may be of interest:
import java.util.Arrays;
interface Index {
short getIndex(int i);
void setIndex(int i, short value);
int size();
}
class ShortIndexImpl implements Index {
ShortIndexImpl(int n) {
indices = new short[n];
}
#Override public short getIndex(int i) {
return indices[i];
}
#Override public void setIndex(int i, short value) {
indices[i] = value;
}
#Override public int size() {
return indices.length;
}
final short[] indices;
}
class TenBitIndexImpl implements Index {
TenBitIndexImpl(int n) {
indices = new int[(n + 2) / 3];
}
#Override public short getIndex(int i) {
int index = i / 3;
int remainder = i % 3;
int word = indices[index];
return (short) (0x3ff & (word >> shifts[remainder]));
}
#Override public void setIndex(int i, short value) {
int index = i / 3;
int remainder = i % 3;
int word = indices[index] & ~masks[remainder];
int shiftedValue = ((int) value) << shifts[remainder];
word |= shiftedValue;
indices[index] = word;
}
#Override public int size() {
return indices.length;
}
final int masks[] = new int[] { 0x3ff00000, 0xffc00, 0x3ff };
final int shifts[] = new int[] { 20, 10, 0 };
final int[] indices;
}
public class Main {
static void test(Index index) {
for (int i = 0; i < values.length; i++)
index.setIndex(i, values[i]);
for (int i = 0; i < values.length; i++) {
System.out.println(values[i] + " " + index.getIndex(i));
if (index.getIndex(i) != values[i])
System.out.println("expected " + values[i] + " but got " + index.getIndex(i));
}
}
public static void main(String[] args) {
Index index = new ShortIndexImpl(values.length);
test(index);
index = new TenBitIndexImpl(values.length);
test(index);
System.out.println("indices");
for (int i = 0; i < ((TenBitIndexImpl) index).indices.length; i++)
System.out.println(((TenBitIndexImpl) index).indices[i]);
}
static short[] values = new short[] { 1, 2, 3, 4, 5, 6 };
}

Categories