jclass
Class SyncSimpleArray
java.lang.Object
|
+--jclass.SyncSimpleArray
- public class SyncSimpleArray
- extends java.lang.Object
A simple synchronized static allocated array class.
The only difference from a normal array of objects is that the
access is synchronized. Is this enough ;-) ?
Written: Radu Sion
Version: 0.1
Source: SyncSimpleArray.java
Visit
Smart Software
Constructor Summary |
SyncSimpleArray(int size)
Creates a new array object of a given size and fills it up with null. |
Method Summary |
int |
active()
Returns the number of nonnull objects in the array. |
java.lang.Object |
get(int index)
Reads the object value at the specified index in the array. |
void |
remove(int index)
Removes a given object at a specified index in the array. |
void |
set(int index,
java.lang.Object obj)
Puts a object at a specified index in the array. |
int |
size()
Returns the number of static allocated slots. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
SyncSimpleArray
public SyncSimpleArray(int size)
- Creates a new array object of a given size and fills it up with null.
No parameter checkings are performed.
- Parameters:
size
- Number of empty slots to allocate static
active
public int active()
- Returns the number of nonnull objects in the array.
set
public void set(int index,
java.lang.Object obj)
- Puts a object at a specified index in the array.
No parameter checkings are performed.
- Parameters:
index
- The position inside the array where to put that objectobj
- object to use (may be also null)
remove
public void remove(int index)
- Removes a given object at a specified index in the array.
Is equivalent (for now) to .set(index,null).
No parameter checkings are performed.
- Parameters:
index
- The position inside the array from where to remove that object
get
public java.lang.Object get(int index)
- Reads the object value at the specified index in the array.
No parameter checkings are performed.
- Parameters:
index
- The position inside the array where to read from- Returns:
- The value at that position
size
public int size()
- Returns the number of static allocated slots.