예제 #1
0
 public Iterator<Item> iterator() {
   return items.iterator();
 }
예제 #2
0
 public Item deleteItem(int id) {
   return items.delete(id);
 }
예제 #3
0
 public Item getItem(int id) {
   return items.get(id);
 }
예제 #4
0
 public boolean addItem(Item item) {
   return items.add(item);
 }
예제 #5
0
 // access the items that belong to the category
 public int itemCount() {
   return items.size();
 }
예제 #6
0
  @Test
  public void testReadableMap() {
    final IterableMap<String, Integer> map = SplitMapUtils.readableMap(transformedMap);

    // basic
    for (int i = 0; i < 10; i++) {
      assertFalse(map.containsValue(String.valueOf(i)));
      assertEquals(i, map.get(String.valueOf(i)).intValue());
    }

    // mapIterator
    final MapIterator<String, Integer> it = map.mapIterator();
    while (it.hasNext()) {
      final String k = it.next();
      assertEquals(k, it.getKey());
      assertEquals(Integer.valueOf(k), it.getValue());
    }

    // unmodifiable
    assertTrue(map instanceof Unmodifiable);

    // check individual operations
    int sz = map.size();

    attemptPutOperation(
        new Runnable() {
          public void run() {
            map.clear();
          }
        });

    assertEquals(sz, map.size());

    attemptPutOperation(
        new Runnable() {
          public void run() {
            map.put("foo", 100);
          }
        });

    final HashMap<String, Integer> m = new HashMap<String, Integer>();
    m.put("foo", 100);
    m.put("bar", 200);
    m.put("baz", 300);
    attemptPutOperation(
        new Runnable() {
          public void run() {
            map.putAll(m);
          }
        });

    // equals, hashcode
    final IterableMap<String, Integer> other = SplitMapUtils.readableMap(transformedMap);
    assertEquals(other, map);
    assertEquals(other.hashCode(), map.hashCode());

    // remove
    for (int i = 0; i < 10; i++) {
      assertEquals(i, map.remove(String.valueOf(i)).intValue());
      assertEquals(--sz, map.size());
    }
    assertTrue(map.isEmpty());
    assertSame(map, SplitMapUtils.readableMap(map));
  }