Package elemental.util

Examples of elemental.util.MapFromStringToInt


  /**
   * Tests {@link MapFromStringToInt}.
   */
  public void testMapsFromStringsToInts() {
    // This is our test subject.
    final MapFromStringToInt map = Collections.mapFromStringToInt();

    // These are his keys.
    final String[] keys = new String[] {"key-1", "key-2", "key-3"};

    // These are the values for those keys.
    final int[] vals = new int[] {0, 1, 2};

    // Let's put those values in.
    for (int i = 0, n = keys.length; i < n; ++i) {
      map.put(keys[i], vals[i]);
    }

    // Are they all in the right place?
    for (int i = 0, n = keys.length; i < n; ++i) {
      assertTrue(map.hasKey(keys[i]));
      assertEquals(vals[i], map.get(keys[i]));
    }

    // These are some new values.
    final int[] newVals = new int[] {3, 4, 5};

    // Let's update those keys, ok.
    for (int i = 0, n = keys.length; i < n; ++i) {
      map.put(keys[i], newVals[i]);
    }

    // Are they all in the right place?
    for (int i = 0, n = keys.length; i < n; ++i) {
      assertTrue(map.hasKey(keys[i]));
      assertEquals(newVals[i], map.get(keys[i]));
    }

    checkMapContents(map, keys, newVals);

    // Let's remove a key, did it go away?
    map.remove(keys[0]);
    assertFalse(map.hasKey(keys[0]));
  }
View Full Code Here

TOP

Related Classes of elemental.util.MapFromStringToInt

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.