Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Conditions Of Use
   *
   * This software was developed by employees of the National Institute of
   * Standards and Technology (NIST), an agency of the Federal Government.
   * Pursuant to title 15 Untied States Code Section 105, works of NIST
   * employees are not subject to copyright protection in the United States
   * and are considered to be in the public domain.  As a result, a formal
   * license is not needed to use the software.
  *
  * This software is provided by NIST as a service and is expressly
  * provided "AS IS."  NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED
  * OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT
  * AND DATA ACCURACY.  NIST does not warrant or make any representations
  * regarding the use of the software or the results thereof, including but
  * not limited to the correctness, accuracy, reliability or usefulness of
  * the software.
  *
  * Permission to use this software is contingent upon your acceptance
  * of the terms of this agreement
  *
  * .
  *
  */
Product of NIST/ITL Advanced Networking Technologies Division (ANTD). * /
 
 package gov.nist.core;
 
 import java.util.*;
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.

Author(s):
M. Ranganathan
Version:
1.2
 
 public abstract class GenericObjectList extends LinkedList<GenericObjectimplements
         SerializableCloneable{
     // Useful constants.
     protected static final String SEMICOLON = .;
 
     protected static final String COLON = .;
 
     protected static final String COMMA = .;
 
     protected static final String SLASH = .;
 
     protected static final String SP = .;
 
     protected static final String EQUALS = .;
 
     protected static final String STAR = .;
 
     protected static final String NEWLINE = .;
 
     protected static final String RETURN = .;
 
     protected static final String LESS_THAN = .;
 
     protected static final String GREATER_THAN = .;
 
     protected static final String AT = .;
 
     protected static final String DOT = .;
 
     protected static final String QUESTION = .;
 
     protected static final String POUND = .;
 
     protected static final String AND = .;
 
     protected static final String LPAREN = .;
 
     protected static final String RPAREN = .;
 
     protected static final String DOUBLE_QUOTE = .;
 
     protected static final String QUOTE = .;
 
     protected static final String HT = .;
 
     protected static final String PERCENT = .;
 
     protected int indentation;
 
     protected String listName// For debugging
 
     private ListIterator<? extends GenericObjectmyListIterator;
 
    private String stringRep;
    protected Class<?> myClass;
    protected String separator;
    protected String getIndentation() {
        char[] chars = new char[];
        java.util.Arrays.fill(chars' ');
        return new String(chars);
    }

    
Return true if this supports reflection based cloning.
    protected static boolean isCloneable(Object obj) {
        return obj instanceof Cloneable;
    }
    public static boolean isMySubclass(Class<?> other) {
        return GenericObjectList.class.isAssignableFrom(other);
    }

    
Makes a deep clone of this list.
    public Object clone() {
        GenericObjectList retval = (GenericObjectListsuper.clone();
        for (ListIterator<GenericObjectiter = retval.listIterator(); iter.hasNext();) {
            GenericObject obj = (GenericObject) ((GenericObjectiter.next())
                    .clone();
            iter.set(obj);
        }
        return retval;
    }
    public void setMyClass(Class cl) {
         = cl;
    }
    protected GenericObjectList() {
        super();
         = null;
         = "";
         = ";";
    }
    protected GenericObjectList(String lname) {
        this();
         = lname;
    }

    
A Constructor which takes a list name and a class name (for assertion checking).
    protected GenericObjectList(String lnameString classname) {
        this(lname);
        try {
             = Class.forName(classname);
        } catch (ClassNotFoundException ex) {
            InternalErrorHandler.handleException(ex);
        }
    }

    
A Constructor which takes a list name and a class (for assertion checking).
    protected GenericObjectList(String lnameClass objclass) {
        this(lname);
         = objclass;
    }

    
Traverse the list given a list iterator
    protected GenericObject next(ListIterator iterator) {
        try {
            return (GenericObjectiterator.next();
        } catch (NoSuchElementException ex) {
            return null;
        }
    }

    
This is the default list iterator.This will not handle nested list traversal.
    protected GenericObject first() {
         = this.listIterator(0);
        try {
            return (GenericObject.next();
        } catch (NoSuchElementException ex) {
            return null;
        }
    }

    
Fetch the next object from the list based on the default list iterator
    protected GenericObject next() {
        if ( == null) {
             = this.listIterator(0);
        }
        try {
            return (GenericObject.next();
        } catch (NoSuchElementException ex) {
             = null;
            return null;
        }
    }

    
Concatenate two compatible header lists, adding the argument to the tail end of this list.

Parameters:
<var> topFlag set to true to add items to top of list
    protected void concatenate(GenericObjectList objList) {
        concatenate(objListfalse);
    }

    
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.

Parameters:
<var> topFlag set to true to add items to top of list else add them to the tail end of the list.
    protected void concatenate(GenericObjectList objListboolean topFlag) {
        if (!topFlag) {
            this.addAll(objList);
        } else {
            // add given items to the top end of the list.
            this.addAll(0, objList);
        }
    }

    
string formatting function.
    private void sprint(String s) {
        if (s == null) {
             += getIndentation();
             += "<null>\n";
            return;
        }
        if (s.compareTo("}") == 0 || s.compareTo("]") == 0) {
            --;
        }
         += getIndentation();
         += s;
         += "\n";
        if (s.compareTo("{") == 0 || s.compareTo("[") == 0) {
            ++;
        }
    }

    
Convert this list of headers to a formatted string.
    public String debugDump() {
         = "";
        Object obj = this.first();
        if (obj == null)
            return "<null>";
        sprint("listName:");
        sprint();
        sprint("{");
        while (obj != null) {
            sprint("[");
            sprint(((GenericObjectobj).debugDump(this.));
            obj = next();
            sprint("]");
        }
        sprint("}");
        return ;
    }

    
Convert this list of headers to a string (for printing) with an indentation given.
    public String debugDump(int indent) {
        int save = ;
         = indent;
        String retval = this.debugDump();
         = save;
        return retval;
    }
    public void addFirst(GenericObject objToAdd) {
        if ( == null) {
             = objToAdd.getClass();
        } else {
            super.addFirst(objToAdd);
        }
    }

    
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.
    public void mergeObjects(GenericObjectList mergeList) {
        if (mergeList == null)
            return;
        Iterator it1 = this.listIterator();
        Iterator it2 = mergeList.listIterator();
        while (it1.hasNext()) {
            GenericObject outerObj = (GenericObjectit1.next();
            while (it2.hasNext()) {
                Object innerObj = it2.next();
                outerObj.merge(innerObj);
            }
        }
    }

    
Encode the list in semicolon separated form.

Returns:
an encoded string containing the objects in this list.
Since:
v1.0
    public String encode() {
        if (this.isEmpty())
            return "";
        StringBuffer encoding = new StringBuffer();
        ListIterator iterator = this.listIterator();
        if (iterator.hasNext()) {
            while (true) {
                Object obj = iterator.next();
                if (obj instanceof GenericObject) {
                    GenericObject gobj = (GenericObjectobj;
                    encoding.append(gobj.encode());
                } else {
                    encoding.append(obj.toString());
                }
                if (iterator.hasNext())
                    encoding.append();
                else
                    break;
            }
        }
        return encoding.toString();
    }

    
Alias for the encode function above.
    public String toString() {
        return this.encode();
    }

    
Set the separator (for encoding the list)

Parameters:
sep is the new seperator (default is semicolon)
Since:
v1.0
    public void setSeparator(String sep) {
         = sep;
    }
    
    
Hash code. We never expect to put this in a hash table so return a constant.
    public int hashCode() { return 42; }

    
Equality checking predicate.

Parameters:
other is the object to compare ourselves to.
Returns:
true if the objects are equal.
    public boolean equals(Object other) {
        if (other == null ) return false;
        if (!this.getClass().equals(other.getClass()))
            return false;
        GenericObjectList that = (GenericObjectListother;
        if (this.size() != that.size())
            return false;
        ListIterator myIterator = this.listIterator();
        while (myIterator.hasNext()) {
            Object myobj = myIterator.next();
            ListIterator hisIterator = that.listIterator();
            try {
                while (true) {
                    Object hisobj = hisIterator.next();
                    if (myobj.equals(hisobj))
                        break;
                }
            } catch (NoSuchElementException ex) {
                return false;
            }
        }
        ListIterator hisIterator = that.listIterator();
        while (hisIterator.hasNext()) {
            Object hisobj = hisIterator.next();
            myIterator = this.listIterator();
            try {
                while (true) {
                    Object myobj = myIterator.next();
                    if (hisobj.equals(myobj))
                        break;
                }
            } catch (NoSuchElementException ex) {
                return false;
            }
        }
        return true;
    }

    
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.
    public boolean match(Object other) {
        if (!this.getClass().equals(other.getClass()))
            return false;
        GenericObjectList that = (GenericObjectListother;
        ListIterator hisIterator = that.listIterator();
        outer: while (hisIterator.hasNext()) {
            Object hisobj = hisIterator.next();
            Object myobj = null;
            ListIterator myIterator = this.listIterator();
            while (myIterator.hasNext()) {
                myobj = myIterator.next();
                if (myobj instanceof GenericObject)
                    ..println("Trying to match  = "
                            + ((GenericObjectmyobj).encode());
                if (GenericObject.isMySubclass(myobj.getClass())
                        && ((GenericObjectmyobj).match(hisobj))
                    break outer;
                else if (GenericObjectList.isMySubclass(myobj.getClass())
                        && ((GenericObjectListmyobj).match(hisobj))
                    break outer;
            }
            ..println(((GenericObjecthisobj).encode());
            return false;
        }
        return true;
    }
New to GrepCode? Check out our FAQ X