/*
 * Balsa SCGI
 * Copyright (c) 2012, Chris Ellis
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met: 
 * 
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer. 
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution. 
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *  
 */

package com.intrbiz.balsa.parameter;

import java.io.InputStream;
import java.util.List;


public abstract class AbstractParameter implements Parameter
{
    private final String name;
    
    private final int index;

    public AbstractParameter(String name, int index)
    {
        this.name = name;
        this.index = index;
    }
    
    public AbstractParameter(String name)
    {
        this(name, -1);
    }

    public String getName()
    {
        return name;
    }
    
    public int getIndex()
    {
        return this.index;
    }

    public Object getValue()
    {
        return null;
    }

    public String getStringValue()
    {
        return null;
    }

    public List<Parameter> getListValue()
    {
        return null;
    }
    
    public Parameter getListValue(int index)
    {
        return null;
    }
    
    public List<String> getStringListValue()
    {
        return null;
    }
    
    public String getStringListValue(int index)
    {
        return null;
    }
    
    public int getLength()
    {
        return 0;
    }

    public byte[] getBytesValue()
    {
        return null;
    }

    public InputStream getInputStream()
    {
        return null;
    }

    public void close()
    {
    }

    public String toString()
    {
        return this.getName() + " => " + this.getValue();
    }

    @Override
    public int hashCode()
    {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((name == null) ? 0 : name.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj)
    {
        if (this == obj) return true;
        if (obj == null) return false;
        if (getClass() != obj.getClass()) return false;
        AbstractParameter other = (AbstractParameter) obj;
        if (name == null)
        {
            if (other.name != null) return false;
        }
        else if (!name.equals(other.name)) return false;
        return true;
    }

    @Override
    public int compareTo(Parameter o)
    {
        if (this.name.equals(o.getName()))
        {
            return Integer.compare(this.index, o.getIndex());
        }
        return this.name.compareTo(o.getName());
    }
}

@@ -9,19 +9,16 @@
 lsa SCGI
-%0A *
  Copyrig
@@ -41,19 +41,16 @@
 is Ellis
-%0A *
  All rig
@@ -136,19 +136,16 @@
  without
-%0A *
  modific
@@ -212,17 +212,16 @@
 are met:
- 
 %0A * %0A * 
@@ -298,22 +298,16 @@
 ce, this
-%0A *   
  list of
@@ -348,20 +348,16 @@
 laimer. 
-%0A * 
 2. Redis
@@ -424,22 +424,16 @@
  notice,
-%0A *   
  this li
@@ -502,14 +502,8 @@
 tion
-%0A *   
  and
@@ -553,17 +553,16 @@
 ibution.
- 
 %0A * %0A * 
@@ -640,19 +640,16 @@
  IS%22 AND
-%0A *
  ANY EXP
@@ -718,19 +718,16 @@
  IMPLIED
-%0A *
  WARRANT
@@ -789,19 +789,16 @@
 POSE ARE
-%0A *
  DISCLAI
@@ -869,19 +869,16 @@
 ABLE FOR
-%0A *
  ANY DIR
@@ -948,19 +948,16 @@
  DAMAGES
-%0A *
  (INCLUD
@@ -1025,19 +1025,16 @@
 ERVICES;
-%0A *
  LOSS OF
@@ -1101,19 +1101,16 @@
 USED AND
-%0A *
  ON ANY 
@@ -1176,19 +1176,16 @@
  OR TORT
-%0A *
  (INCLUD
@@ -1254,19 +1254,16 @@
  OF THIS
-%0A *
  SOFTWAR
@@ -1320,13 +1320,8 @@
 GE.%0A
- *  %0A
  */%0A
@@ -1411,17 +1411,16 @@
 .List;%0A%0A
-%0A
 public a
@@ -1505,20 +1505,16 @@
 g name;%0A
-    
 %0A    pri
@@ -1647,36 +1647,32 @@
  = index;%0A    %7D%0A
-    
 %0A    public Abst
@@ -1788,36 +1788,32 @@
 urn name;%0A    %7D%0A
-    
 %0A    public int 
@@ -2062,36 +2062,32 @@
 urn null;%0A    %7D%0A
-    
 %0A    public Para
@@ -2141,36 +2141,32 @@
 urn null;%0A    %7D%0A
-    
 %0A    public List
@@ -2220,36 +2220,32 @@
 urn null;%0A    %7D%0A
-    
 %0A    public Stri
@@ -2310,20 +2310,16 @@
 ;%0A    %7D%0A
-    
 %0A    pub
@@ -2614,16 +2614,46 @@
 Name() +
+ %22%5B%22 + this.getIndex() + %22%5D%22 +
  %22 =%3E %22 
@@ -2778,16 +2778,57 @@
 lt = 1;%0A
+        result = prime * result + index;%0A
         
@@ -3173,16 +3173,64 @@
 r) obj;%0A
+        if (index != other.index) return false;%0A
         
@@ -3502,38 +3502,18 @@
 Name()))
-%0A        %7B%0A          
  
+%7B
  return 
@@ -3554,24 +3554,16 @@
 ndex());
-%0A       
  %7D%0A     

Use name and index for equality