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.
  *
  */
 package gov.nist.core;
 
 import java.util.Map;
 import java.util.Set;

This is a Duplicate Name Value List that will allow multiple values map to the same key. The parsing and encoding logic for it is the same as that of NameValueList. Only the HashMap container is different.

Author(s):
aayush.bhatnagar
Since:
2.0
 
 public class DuplicateNameValueList implements SerializableCloneable {
 
 
     private static final long serialVersionUID = -5611332957903796952L;
 
     public DuplicateNameValueList()
 
     {
     }
 
     // ------------------
 
    
Encode the list in semicolon separated form.

Returns:
an encoded string containing the objects in this list.
Since:
v1.0
 
     public String encode() {
         return encode(new StringBuilder()).toString();
     }
 
     public StringBuilder encode(StringBuilder buffer) {
         if (!.isEmpty()) {
             Iterator<NameValueiterator = .values().iterator();
             if (iterator.hasNext()) {
                 while (true) {
                     Object obj = iterator.next();
                     if (obj instanceof GenericObject) {
                         GenericObject gobj = (GenericObjectobj;
                         gobj.encode(buffer);
                     } else {
                         buffer.append(obj.toString());
                     }
                     if (iterator.hasNext())
                         buffer.append(.);
                     else
                         break;
                 }
             }
         }
         return buffer;
     }
 
     public String toString() {
         return this.encode();
     }

    
Set a namevalue object in this list.
 
 
     public void set(NameValue nv) {
         this..put(nv.getName().toLowerCase(), nv);
     }

    
Set a namevalue object in this list.
    public void set(String nameObject value) {
        NameValue nameValue = new NameValue(namevalue);
        .put(name.toLowerCase(), nameValue);
    }

    
Compare if two NameValue lists are equal.

Parameters:
otherObject is the object to compare to.
Returns:
true if the two objects compare for equality.
    public boolean equals(Object otherObject) {
        if ( otherObject == null ) {
            return false;
        }
        if (!otherObject.getClass().equals(this.getClass())) {
            return false;
        }
        DuplicateNameValueList other = (DuplicateNameValueListotherObject;
        if (.size() != other.nameValueMap.size()) {
            return false;
        }
        Iterator<Stringli = this..keySet().iterator();
        while (li.hasNext()) {
            String key = (Stringli.next();
            Collection nv1 = this.getNameValue(key);
            Collection nv2 = (Collectionother.nameValueMap.get(key);
            if (nv2 == null)
                return false;
            else if (!nv2.equals(nv1))
                return false;
        }
        return true;
    }

    
Do a lookup on a given name and return value associated with it.
    public Object getValue(String name) {
        Collection nv = this.getNameValue(name.toLowerCase());
        if (nv != null)
            return nv;
        else
            return null;
    }

    
Get the NameValue record given a name.
    public Collection getNameValue(String name) {
        return (Collectionthis..get(name.toLowerCase());
    }

    
Returns a boolean telling if this NameValueList has a record with this name
    public boolean hasNameValue(String name) {
        return .containsKey(name.toLowerCase());
    }

    
Remove the element corresponding to this name.
    public boolean delete(String name) {
        String lcName = name.toLowerCase();
        if (this..containsKey(lcName)) {
            this..remove(lcName);
            return true;
        } else {
            return false;
        }
    }
    public Object clone() {
        DuplicateNameValueList retval = new DuplicateNameValueList();        
        Iterator<NameValueit = this..values().iterator();
        while (it.hasNext()) {
            retval.set((NameValue) ((NameValueit.next()).clone());
        }
        return retval;
    }

    
Return an iterator for the name-value pairs of this list.

Returns:
the iterator.
    public Iterator<NameValueiterator() {
        return this..values().iterator();
    }

    
Get a list of parameter names.

Returns:
a list iterator that has the names of the parameters.
    public Iterator<StringgetNames() {
        return this..keySet().iterator();
    }

    
Get the parameter as a String.

Returns:
the parameter as a string.
    public String getParameter(String name) {
        Object val = this.getValue(name);
        if (val == null)
            return null;
        if (val instanceof GenericObject)
            return ((GenericObjectval).encode();
        else
            return val.toString();
    }
    public void clear() {
        .clear();
    }
    public boolean isEmpty() {
        return this..isEmpty();
    }
    public NameValue put(String keyNameValue value) {
        return (NameValuethis..put(keyvalue);
    }
    public NameValue remove(Object key) {
        return (NameValuethis..remove(key);
    }
    public int size() {
        return this..size();
    }
    public Collection<NameValuevalues() {
        return this..values();
    }
    public int hashCode() {
        return this..keySet().hashCode();
    }
New to GrepCode? Check out our FAQ X