org.lastbamboo.common.sdp
Class GenericObjectList

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.AbstractSequentialList<E>
              extended by java.util.LinkedList
                  extended by org.lastbamboo.common.sdp.GenericObjectList
All Implemented Interfaces:
Serializable, Cloneable, Iterable, Collection, Deque, List, Queue
Direct Known Subclasses:
NameValueList, SDPObjectList

public abstract class GenericObjectList
extends LinkedList
implements Serializable, Cloneable

Implements a homogenous consistent linked list. All the objects in the linked list must derive from the same root class. This is a useful constraint to place on our code as this property is invariant.The list is created with the superclass which can be specified as either a class name or a Class.

Version:
JAIN-SIP-1.1
Author:
M. Ranganathan
This code is in the public domain.
See Also:
Serialized Form

Field Summary
protected static String AND
           
protected static String AT
           
protected static String COLON
           
protected static String COMMA
           
protected static String DOT
           
protected static String DOUBLE_QUOTE
           
protected static String EQUALS
           
protected static String GREATER_THAN
           
protected static String HT
           
protected  int indentation
           
protected static String LESS_THAN
           
protected  String listName
           
protected static String LPAREN
           
protected  Class myClass
           
protected static String NEWLINE
           
protected static String PERCENT
           
protected static String POUND
           
protected static String QUESTION
           
protected static String QUOTE
           
protected static String RETURN
           
protected static String RPAREN
           
protected static String SEMICOLON
           
protected  String separator
           
protected static String SLASH
           
protected static String SP
           
protected static String STAR
           
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
protected GenericObjectList()
           
protected GenericObjectList(String lname)
           
protected GenericObjectList(String lname, Class objclass)
          A Constructor which takes a list name and a class (for assertion checking).
 
Method Summary
protected  void add(GenericObject obj)
          Type checked add operation.
 boolean add(Object obj)
           
 void addFirst(Object objToAdd)
           
 Object clone()
          Makes a deep clone of this list.
protected  void concatenate(GenericObjectList objList)
          Concatenate two compatible header lists, adding the argument to the tail end of this list.
protected  void concatenate(GenericObjectList objList, boolean topFlag)
          Concatenate two compatible header lists, adding the argument either to the beginning or the tail end of this list.
 String debugDump()
          Convert this list of headers to a formatted string.
 String debugDump(int indent)
          Convert this list of headers to a string (for printing) with an indentation given.
 String encode()
          Encode the list in semicolon separated form.
 boolean equals(Object other)
          Equality checking predicate.
protected  GenericObject first()
          This is the default list iterator.This will not handle nested list traversal.
protected  String getIndentation()
           
 Iterator getIterator()
          Get the list iterator for this list.
 Class getMyClass()
          Sets the class that all our elements derive from.
protected static boolean isCloneable(Object obj)
          Return true if this supports reflection based cloning.
static boolean isMySubclass(Class other)
           
 boolean match(Object other)
          Match with a template (return true if we have a superset of the given template.
 void mergeObjects(GenericObjectList mergeList)
          Do a merge of the GenericObjects contained in this list with the GenericObjects in the mergeList.
protected  GenericObject next()
          Fetch the next object from the list based on the default list iterator
protected  GenericObject next(ListIterator iterator)
          Traverse the list given a list iterator
 void replace(Match regexp, GenericObject replacementObject)
          Do a find and replace of objects in this list.
 void replace(Match regexp, GenericObjectList replacementObject)
          Do a find and replace of objects in this list.
 void replace(String objectText, GenericObject replacementObject, boolean matchSubstring)
          Do a find and replace of objects in this list.
 void replace(String objectText, GenericObjectList replacementObject, boolean matchSubstring)
          Do a find and replace of objects in this list.
 void setMyClass(Class cl)
           
 void setSeparator(String sep)
          Set the separator (for encoding the list)
 String toString()
          Alias for the encode function above.
 
Methods inherited from class java.util.LinkedList
add, addAll, addAll, addLast, clear, contains, descendingIterator, element, get, getFirst, getLast, indexOf, lastIndexOf, listIterator, offer, offerFirst, offerLast, peek, peekFirst, peekLast, poll, pollFirst, pollLast, pop, push, remove, remove, remove, removeFirst, removeFirstOccurrence, removeLast, removeLastOccurrence, set, size, toArray, toArray
 
Methods inherited from class java.util.AbstractSequentialList
iterator
 
Methods inherited from class java.util.AbstractList
hashCode, listIterator, removeRange, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, isEmpty, removeAll, retainAll
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, hashCode, isEmpty, iterator, listIterator, removeAll, retainAll, subList
 
Methods inherited from interface java.util.Deque
iterator
 

Field Detail

SEMICOLON

protected static final String SEMICOLON
See Also:
Constant Field Values

COLON

protected static final String COLON
See Also:
Constant Field Values

COMMA

protected static final String COMMA
See Also:
Constant Field Values

SLASH

protected static final String SLASH
See Also:
Constant Field Values

SP

protected static final String SP
See Also:
Constant Field Values

EQUALS

protected static final String EQUALS
See Also:
Constant Field Values

STAR

protected static final String STAR
See Also:
Constant Field Values

NEWLINE

protected static final String NEWLINE
See Also:
Constant Field Values

RETURN

protected static final String RETURN
See Also:
Constant Field Values

LESS_THAN

protected static final String LESS_THAN
See Also:
Constant Field Values

GREATER_THAN

protected static final String GREATER_THAN
See Also:
Constant Field Values

AT

protected static final String AT
See Also:
Constant Field Values

DOT

protected static final String DOT
See Also:
Constant Field Values

QUESTION

protected static final String QUESTION
See Also:
Constant Field Values

POUND

protected static final String POUND
See Also:
Constant Field Values

AND

protected static final String AND
See Also:
Constant Field Values

LPAREN

protected static final String LPAREN
See Also:
Constant Field Values

RPAREN

protected static final String RPAREN
See Also:
Constant Field Values

DOUBLE_QUOTE

protected static final String DOUBLE_QUOTE
See Also:
Constant Field Values

QUOTE

protected static final String QUOTE
See Also:
Constant Field Values

HT

protected static final String HT
See Also:
Constant Field Values

PERCENT

protected static final String PERCENT
See Also:
Constant Field Values

indentation

protected int indentation

listName

protected String listName

myClass

protected Class myClass

separator

protected String separator
Constructor Detail

GenericObjectList

protected GenericObjectList()

GenericObjectList

protected GenericObjectList(String lname)

GenericObjectList

protected GenericObjectList(String lname,
                            Class objclass)
A Constructor which takes a list name and a class (for assertion checking).

Method Detail

getIndentation

protected String getIndentation()

isCloneable

protected static boolean isCloneable(Object obj)
Return true if this supports reflection based cloning.


isMySubclass

public static boolean isMySubclass(Class other)

clone

public Object clone()
Makes a deep clone of this list.

Overrides:
clone in class LinkedList

getMyClass

public Class getMyClass()
Sets the class that all our elements derive from.


setMyClass

public void setMyClass(Class cl)

next

protected GenericObject next(ListIterator iterator)
Traverse the list given a list iterator


first

protected GenericObject first()
This is the default list iterator.This will not handle nested list traversal.


next

protected GenericObject next()
Fetch the next object from the list based on the default list iterator


concatenate

protected void concatenate(GenericObjectList objList)
Concatenate two compatible header lists, adding the argument to the tail end of this list.

Type Parameters:
var - topFlag set to true to add items to top of list

concatenate

protected void concatenate(GenericObjectList objList,
                           boolean topFlag)
Concatenate two compatible header lists, adding the argument either to the beginning or the tail end of this list. A type check is done before concatenation.

Type Parameters:
var - topFlag set to true to add items to top of list else add them to the tail end of the list.

getIterator

public Iterator getIterator()
Get the list iterator for this list.


debugDump

public String debugDump()
Convert this list of headers to a formatted string.


debugDump

public String debugDump(int indent)
Convert this list of headers to a string (for printing) with an indentation given.


add

public boolean add(Object obj)
Specified by:
add in interface Collection
Specified by:
add in interface Deque
Specified by:
add in interface List
Specified by:
add in interface Queue
Overrides:
add in class LinkedList

addFirst

public void addFirst(Object objToAdd)
Specified by:
addFirst in interface Deque
Overrides:
addFirst in class LinkedList

add

protected void add(GenericObject obj)
Type checked add operation. All objects in this list are assignable from a common superclass. If the class is already set, then the new one is just compared with the existing class objects. Otherwise the first object that is added determines the class of the objects in the list.


replace

public void replace(String objectText,
                    GenericObject replacementObject,
                    boolean matchSubstring)
             throws IllegalArgumentException
Do a find and replace of objects in this list.

Parameters:
objectText - text of the object to find.
replacementObject - object to replace the target with ( in case a target is found).
matchSubstring - boolean that indicates whether to flag a match when objectText is a substring of a candidate object's encoded text.
Throws:
IllegalArgumentException

replace

public void replace(String objectText,
                    GenericObjectList replacementObject,
                    boolean matchSubstring)
             throws IllegalArgumentException
Do a find and replace of objects in this list.

Parameters:
objectText - text of the object to find.
replacementObject - object to replace the target with (in case a target is found).
matchSubstring - boolean that indicates whether to flag a match when objectText is a substring of a candidate object's encoded text.
Throws:
IllegalArgumentException
Since:
v1.0

replace

public void replace(Match regexp,
                    GenericObjectList replacementObject)
             throws IllegalArgumentException
Do a find and replace of objects in this list.

Parameters:
regexp - regular expression to match with the canonical text we want to replace.
replacementObject - object to replace the target with (in case a target is found).
Throws:
IllegalArgumentException

replace

public void replace(Match regexp,
                    GenericObject replacementObject)
             throws IllegalArgumentException
Do a find and replace of objects in this list.

Parameters:
regexp - match regular expression of the object to find. this is generated using the org.apache.regexp package.
replacementObject - object to replace the target with ( in case a target is found).
Throws:
IllegalArgumentException

mergeObjects

public void mergeObjects(GenericObjectList mergeList)
Do a merge of the GenericObjects contained in this list with the GenericObjects in the mergeList. Note that this does an inplace modification of the given list. This does an object by object merge of the given objects.

Parameters:
mergeList - is the list of Generic objects that we want to do an object by object merge with. Note that no new objects are added to this list.

encode

public String encode()
Encode the list in semicolon separated form.

Returns:
an encoded string containing the objects in this list.
Since:
v1.0

toString

public String toString()
Alias for the encode function above.

Overrides:
toString in class AbstractCollection

setSeparator

public void setSeparator(String sep)
Set the separator (for encoding the list)

Parameters:
sep - is the new seperator (default is semicolon)
Since:
v1.0

equals

public boolean equals(Object other)
Equality checking predicate.

Specified by:
equals in interface Collection
Specified by:
equals in interface List
Overrides:
equals in class AbstractList
Parameters:
other - is the object to compare ourselves to.
Returns:
true if the objects are equal.

match

public boolean match(Object other)
Match with a template (return true if we have a superset of the given template. This can be used for partial match (template matching of SIP objects). Note -- this implementation is not unnecessarily efficient :-)

Parameters:
other - template object to compare against.


Copyright © 2013 LittleShoot. All Rights Reserved.