コード例 #1
0
  @Test
  public void testPairsMatching() {
    ShortArrayList keyList = new ShortArrayList();
    DoubleArrayList valueList = new DoubleArrayList();
    OpenShortDoubleHashMap map = new OpenShortDoubleHashMap();
    map.put((short) 11, (double) 22);
    map.put((short) 12, (double) 23);
    map.put((short) 13, (double) 24);
    map.put((short) 14, (double) 25);
    map.removeKey((short) 13);
    map.pairsMatching(
        new ShortDoubleProcedure() {

          @Override
          public boolean apply(short first, double second) {
            return (first % 2) == 0;
          }
        },
        keyList,
        valueList);
    keyList.sort();
    valueList.sort();
    assertEquals(2, keyList.size());
    assertEquals(2, valueList.size());
    assertEquals(12, keyList.get(0));
    assertEquals(14, keyList.get(1));
    assertEquals(23, valueList.get(0), (double) 0.000001);
    assertEquals(25, valueList.get(1), (double) 0.000001);
  }
コード例 #2
0
 @Test
 public void testEquals() {
   // since there are no other subclasses of
   // Abstractxxx available, we have to just test the
   // obvious.
   OpenShortDoubleHashMap map = new OpenShortDoubleHashMap();
   map.put((short) 11, (double) 22);
   map.put((short) 12, (double) 23);
   map.put((short) 13, (double) 24);
   map.put((short) 14, (double) 25);
   map.removeKey((short) 13);
   OpenShortDoubleHashMap map2 = (OpenShortDoubleHashMap) map.copy();
   assertEquals(map, map2);
   assertTrue(map2.equals(map));
   assertFalse("Hello Sailor".equals(map));
   assertFalse(map.equals("hello sailor"));
   map2.removeKey((short) 11);
   assertFalse(map.equals(map2));
   assertFalse(map2.equals(map));
 }
コード例 #3
0
 @Test
 public void testKeysSortedByValue() {
   OpenShortDoubleHashMap map = new OpenShortDoubleHashMap();
   map.put((short) 11, (double) 22);
   map.put((short) 12, (double) 23);
   map.put((short) 13, (double) 24);
   map.put((short) 14, (double) 25);
   map.removeKey((short) 13);
   ShortArrayList keys = new ShortArrayList();
   map.keysSortedByValue(keys);
   short[] keysArray = keys.toArray(new short[keys.size()]);
   assertArrayEquals(new short[] {11, 12, 14}, keysArray);
 }
コード例 #4
0
 @Test
 public void testValues() {
   OpenShortDoubleHashMap map = new OpenShortDoubleHashMap();
   map.put((short) 11, (double) 22);
   map.put((short) 12, (double) 23);
   map.put((short) 13, (double) 24);
   map.put((short) 14, (double) 25);
   map.removeKey((short) 13);
   DoubleArrayList values = new DoubleArrayList(100);
   map.values(values);
   assertEquals(3, values.size());
   values.sort();
   assertEquals(22, values.get(0), (double) 0.000001);
   assertEquals(23, values.get(1), (double) 0.000001);
   assertEquals(25, values.get(2), (double) 0.000001);
 }
コード例 #5
0
  @Test
  public void testForEachPair() {
    final List<Pair> pairs = new ArrayList<Pair>();
    OpenShortDoubleHashMap map = new OpenShortDoubleHashMap();
    map.put((short) 11, (double) 22);
    map.put((short) 12, (double) 23);
    map.put((short) 13, (double) 24);
    map.put((short) 14, (double) 25);
    map.removeKey((short) 13);
    map.forEachPair(
        new ShortDoubleProcedure() {

          @Override
          public boolean apply(short first, double second) {
            pairs.add(new Pair(first, second));
            return true;
          }
        });

    Collections.sort(pairs);
    assertEquals(3, pairs.size());
    assertEquals((short) 11, pairs.get(0).k);
    assertEquals((double) 22, pairs.get(0).v, (double) 0.000001);
    assertEquals((short) 12, pairs.get(1).k);
    assertEquals((double) 23, pairs.get(1).v, (double) 0.000001);
    assertEquals((short) 14, pairs.get(2).k);
    assertEquals((double) 25, pairs.get(2).v, (double) 0.000001);

    pairs.clear();
    map.forEachPair(
        new ShortDoubleProcedure() {
          int count = 0;

          @Override
          public boolean apply(short first, double second) {
            pairs.add(new Pair(first, second));
            count++;
            return count < 2;
          }
        });

    assertEquals(2, pairs.size());
  }
コード例 #6
0
  @Test
  public void testForEachKey() {
    final ShortArrayList keys = new ShortArrayList();
    OpenShortDoubleHashMap map = new OpenShortDoubleHashMap();
    map.put((short) 11, (double) 22);
    map.put((short) 12, (double) 23);
    map.put((short) 13, (double) 24);
    map.put((short) 14, (double) 25);
    map.removeKey((short) 13);
    map.forEachKey(
        new ShortProcedure() {

          @Override
          public boolean apply(short element) {
            keys.add(element);
            return true;
          }
        });

    short[] keysArray = keys.toArray(new short[keys.size()]);
    Arrays.sort(keysArray);

    assertArrayEquals(new short[] {11, 12, 14}, keysArray);
  }