xbn.named
Class ManualNamedArray

java.lang.Object
  |
  +--xbn.XBNObject
        |
        +--xbn.named.ManualNamedArray

public class ManualNamedArray
extends XBNObject

A manual implementation of NamedArray. Where the heart of a NamedArray is an AOSLookup, the heart of ManualNamedArray is a plain array of Named objects.

Source code:  ManualNamedArray.java

Don't use this when speed and efficiency are critical. Do use this when you must not be dependent on the xbn.named (and other fundamental) classes. ManualNamedArray is intended for use in objects that cannot depend on NamedArray (to avoid circular dependencies), but need most of it's functionality.


Fields inherited from class xbn.XBNObject
bFALSE_IN_PRODUCTION, bTRUE_IN_PRODUCTION, sCNSTR, sES, sLINE_SEP
 
Constructor Summary
ManualNamedArray(Named[] a_named)
          Create a ManualNamedArray.
ManualNamedArray(Named[] a_named, boolean b_lock)
          Create a ManualNamedArray.
 
Method Summary
 void add(Named n_amed)
          Add a new Named object to the array.
 void addOrReplace(Named n_amed)
          Add a new or replace an existing Named object in the array.
 boolean doesExist(String s_name)
          Does the provided name exist in the Named array?
 Named[] getAONamed()
          Get the array of Named objects for direct manipulation.
 int getArrIdx(String s_name)
          At which array index does the requested Named element exist?
protected  int getArrIdx(String s_name, boolean b_crashIfNotFound)
          At which array index does the requested Named element exist?
 int getLength()
          How many Named elements exist in the array?
 Named getNamed(int i_dx)
          Get the Named element at the requested array index.
 Named getNamed(String s_name)
          Get the Named element having the provided name.
 void replace(Named n_amed)
          Replace a Named object already existing in the array.
 String toString()
          Get some information about this ManualNamedArray.
 
Methods inherited from class xbn.XBNObject
getXMsgPrefix, sop, sopl, sopl, throwAX, throwAXIfBadStr, throwAXIfNull, throwAXSpoof
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ManualNamedArray

public ManualNamedArray(Named[] a_named)

Create a ManualNamedArray.

Equal to ManualNamedArray(a_named, false)


ManualNamedArray

public ManualNamedArray(Named[] a_named,
                        boolean b_lock)

Create a ManualNamedArray.

Parameters:
a_named - The array of Named objects. May not be null, zero elements in length, and every element must be non null, and have unique names.
b_lock - Should direct access be allowed to a_named? If true, then yes. If false, no. See getAONamed, add, addOrReplace and replace.
Method Detail

doesExist

public boolean doesExist(String s_name)

Does the provided name exist in the Named array?

Returns:
(getArrIdx(s_name, false) != -1)

getNamed

public Named getNamed(String s_name)

Get the Named element having the provided name.

Returns:
a_named[getArrIdx(s_name)] Where a_named is exactly as provided to the constructor.

getNamed

public Named getNamed(int i_dx)

Get the Named element at the requested array index.

Returns:
a_named[i_dx] Where a_named is exactly as provided to the constructor.

getLength

public int getLength()

How many Named elements exist in the array?

Returns:
a_named.length Where a_named is exactly as provided to the constructor.

getAONamed

public Named[] getAONamed()

Get the array of Named objects for direct manipulation.

Returns:
a_named Where a_named is exactly as provided to the constructor.

addOrReplace

public void addOrReplace(Named n_amed)

Add a new or replace an existing Named object in the array.

Parameters:
n_amed - The Named object to add or replace. May not be null. If n_amed.getName does exist in the array of Named objects, then that element is replaced by this. If the name does not exist, this n_amed is added to the end of the array.

replace

public void replace(Named n_amed)

Replace a Named object already existing in the array.

Parameters:
n_amed - The Named object to add. May not be null and getName must exist.

add

public void add(Named n_amed)

Add a new Named object to the array.

Parameters:
n_amed - The Named object to add. May not be null and getName may not exist.

getArrIdx

public int getArrIdx(String s_name)

At which array index does the requested Named element exist?

Returns:
getArrIdx(s_name, true)

getArrIdx

protected int getArrIdx(String s_name,
                        boolean b_crashIfNotFound)

At which array index does the requested Named element exist?

Parameters:
s_name - The name of the Named object. May not be null.
b_crashIfNotFound - If true and s_name does not exist, then an AssertException is thrown with an error message saying so. If false and s_name does not exist, then -1 is returned.
Returns:
The array index at which the Named having s_name as its name exists, or -1 if it does not.

toString

public String toString()

Get some information about this ManualNamedArray.

Overrides:
toString in class Object



Copyright 1997-2003, Jeff Epstein, All Rights Reserved. See top of source code files for copyright notice.

 

http://sourceforge.net/projects/xbnjava

 

SourceForge.net Logo