gt:             if (!compare(realValue, value)) {
context: /*
   * Copyright (C) 2014 The Android Open Source Project
   *
   * 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 android.util.cts;
  
  import android.os.Bundle;
  import android.os.Parcel;
  import android.os.Parcelable;
  import android.test.AndroidTestCase;
  import android.util.ArrayMap;
  import android.util.Log;
  
  import java.lang.reflect.InvocationTargetException;
  import java.lang.reflect.Method;
  import java.util.Collection;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Map;
  import java.util.Set;
  
  public class ArrayMapTest extends AndroidTestCase {
      static final boolean DEBUG = false;
  
      static final int OP_ADD = 1;
      static final int OP_REM = 2;
  
      static int[] OPS = new int[] {
              OP_ADD, OP_ADD, OP_ADD, OP_ADD, OP_ADD, OP_ADD, OP_ADD, OP_ADD, OP_ADD,
              OP_ADD, OP_ADD, OP_ADD, OP_ADD, OP_ADD, OP_ADD, OP_ADD, OP_ADD, OP_ADD,
              OP_REM, OP_REM, OP_REM, OP_REM, OP_REM, OP_REM, OP_REM, OP_REM, OP_REM,
              OP_REM, OP_REM, OP_REM, OP_REM, OP_REM, OP_REM, OP_REM, OP_REM, OP_REM,
  
              OP_ADD, OP_ADD, OP_ADD, OP_ADD, OP_ADD, OP_ADD, OP_ADD, OP_ADD, OP_ADD,
              OP_REM, OP_REM, OP_REM, OP_REM, OP_REM, OP_REM, OP_REM, OP_REM, OP_REM,
  
              OP_ADD, OP_ADD, OP_ADD, OP_ADD, OP_ADD, OP_ADD, OP_ADD, OP_ADD, OP_ADD,
              OP_REM, OP_REM, OP_REM, OP_REM, OP_REM, OP_REM, OP_REM, OP_REM, OP_REM,
  
              OP_ADD, OP_ADD, OP_ADD, OP_ADD, OP_ADD, OP_ADD, OP_ADD, OP_ADD, OP_ADD,
              OP_REM, OP_REM, OP_REM, OP_REM, OP_REM, OP_REM, OP_REM, OP_REM, OP_REM,
  
              OP_ADD, OP_ADD, OP_ADD, OP_ADD, OP_ADD, OP_ADD, OP_ADD, OP_ADD, OP_ADD,
              OP_ADD, OP_ADD, OP_ADD, OP_ADD, OP_ADD, OP_ADD, OP_ADD, OP_ADD, OP_ADD,
              OP_ADD, OP_ADD, OP_ADD,
              OP_REM, OP_REM, OP_REM, OP_REM, OP_REM, OP_REM, OP_REM, OP_REM, OP_REM,
              OP_REM, OP_REM, OP_REM,
              OP_REM, OP_REM, OP_REM, OP_REM, OP_REM, OP_REM, OP_REM, OP_REM, OP_REM,
      };
  
      static int[] KEYS = new int[] {
              // General adding and removing.
                -1,   1900,    600,    200,   1200,   1500,   1800,    100,   1900,
              2100,    300,    800,    600,   1100,   1300,   2000,   1000,   1400,
               600,     -1,   1900,    600,    300,   2100,    200,    800,    800,
              1800,   1500,   1300,   1100,   2000,   1400,   1000,   1200,   1900,
  
              // Shrink when removing item from end.
               100,    200,    300,    400,    500,    600,    700,    800,    900,
               900,    800,    700,    600,    500,    400,    300,    200,    100,
  
              // Shrink when removing item from middle.
               100,    200,    300,    400,    500,    600,    700,    800,    900,
               900,    800,    700,    600,    500,    400,    200,    300,    100,
  
              // Shrink when removing item from front.
               100,    200,    300,    400,    500,    600,    700,    800,    900,
               900,    800,    700,    600,    500,    400,    100,    200,    300,
  
              // Test hash collisions.
               105,    106,    108,    104,    102,    102,    107,      5,    205,
                 4,    202,    203,      3,      5,    101,    109,    200,    201,
                 0,     -1,    100,
               106,    108,    104,    102,    103,    105,    107,    101,    109,
                -1,    100,      0,
                 4,      5,      3,      5,    200,    203,    202,    201,    205,
      };
  
      public static class ControlledHash implements Parcelable {
          final int mValue;
  
          ControlledHash(int value) {
              mValue = value;
          }
  
          @Override
          public final boolean equals(Object o) {
              if (o == null) {
                  return false;
              }
              return mValue == ((ControlledHash)o).mValue;
          }
  
          @Override
          public final int hashCode() {
              return mValue/100;
          }
  
          @Override
          public final String toString() {
              return Integer.toString(mValue);
          }
  
          @Override
          public int describeContents() {
              return 0;
          }
  
          @Override
          public void writeToParcel(Parcel dest, int flags) {
              dest.writeInt(mValue);
          }
  
          public static final Parcelable.Creator<ControlledHash> CREATOR
                  = new Parcelable.Creator<ControlledHash>() {
              public ControlledHash createFromParcel(Parcel in) {
                  return new ControlledHash(in.readInt());
              }
  
              public ControlledHash[] newArray(int size) {
                  return new ControlledHash[size];
              }
          };
      }
  
      private static boolean compare(Object v1, Object v2) {
          if (v1 == null) {
              return v2 == null;
          }
          if (v2 == null) {
              return false;
          }
          return v1.equals(v2);
      }
  
      private static void compareMaps(HashMap map, ArrayMap array) {
          if (map.size() != array.size()) {
              fail("Bad size: expected " + map.size() + ", got " + array.size());
          }
  
          Set<Map.Entry> mapSet = map.entrySet();
          for (Map.Entry entry : mapSet) {
              Object expValue = entry.getValue();
              Object gotValue = array.get(entry.getKey());
              if (!compare(expValue, gotValue)) {
                  fail("Bad value: expected " + expValue + ", got " + gotValue
                          + " at key " + entry.getKey());
              }
          }
  
          for (int i=0; i<array.size(); i++) {
              Object gotValue = array.valueAt(i);
              Object key = array.keyAt(i);
              Object expValue = map.get(key);
              if (!compare(expValue, gotValue)) {
                  fail("Bad value: expected " + expValue + ", got " + gotValue
                          + " at key " + key);
              }
          }
  
          if (map.entrySet().hashCode() != array.entrySet().hashCode()) {
              fail("Entry set hash codes differ: map=0x"
                      + Integer.toHexString(map.entrySet().hashCode()) + " array=0x"
                      + Integer.toHexString(array.entrySet().hashCode()));
          }
  
          if (!map.entrySet().equals(array.entrySet())) {
              fail("Failed calling equals on map entry set against array set");
          }
  
          if (!array.entrySet().equals(map.entrySet())) {
              fail("Failed calling equals on array entry set against map set");
          }
  
          if (map.keySet().hashCode() != array.keySet().hashCode()) {
              fail("Key set hash codes differ: map=0x"
                      + Integer.toHexString(map.keySet().hashCode()) + " array=0x"
                      + Integer.toHexString(array.keySet().hashCode()));
          }
  
          if (!map.keySet().equals(array.keySet())) {
              fail("Failed calling equals on map key set against array set");
          }
  
          if (!array.keySet().equals(map.keySet())) {
              fail("Failed calling equals on array key set against map set");
          }
  
          if (!map.keySet().containsAll(array.keySet())) {
              fail("Failed map key set contains all of array key set");
          }
  
          if (!array.keySet().containsAll(map.keySet())) {
              fail("Failed array key set contains all of map key set");
          }
  
          if (!array.containsAll(map.keySet())) {
              fail("Failed array contains all of map key set");
          }
  
          if (!map.entrySet().containsAll(array.entrySet())) {
              fail("Failed map entry set contains all of array entry set");
          }
  
          if (!array.entrySet().containsAll(map.entrySet())) {
              fail("Failed array entry set contains all of map entry set");
          }
      }
  
      private static void validateArrayMap(ArrayMap array) {
          Set<Map.Entry> entrySet = array.entrySet();
          int index=0;
          Iterator<Map.Entry> entryIt = entrySet.iterator();
          while (entryIt.hasNext()) {
              Map.Entry entry = entryIt.next();
              Object value = entry.getKey();
              Object realValue = array.keyAt(index);
  