com.isti.util
Class AddrPortListMgr

java.lang.Object
  extended by com.isti.util.ErrorMessageMgr
      extended by com.isti.util.AddrPortListMgr
All Implemented Interfaces:
ErrorMsgMgrIntf

public class AddrPortListMgr
extends ErrorMessageMgr

Class AddrPortListMgr manages a list of host-address/port-number entries.


Nested Class Summary
static class AddrPortListMgr.EntryBlock
          Class EntryBlock holds a host-address string and a port number value.
 
Field Summary
protected  java.util.Vector entriesVec
           
protected  boolean keepDefaultServersFlag
           
protected  DataChangedListener listCommitListenerObj
           
protected  java.util.Random randomObj
           
protected static char sepCh
           
 
Constructor Summary
AddrPortListMgr()
          Creates a manager for a list of host-address/port-number entries, with the list initially empty.
AddrPortListMgr(java.lang.String dataListStr)
          Creates a manager for a list of host-address/port-number entries, interprets the given data list string into host-address/port-number entries and adds them to the end of the list.
AddrPortListMgr(java.lang.String dataListStr, char itemSepChar)
          Creates a manager for a list of host-address/port-number entries, interprets the given data list string into host-address/port-number entries and adds them to the end of the list.
 
Method Summary
 boolean addEntriesListStr(java.lang.String dataListStr)
          Interprets the given data list string into host-address/port-number entries and adds them to the end of the list.
 boolean addEntriesListStr(java.lang.String dataListStr, char itemSepChar)
          Interprets the given data list string into host-address/port-number entries and adds them to the end of the list.
 boolean addEntry(AddrPortListMgr.EntryBlock blkObj)
          Adds a host-address/port-number entry to the end of the list.
 boolean addEntry(java.lang.String dataStr)
          Interprets the given data string into a host address and port number and adds a new entry with the values to the end of the list.
 boolean addEntry(java.lang.String addrStr, int portNum)
          Adds a host-address/port-number entry to the end of the list.
 void clearAllEntries()
          Removes all entries from the list.
 boolean contains(AddrPortListMgr.EntryBlock blkObj)
          Determines whether or not an entry with the same host-address and port-number exists in the list.
 boolean equalsFirstEntry(java.lang.String hostAddr, int portNum)
          Compares the given host-address/port-number to those held by the first entry in the list.
 void fireListCommit(java.lang.Object sourceObj)
          Indicates that the contents of the list should be "committed".
 java.lang.String getEntriesListStr()
          Returns a data list string containing the host-name/port-number entries in this list.
 java.lang.String getEntriesListStr(boolean randomFlag)
          Returns a data list string containing the host-name/port-number entries in this list.
 java.lang.String getEntriesListStr(char itemSepChar)
          Returns a data list string containing the host-name/port-number entries in this list.
 java.lang.String getEntriesListStr(char itemSepChar, boolean randomFlag)
          Returns a data list string containing the host-name/port-number entries in this list.
 AddrPortListMgr.EntryBlock getEntry(int idx)
          Returns the host-address/port-number entry at the given index in the list.
 boolean getKeepDefaultServersFlag()
          Returns the 'keepDefaultServersFlag' flag.
static char getSeparatorChar()
          Returns the host-address/port-number separator character.
 AddrPortListMgr.EntryBlock parseEntry(java.lang.String dataStr)
          Interprets the given data string into a host address and port number and creates and entry data block containing the values.
 java.lang.String popAllEntries()
          Removes and returns all entries in this list.
 java.lang.String popAllEntries(char itemSepChar)
          Removes and returns all entries in this list.
 AddrPortListMgr.EntryBlock popFirstAndAddEntry(AddrPortListMgr.EntryBlock blkObj)
          Fetches the first entry and deletes it from the list and then adds a host-address/port-number entry to the end of the list.
 AddrPortListMgr.EntryBlock popFirstAndAddEntry(java.lang.String addrStr, int portNum)
          Fetches the first entry and deletes it from the list and then adds a host-address/port-number entry to the end of the list.
 AddrPortListMgr.EntryBlock popFirstEntry()
          Fetches the first entry and deletes it from the list.
 AddrPortListMgr.EntryBlock popRandomEntry()
          Fetches a randomly-selected entry and deletes it from the list.
 boolean removeEntry(AddrPortListMgr.EntryBlock blkObj)
          Removes the given host-address/port-number entry.
 AddrPortListMgr.EntryBlock removeEntry(java.lang.String addrStr, int portNum)
          Removes the given host-address/port-number entry.
 boolean setEntriesListStr(java.lang.String dataListStr)
          Clears any current entries; then interprets the given data list string into host-address/port-number entries and adds them to the end of the list.
 boolean setEntriesListStr(java.lang.String dataListStr, char itemSepChar)
          Clears any current entries; then interprets the given data list string into host-address/port-number entries and adds them to the end of the list.
 void setKeepDefaultServersFlag(boolean flgVal)
          Sets the 'keepDefaultServersFlag' flag.
 void setListCommitListenerObj(DataChangedListener listenerObj)
          Enters the call-back listener to be called when the 'fireListCommit()' method is invoke.
static void setSeparatorChar(char ch)
          Sets the host-address/port-number separator character.
 int size()
          Returns the number of host-address/port-number entries in the list.
 
Methods inherited from class com.isti.util.ErrorMessageMgr
clearErrorMessageString, clearFetchedErrorMessage, enterErrorMessageString, getErrorMessageFlag, getErrorMessageString, getUnfetchedMessageFlag, setErrorMessageString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sepCh

protected static char sepCh

entriesVec

protected final java.util.Vector entriesVec

listCommitListenerObj

protected DataChangedListener listCommitListenerObj

keepDefaultServersFlag

protected boolean keepDefaultServersFlag

randomObj

protected final java.util.Random randomObj
Constructor Detail

AddrPortListMgr

public AddrPortListMgr()
Creates a manager for a list of host-address/port-number entries, with the list initially empty.


AddrPortListMgr

public AddrPortListMgr(java.lang.String dataListStr,
                       char itemSepChar)
Creates a manager for a list of host-address/port-number entries, interprets the given data list string into host-address/port-number entries and adds them to the end of the list. The 'getErrorMessage()' method may be used to determine if an error occurred while interpreting the data list string (in which case the 'getErrorMessageString()' method may be used to fetch the error message).

Parameters:
dataListStr - a data list string in the form "hostAddr:portNum,hostAddr:portNum,...", where ':' is the separator character defined via the 'setSeparatorChar()' method (default is ':') and ',' is the item-separator character defined by the 'itemSepChar' parameter.
itemSepChar - the item separator character.

AddrPortListMgr

public AddrPortListMgr(java.lang.String dataListStr)
Creates a manager for a list of host-address/port-number entries, interprets the given data list string into host-address/port-number entries and adds them to the end of the list. The 'getErrorMessage()' method may be used to determine if an error occurred while interpreting the data list string (in which case the 'getErrorMessageString()' method may be used to fetch the error message).

Parameters:
dataListStr - a data list string in the form "hostAddr:portNum,hostAddr:portNum,...", where ':' is the separator character defined via the 'setSeparatorChar()' method (default is ':').
Method Detail

parseEntry

public AddrPortListMgr.EntryBlock parseEntry(java.lang.String dataStr)
Interprets the given data string into a host address and port number and creates and entry data block containing the values.

Parameters:
dataStr - a data string in the form "hostAddr:portNum", where ':' is the separator character defined via the 'setSeparatorChar()' method (default is ':').
Returns:
A new 'EntryBlock' object, or null if an error occurred while interpreting the data string (in which case the 'getErrorMessageString()' method may be used to fetch the error message).

contains

public boolean contains(AddrPortListMgr.EntryBlock blkObj)
Determines whether or not an entry with the same host-address and port-number exists in the list.

Parameters:
blkObj - the host-address/port-number data-block to add.
Returns:
true if an an entry with the same host-address and port-number exists in the list.

addEntry

public boolean addEntry(AddrPortListMgr.EntryBlock blkObj)
Adds a host-address/port-number entry to the end of the list. If an entry with the same host address and port number already exists in the list then the list is left unchanged.

Parameters:
blkObj - the host-address/port-number data-block to use.
Returns:
true if the new entry was added to the end of the list; false if an entry with the same host address and port number already existed in the list and the list was left unchanged.

addEntry

public boolean addEntry(java.lang.String addrStr,
                        int portNum)
Adds a host-address/port-number entry to the end of the list. If an entry with the same host address and port number already exists in the list then the list is left unchanged.

Parameters:
addrStr - the host address to use.
portNum - the port number to use.
Returns:
true if the new entry was added to the end of the list; false if an entry with the same host address and port number already existed in the list and the list was left unchanged.

addEntry

public boolean addEntry(java.lang.String dataStr)
Interprets the given data string into a host address and port number and adds a new entry with the values to the end of the list.

Parameters:
dataStr - a data string in the form "hostAddr:portNum", where ':' is the separator character defined via the 'setSeparatorChar()' method (default is ':').
Returns:
true if successful, false if an error occurred while interpreting the data string (in which case the 'getErrorMessageString()' method may be used to fetch the error message).

addEntriesListStr

public final boolean addEntriesListStr(java.lang.String dataListStr,
                                       char itemSepChar)
Interprets the given data list string into host-address/port-number entries and adds them to the end of the list. If the given data list string contains no data then this method just returns 'true'.

Parameters:
dataListStr - a data list string in the form "hostAddr:portNum,hostAddr:portNum,...", where ':' is the separator character defined via the 'setSeparatorChar()' method (default is ':') and ',' is the item-separator character defined by the 'itemSepChar' parameter.
itemSepChar - the item separator character.
Returns:
true if successful, false if an error occurred while interpreting the data list string (in which case the 'getErrorMessageString()' method may be used to fetch the error message).

addEntriesListStr

public final boolean addEntriesListStr(java.lang.String dataListStr)
Interprets the given data list string into host-address/port-number entries and adds them to the end of the list. If the given data list string contains no data then this method just returns 'true'.

Parameters:
dataListStr - a data list string in the form "hostAddr:portNum,hostAddr:portNum,...", where ':' is the separator character defined via the 'setSeparatorChar()' method (default is ':').
Returns:
true if successful, false if an error occurred while interpreting the data list string (in which case the 'getErrorMessageString()' method may be used to fetch the error message).

setEntriesListStr

public boolean setEntriesListStr(java.lang.String dataListStr,
                                 char itemSepChar)
Clears any current entries; then interprets the given data list string into host-address/port-number entries and adds them to the end of the list. If the given data list string contains no data then this method just returns 'true'.

Parameters:
dataListStr - a data list string in the form "hostAddr:portNum,hostAddr:portNum,...", where ':' is the separator character defined via the 'setSeparatorChar()' method (default is ':') and ',' is the item-separator character defined by the 'itemSepChar' parameter.
itemSepChar - the item separator character.
Returns:
true if successful, false if an error occurred while interpreting the data list string (in which case the 'getErrorMessageString()' method may be used to fetch the error message).

setEntriesListStr

public boolean setEntriesListStr(java.lang.String dataListStr)
Clears any current entries; then interprets the given data list string into host-address/port-number entries and adds them to the end of the list. If the given data list string contains no data then this method just returns 'true'.

Parameters:
dataListStr - a data list string in the form "hostAddr:portNum,hostAddr:portNum,...", where ':' is the separator character defined via the 'setSeparatorChar()' method (default is ':').
Returns:
true if successful, false if an error occurred while interpreting the data list string (in which case the 'getErrorMessageString()' method may be used to fetch the error message).

size

public int size()
Returns the number of host-address/port-number entries in the list.

Returns:
The number of entries in the list.

removeEntry

public boolean removeEntry(AddrPortListMgr.EntryBlock blkObj)
Removes the given host-address/port-number entry.

Parameters:
blkObj - the host-address/port-number entry to remove.
Returns:
true if the list contained the entry, false if not.

removeEntry

public AddrPortListMgr.EntryBlock removeEntry(java.lang.String addrStr,
                                              int portNum)
Removes the given host-address/port-number entry.

Parameters:
addrStr - the host address to use.
portNum - the port number to use.
Returns:
An entry block object containing the host address and port number of the removed entry, or null if no matching entry was found.

clearAllEntries

public void clearAllEntries()
Removes all entries from the list.


getEntry

public AddrPortListMgr.EntryBlock getEntry(int idx)
Returns the host-address/port-number entry at the given index in the list.

Parameters:
idx - the index into the list to use.
Returns:
The host-address/port-number entry at the given index in the list, or null if no entries exists for the given index.

popFirstEntry

public AddrPortListMgr.EntryBlock popFirstEntry()
Fetches the first entry and deletes it from the list.

Returns:
The first 'EntryBlock' object in the list, or null if none were found.

popFirstAndAddEntry

public AddrPortListMgr.EntryBlock popFirstAndAddEntry(AddrPortListMgr.EntryBlock blkObj)
Fetches the first entry and deletes it from the list and then adds a host-address/port-number entry to the end of the list. If an entry with the same host address and port number already exists in the list then the list is left unchanged. If the list is empty then the given entry is added and null is returned.

Parameters:
blkObj - the host-address/port-number data-block to add.
Returns:
The first 'EntryBlock' object in the list, or null if none were found.

popFirstAndAddEntry

public AddrPortListMgr.EntryBlock popFirstAndAddEntry(java.lang.String addrStr,
                                                      int portNum)
Fetches the first entry and deletes it from the list and then adds a host-address/port-number entry to the end of the list. If an entry with the same host address and port number already exists in the list then the list is left unchanged. If the list is empty then the given entry is added and null is returned.

Parameters:
addrStr - the host address to use.
portNum - the port number to use.
Returns:
The first 'EntryBlock' object in the list, or null if none were found.

popRandomEntry

public AddrPortListMgr.EntryBlock popRandomEntry()
Fetches a randomly-selected entry and deletes it from the list.

Returns:
A randomly-selected 'EntryBlock' object in the list, or null if none were found.

equalsFirstEntry

public boolean equalsFirstEntry(java.lang.String hostAddr,
                                int portNum)
Compares the given host-address/port-number to those held by the first entry in the list.

Parameters:
hostAddr - the host address to use.
portNum - the port number to use.
Returns:
true if the given host-address/port-number equals the host address string and port number fields held by the first entry in the list; false if not.

getEntriesListStr

public java.lang.String getEntriesListStr(char itemSepChar,
                                          boolean randomFlag)
Returns a data list string containing the host-name/port-number entries in this list. The returned string is in the form "hostAddr:portNum,hostAddr:portNum,...", where ':' is the separator character defined via the 'setSeparatorChar()' method (default is ':') and ',' is the item-separator character defined by the 'itemSepChar' parameter.

Parameters:
itemSepChar - the item separator character.
randomFlag - true to return the entries in random order; false to return the entries in order as entered.
Returns:
A data list string containing the host-name/port-number entries in this list.

getEntriesListStr

public java.lang.String getEntriesListStr(char itemSepChar)
Returns a data list string containing the host-name/port-number entries in this list. The returned string is in the form "hostAddr:portNum,hostAddr:portNum,...", where ':' is the separator character defined via the 'setSeparatorChar()' method (default is ':') and ',' is the item-separator character defined by the 'itemSepChar' parameter.

Parameters:
itemSepChar - the item separator character.
Returns:
A data list string containing the host-name/port-number entries in this list.

getEntriesListStr

public java.lang.String getEntriesListStr(boolean randomFlag)
Returns a data list string containing the host-name/port-number entries in this list. The returned string is in the form "hostAddr:portNum,hostAddr:portNum,...", where ':' is the separator character defined via the 'setSeparatorChar()' method (default is ':').

Parameters:
randomFlag - true to return the entries in random order; false to return the entries in order as entered.
Returns:
A data list string containing the host-name/port-number entries in this list.

getEntriesListStr

public java.lang.String getEntriesListStr()
Returns a data list string containing the host-name/port-number entries in this list. The returned string is in the form "hostAddr:portNum,hostAddr:portNum,...", where ':' is the separator character defined via the 'setSeparatorChar()' method (default is ':').

Returns:
A data list string containing the host-name/port-number entries in this list.

popAllEntries

public java.lang.String popAllEntries(char itemSepChar)
Removes and returns all entries in this list. The returned string is in the form "hostAddr:portNum,hostAddr:portNum,...", where ':' is the separator character defined via the 'setSeparatorChar()' method (default is ':') and ',' is the item-separator character defined by the 'itemSepChar' parameter.

Parameters:
itemSepChar - the item separator character.
Returns:
A data list string containing the host-name/port-number entries that were removed from this list.

popAllEntries

public java.lang.String popAllEntries()
Removes and returns all entries in this list. The returned string is in the form "hostAddr:portNum,hostAddr:portNum,...", where ':' is the separator character defined via the 'setSeparatorChar()' method (default is ':').

Returns:
A data list string containing the host-name/port-number entries that were removed from this list.

setListCommitListenerObj

public void setListCommitListenerObj(DataChangedListener listenerObj)
Enters the call-back listener to be called when the 'fireListCommit()' method is invoke.

Parameters:
listenerObj - the call-back listener to use, or null to clear any current listener.

fireListCommit

public void fireListCommit(java.lang.Object sourceObj)
Indicates that the contents of the list should be "committed". The call-back listener setup by the 'setListCommitListenerObj()' method is called.

Parameters:
sourceObj - the source object to be passed along to the call-back listener.

setSeparatorChar

public static void setSeparatorChar(char ch)
Sets the host-address/port-number separator character. The default value is ':'.

Parameters:
ch - the separator character to use.

getSeparatorChar

public static char getSeparatorChar()
Returns the host-address/port-number separator character.

Returns:
The host-address/port-number separator character.

setKeepDefaultServersFlag

public void setKeepDefaultServersFlag(boolean flgVal)
Sets the 'keepDefaultServersFlag' flag. This determines what value is returned by the 'getKeepDefaultServersFlag()', but is not otherwise used by this class.

Parameters:
flgVal - the flag value to use.

getKeepDefaultServersFlag

public boolean getKeepDefaultServersFlag()
Returns the 'keepDefaultServersFlag' flag.

Returns:
The 'keepDefaultServersFlag' flag.