Remove Assembly.
[SquirrelJME.git] / emulators / springcoat-vm / src / main / java / cc / squirreljme / vm / springcoat / SpringArrayObjectBoolean.java
blob0a886c3fdb4a84ef3816e91b7da294a6405e43eb
1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // SquirrelJME
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;
16 /**
17 * Array backed by a boolean array.
19 * @since 2018/11/14
21 public final class SpringArrayObjectBoolean
22 extends SpringArrayObject
24 /** Elements in the array. */
25 private final boolean[] _elements;
27 /**
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.
34 * @since 2018/11/14
36 public SpringArrayObjectBoolean(SpringClass __self, int __l)
37 throws NullPointerException
39 super(__self, __l);
41 // Initialize elements
42 this._elements = new boolean[__l];
45 /**
46 * Wraps the native array.
48 * @param __self The self type.
49 * @param __a The array to wrap.
50 * @throws NullPointerException On null arguments.
51 * @since 2018/11/18
53 public SpringArrayObjectBoolean(SpringClass __self, boolean[] __a)
54 throws NullPointerException
56 super(__self, __a.length);
58 this._elements = __a;
61 /**
62 * {@inheritDoc}
63 * @since 2018/11/19
65 @Override
66 public final boolean[] array()
68 return this._elements;
71 /**
72 * {@inheritDoc}
73 * @since 2018/11/14
75 @Override
76 public final <C> C get(Class<C> __cl, int __dx)
77 throws NullPointerException, SpringArrayIndexOutOfBoundsException
79 // Read value
80 try
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);
94 /**
95 * {@inheritDoc}
96 * @since 2018/11/14
98 @Override
99 public final void set(int __dx, Object __v)
100 throws SpringArrayStoreException, SpringArrayIndexOutOfBoundsException
102 // Try setting
105 boolean v;
106 if (__v instanceof Integer)
107 v = (((int)__v) & 0x1) != 0;
108 else
109 v = ((boolean)__v);
111 this._elements[__dx] = v;
114 // {@squirreljme.error BK03 Could not set the index in the boolean
115 // array.}
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);