1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the GNU General Public License v3+, or later.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package cc
.squirreljme
.vm
.springcoat
;
12 import cc
.squirreljme
.vm
.springcoat
.exceptions
.SpringArrayIndexOutOfBoundsException
;
13 import cc
.squirreljme
.vm
.springcoat
.exceptions
.SpringArrayStoreException
;
14 import cc
.squirreljme
.vm
.springcoat
.exceptions
.SpringNegativeArraySizeException
;
17 * Array backed by a boolean array.
21 public final class SpringArrayObjectBoolean
22 extends SpringArrayObject
24 /** Elements in the array. */
25 private final boolean[] _elements
;
28 * Initializes the array.
30 * @param __self The self type.
31 * @param __l The array length.
32 * @throws NullPointerException On null arguments.
33 * @throws SpringNegativeArraySizeException If the array size is negative.
36 public SpringArrayObjectBoolean(SpringClass __self
, int __l
)
37 throws NullPointerException
41 // Initialize elements
42 this._elements
= new boolean[__l
];
46 * Wraps the native array.
48 * @param __self The self type.
49 * @param __a The array to wrap.
50 * @throws NullPointerException On null arguments.
53 public SpringArrayObjectBoolean(SpringClass __self
, boolean[] __a
)
54 throws NullPointerException
56 super(__self
, __a
.length
);
66 public final boolean[] array()
68 return this._elements
;
76 public final <C
> C
get(Class
<C
> __cl
, int __dx
)
77 throws NullPointerException
, SpringArrayIndexOutOfBoundsException
82 return (C
)Integer
.valueOf((this._elements
[__dx
] ?
1 : 0));
85 // {@squirreljme.error BK02 Out of bounds access to array. (The index;
86 // The length of the array)}
87 catch (IndexOutOfBoundsException e
)
89 throw new SpringArrayIndexOutOfBoundsException(
90 String
.format("BK02 %d %d", __dx
, this.length
), e
);
99 public final void set(int __dx
, Object __v
)
100 throws SpringArrayStoreException
, SpringArrayIndexOutOfBoundsException
106 if (__v
instanceof Integer
)
107 v
= (((int)__v
) & 0x1) != 0;
111 this._elements
[__dx
] = v
;
114 // {@squirreljme.error BK03 Could not set the index in the boolean
116 catch (ClassCastException e
)
118 throw new SpringArrayStoreException("BK03", e
);
121 // {@squirreljme.error BK04 Out of bounds access to array. (The index;
122 // The length of the array)}
123 catch (IndexOutOfBoundsException e
)
125 throw new SpringArrayIndexOutOfBoundsException(
126 String
.format("BK04 %d %d", __dx
, this.length
), e
);