Commit 6460358c authored by Stephanie Gawroriski's avatar Stephanie Gawroriski
Browse files

Add classes to represent an array of primitives as Lists; Use these wrapper...

Add classes to represent an array of primitives as Lists; Use these wrapper lists to implement sort.
parent e091dc74
// -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
// ---------------------------------------------------------------------------
// Multi-Phasic Applications: SquirrelJME
// Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
// ---------------------------------------------------------------------------
// SquirrelJME is under the GNU General Public License v3+, or later.
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------
package cc.squirreljme.runtime.cldc.util;
import java.util.AbstractList;
/**
* Provides a list view of a {@code double} array.
*
* @since 2020/01/01
*/
public class DoubleArrayList
extends AbstractList<Double>
{
/** The backing array. */
protected final double[] array;
/** The offset. */
protected final int offset;
/** The cached size. */
protected final int size;
/**
* Initializes the long array view.
*
* @param __a The array to wrap.
* @throws NullPointerException On null arguments.
* @since 2020/01/01
*/
public DoubleArrayList(double[] __a)
throws NullPointerException
{
this(__a, 0, __a.length);
}
/**
* Initializes the long array view.
*
* @param __a The array to wrap.
* @param __o The offset.
* @param __l The length.
* @throws IndexOutOfBoundsException If the offset and/or length are
* negative or exceed the array bounds.
* @throws NullPointerException On null arguments.
* @since 2020/01/01
*/
public DoubleArrayList(double[] __a, int __o, int __l)
throws IndexOutOfBoundsException, NullPointerException
{
if (__a == null)
throw new NullPointerException("NARG");
if (__o < 0 || __l < 0 || (__o + __l) > __a.length)
throw new IndexOutOfBoundsException("IOOB");
this.array = __a;
this.offset = __o;
this.size = __l;
}
/**
* {@inheritDoc}
* @since 2020/01/01
*/
@Override
public Double get(int __i)
{
if (__i < 0 || __i >= this.size)
throw new IndexOutOfBoundsException("IOOB");
return this.array[this.offset + __i];
}
/**
* Sets the value of the given index,
*
* @param __i The index to set.
* @param __v The value to set.
* @return The old value.
* @throws IndexOutOfBoundsException If the index is not within bounds.
* @since 2020/01/01
*/
public double set(int __i, double __v)
throws IndexOutOfBoundsException
{
return this.set(__i, __v);
}
/**
* {@inheritDoc}
* @since 2020/01/01
*/
@Override
public Double set(int __i, Double __v)
throws IndexOutOfBoundsException, NullPointerException
{
if (__v == null)
throw new NullPointerException("NARG");
if (__i < 0 || __i >= this.size)
throw new IndexOutOfBoundsException("IOOB");
// The true index to access
int truedx = this.offset + __i;
// Get old value
double[] array = this.array;
double rv = array[truedx];
// Set new value
array[truedx] = __v;
// Return the old value
return rv;
}
/**
* {@inheritDoc}
* @since 2020/01/01
*/
@Override
public int size()
{
return this.size;
}
}
// -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
// ---------------------------------------------------------------------------
// Multi-Phasic Applications: SquirrelJME
// Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
// ---------------------------------------------------------------------------
// SquirrelJME is under the GNU General Public License v3+, or later.
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------
package cc.squirreljme.runtime.cldc.util;
import java.util.AbstractList;
/**
* Provides a list view of a {@code float} array.
*
* @since 2020/01/01
*/
public class FloatArrayList
extends AbstractList<Float>
{
/** The backing array. */
protected final float[] array;
/** The offset. */
protected final int offset;
/** The cached size. */
protected final int size;
/**
* Initializes the long array view.
*
* @param __a The array to wrap.
* @throws NullPointerException On null arguments.
* @since 2020/01/01
*/
public FloatArrayList(float[] __a)
throws NullPointerException
{
this(__a, 0, __a.length);
}
/**
* Initializes the long array view.
*
* @param __a The array to wrap.
* @param __o The offset.
* @param __l The length.
* @throws IndexOutOfBoundsException If the offset and/or length are
* negative or exceed the array bounds.
* @throws NullPointerException On null arguments.
* @since 2020/01/01
*/
public FloatArrayList(float[] __a, int __o, int __l)
throws IndexOutOfBoundsException, NullPointerException
{
if (__a == null)
throw new NullPointerException("NARG");
if (__o < 0 || __l < 0 || (__o + __l) > __a.length)
throw new IndexOutOfBoundsException("IOOB");
this.array = __a;
this.offset = __o;
this.size = __l;
}
/**
* {@inheritDoc}
* @since 2020/01/01
*/
@Override
public Float get(int __i)
{
if (__i < 0 || __i >= this.size)
throw new IndexOutOfBoundsException("IOOB");
return this.array[this.offset + __i];
}
/**
* Sets the value of the given index,
*
* @param __i The index to set.
* @param __v The value to set.
* @return The old value.
* @throws IndexOutOfBoundsException If the index is not within bounds.
* @since 2020/01/01
*/
public float set(int __i, float __v)
throws IndexOutOfBoundsException
{
return this.set(__i, __v);
}
/**
* {@inheritDoc}
* @since 2020/01/01
*/
@Override
public Float set(int __i, Float __v)
throws IndexOutOfBoundsException, NullPointerException
{
if (__v == null)
throw new NullPointerException("NARG");
if (__i < 0 || __i >= this.size)
throw new IndexOutOfBoundsException("IOOB");
// The true index to access
int truedx = this.offset + __i;
// Get old value
float[] array = this.array;
float rv = array[truedx];
// Set new value
array[truedx] = __v;
// Return the old value
return rv;
}
/**
* {@inheritDoc}
* @since 2020/01/01
*/
@Override
public int size()
{
return this.size;
}
}
// -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
// ---------------------------------------------------------------------------
// Multi-Phasic Applications: SquirrelJME
// Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
// ---------------------------------------------------------------------------
// SquirrelJME is under the GNU General Public License v3+, or later.
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------
package cc.squirreljme.runtime.cldc.util;
import java.util.AbstractList;
/**
* Provides a list view of a {@code long} array.
*
* @since 2020/01/01
*/
public class LongArrayList
extends AbstractList<Long>
{
/** The backing array. */
protected final long[] array;
/** The offset. */
protected final int offset;
/** The cached size. */
protected final int size;
/**
* Initializes the long array view.
*
* @param __a The array to wrap.
* @throws NullPointerException On null arguments.
* @since 2020/01/01
*/
public LongArrayList(long[] __a)
throws NullPointerException
{
this(__a, 0, __a.length);
}
/**
* Initializes the long array view.
*
* @param __a The array to wrap.
* @param __o The offset.
* @param __l The length.
* @throws IndexOutOfBoundsException If the offset and/or length are
* negative or exceed the array bounds.
* @throws NullPointerException On null arguments.
* @since 2020/01/01
*/
public LongArrayList(long[] __a, int __o, int __l)
throws IndexOutOfBoundsException, NullPointerException
{
if (__a == null)
throw new NullPointerException("NARG");
if (__o < 0 || __l < 0 || (__o + __l) > __a.length)
throw new IndexOutOfBoundsException("IOOB");
this.array = __a;
this.offset = __o;
this.size = __l;
}
/**
* {@inheritDoc}
* @since 2020/01/01
*/
@Override
public Long get(int __i)
{
if (__i < 0 || __i >= this.size)
throw new IndexOutOfBoundsException("IOOB");
return this.array[this.offset + __i];
}
/**
* Sets the value of the given index,
*
* @param __i The index to set.
* @param __v The value to set.
* @return The old value.
* @throws IndexOutOfBoundsException If the index is not within bounds.
* @since 2020/01/01
*/
public long set(int __i, long __v)
throws IndexOutOfBoundsException
{
return this.set(__i, __v);
}
/**
* {@inheritDoc}
* @since 2020/01/01
*/
@Override
public Long set(int __i, Long __v)
throws IndexOutOfBoundsException, NullPointerException
{
if (__v == null)
throw new NullPointerException("NARG");
if (__i < 0 || __i >= this.size)
throw new IndexOutOfBoundsException("IOOB");
// The true index to access
int truedx = this.offset + __i;
// Get old value
long[] array = this.array;
long rv = array[truedx];
// Set new value
array[truedx] = __v;
// Return the old value
return rv;
}
/**
* {@inheritDoc}
* @since 2020/01/01
*/
@Override
public int size()
{
return this.size;
}
}
......@@ -13,9 +13,12 @@ package java.util;
import cc.squirreljme.runtime.cldc.asm.ObjectAccess;
import cc.squirreljme.runtime.cldc.util.ByteIntegerArray;
import cc.squirreljme.runtime.cldc.util.CharacterIntegerArray;
import cc.squirreljme.runtime.cldc.util.DoubleArrayList;
import cc.squirreljme.runtime.cldc.util.FloatArrayList;
import cc.squirreljme.runtime.cldc.util.IntegerArray;
import cc.squirreljme.runtime.cldc.util.IntegerArrays;
import cc.squirreljme.runtime.cldc.util.IntegerIntegerArray;
import cc.squirreljme.runtime.cldc.util.LongArrayList;
import cc.squirreljme.runtime.cldc.util.ShellSort;
import cc.squirreljme.runtime.cldc.util.ShortIntegerArray;
......@@ -925,6 +928,19 @@ public class Arrays
Arrays.sort(__a, 0, __a.length);
}
/**
* Sorts the specified array.
*
* @param __a The array to sort.
* @param __from The from index.
* @param __to The to index.
* @throws ArrayIndexOutOfBoundsException If the from or to index are
* outside of bounds.
* @throws IllegalArgumentException If the from address is greater than
* the to address.
* @throws NullPointerException If no array was specified.
* @since 2020/01/01
*/
public static void sort(long[] __a, int __from, int __to)
throws ArrayIndexOutOfBoundsException, IllegalArgumentException,
NullPointerException
......@@ -942,7 +958,8 @@ public class Arrays
if (__from == __to)
return;
throw new todo.TODO();
// Non-common sort, use a helper wrapper
ShellSort.<Long>sort(new LongArrayList(__a), __from, __to, null);
}
/**
......@@ -1076,6 +1093,19 @@ public class Arrays
sort(__a, 0, __a.length);
}
/**
* Sorts the specified array.
*
* @param __a The array to sort.
* @param __from The from index.
* @param __to The to index.
* @throws ArrayIndexOutOfBoundsException If the from or to index are
* outside of bounds.
* @throws IllegalArgumentException If the from address is greater than
* the to address.
* @throws NullPointerException If no array was specified.
* @since 2020/01/01
*/
public static void sort(float[] __a, int __from, int __to)
throws ArrayIndexOutOfBoundsException, IllegalArgumentException,
NullPointerException
......@@ -1093,7 +1123,8 @@ public class Arrays
if (__from == __to)
return;
throw new todo.TODO();
// Non-common sort, use a helper wrapper
ShellSort.<Float>sort(new FloatArrayList(__a), __from, __to, null);
}
/**
......@@ -1113,6 +1144,19 @@ public class Arrays
sort(__a, 0, __a.length);
}
/**
* Sorts the specified array.
*
* @param __a The array to sort.
* @param __from The from index.
* @param __to The to index.
* @throws ArrayIndexOutOfBoundsException If the from or to index are
* outside of bounds.
* @throws IllegalArgumentException If the from address is greater than
* the to address.
* @throws NullPointerException If no array was specified.
* @since 2020/01/01
*/
public static void sort(double[] __a, int __from, int __to)
throws ArrayIndexOutOfBoundsException, IllegalArgumentException,
NullPointerException
......@@ -1130,7 +1174,8 @@ public class Arrays
if (__from == __to)
return;
throw new todo.TODO();
// Non-common sort, use a helper wrapper
ShellSort.<Double>sort(new DoubleArrayList(__a), __from, __to, null);
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment