/*
Copyright 2011 Frederic Langlet
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
you may obtain a copy of the License at

                http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package kanzi;


public final class IndexedIntArray
{
    public int[] array;
    public int index;
    
    
    public IndexedIntArray(int[] array, int idx)
    {
        if (array == null)
           throw new NullPointerException("The array cannot be null");
        
        this.array = array;
        this.index = idx;
    }
    
    
    @Override
    public boolean equals(Object o)
    {
        try
        {
            if (this == o)
               return true;

            IndexedIntArray iba = (IndexedIntArray) o;
            return ((this.array == iba.array) && (this.index == iba.index));
        }
        catch (ClassCastException e)
        {
            return false;
        }
        catch (NullPointerException e)
        {
            return false;
        }
    }
        

    @Override
    public int hashCode()
    {
       // Non constant !
       return (this.index + (17 * this.array.hashCode()));
    }


    @Override
    public String toString()
    {
        StringBuilder builder = new StringBuilder(100);
        builder.append("[");
        builder.append(this.array.toString());
        builder.append(","); 
        builder.append(this.index); 
        builder.append("]"); 
        return builder.toString();
    }
}

@@ -980,32 +980,89 @@
   try%0A        %7B%0A
+            if (o == null)%0A               return false;%0A%0A
             if (
@@ -1068,24 +1068,24 @@
 (this == o)%0A
-
             
@@ -1330,93 +1330,8 @@
   %7D%0A
-        catch (NullPointerException e)%0A        %7B%0A            return false;%0A        %7D%0A
     
@@ -1427,17 +1427,16 @@
  return 
-(
 this.ind
@@ -1440,16 +1440,43 @@
 index + 
+((this.array == null) ? 0 :
 (17 * th
@@ -1659,24 +1659,39 @@
 lder.append(
+String.valueOf(
 this.array.t
@@ -1688,26 +1688,16 @@
 is.array
-.toString(
 ));%0A    

Add defensive code