/**
  * Returns true if the option is present in the specified internal option container, otherwise
  * false.
  *
  * @param type the internal option container
  * @param option the option object
  * @return true if the option is present in the specified internal option container, otherwise
  *     false
  * @throws OptionException
  */
 public boolean contains(int type, Option option) throws OptionException {
   if (type == OptionContainer.SAVEDOPTION) {
     return savedOptionMap.containsValue(option);
   } else if (type == OptionContainer.DEPENDENCIES_RESOLVED) {
     return dependenciesResolvedOptionMap.containsValue(option);
   } else if (type == OptionContainer.COMMANDLINE) {
     return commandLineOptionMap.containsValue(option);
   } else if (type == OptionContainer.OPTIONFILE) {
     return optionFileOptionMap.containsValue(option);
   } else {
     throw new OptionException("Unknown option container type");
   }
 }
Exemple #2
0
 public boolean contains(Construct c) {
   if (associative_mode) {
     return associative_array.containsValue(c);
   } else {
     return array.contains(c);
   }
 }
Exemple #3
0
 public boolean containsValue(Object value) {
   return map.containsValue(value);
 }
 public boolean containsValue(Object o) {
   checkInit();
   return delegate.containsValue(o);
 }
  private <K, V> void checkIndex(
      EntityIndex<K, V> index,
      SortedMap<Integer, SortedSet<Integer>> expected,
      Getter<K> kGetter,
      Getter<V> vGetter)
      throws DatabaseException {

    SortedMap<K, V> map = index.sortedMap();

    Transaction txn = txnBegin();
    for (int i : expected.keySet()) {
      K k = kGetter.fromInt(i);
      SortedSet<Integer> dups = expected.get(i);
      if (dups.isEmpty()) {

        /* EntityIndex */
        V v = index.get(txn, k, null);
        assertNull(v);
        assertTrue(!index.contains(txn, k, null));

        /* Map/Collection */
        v = map.get(i);
        assertNull(v);
        assertTrue(!map.containsKey(i));
      } else {
        int j = dups.first();

        /* EntityIndex */
        V v = index.get(txn, k, null);
        assertNotNull(v);
        assertEquals(j, vGetter.getKey(v));
        assertTrue(index.contains(txn, k, null));

        /* Map/Collection */
        v = map.get(i);
        assertNotNull(v);
        assertEquals(j, vGetter.getKey(v));
        assertTrue(map.containsKey(i));
        assertTrue("" + i + ' ' + j + ' ' + v + ' ' + map, map.containsValue(v));
        assertTrue(map.keySet().contains(i));
        assertTrue(map.values().contains(v));
        assertTrue(map.entrySet().contains(new MapEntryParameter(i, v)));
      }
    }
    txnCommit(txn);

    int keysSize = expandKeySize(expected);
    int valuesSize = expandValueSize(expected);

    /* EntityIndex.count */
    assertEquals("keysSize=" + keysSize, valuesSize, index.count());

    /* Map/Collection size */
    assertEquals(valuesSize, map.size());
    assertEquals(valuesSize, map.values().size());
    assertEquals(valuesSize, map.entrySet().size());
    assertEquals(keysSize, map.keySet().size());

    /* Map/Collection isEmpty */
    assertEquals(valuesSize == 0, map.isEmpty());
    assertEquals(valuesSize == 0, map.values().isEmpty());
    assertEquals(valuesSize == 0, map.entrySet().isEmpty());
    assertEquals(keysSize == 0, map.keySet().isEmpty());

    txn = txnBeginCursor();

    /* Unconstrained cursors. */
    checkCursor(index.keys(txn, null), map.keySet(), true, expandKeys(expected), kGetter);
    checkCursor(index.entities(txn, null), map.values(), false, expandValues(expected), vGetter);

    /* Range cursors. */
    if (expected.isEmpty()) {
      checkOpenRanges(txn, 0, index, expected, kGetter, vGetter);
      checkClosedRanges(txn, 0, 1, index, expected, kGetter, vGetter);
    } else {
      int firstKey = expected.firstKey();
      int lastKey = expected.lastKey();
      for (int i = firstKey - 1; i <= lastKey + 1; i += 1) {
        checkOpenRanges(txn, i, index, expected, kGetter, vGetter);
        int j = i + 1;
        if (j < lastKey + 1) {
          checkClosedRanges(txn, i, j, index, expected, kGetter, vGetter);
        }
      }
    }

    txnCommit(txn);
  }
Exemple #6
0
  private <K, V> void verify(
      SortedMap<K, V> immutableMap, SortedMap<K, V> mutableMap, K key1, K key2, V value) {
    try {
      immutableMap.clear();

      Assert.assertTrue(mutableMap.isEmpty());
    } catch (UnsupportedOperationException e) {
      Assert.assertFalse(mutableMap.isEmpty());
    }

    Assert.assertEquals(immutableMap.containsKey(key1), mutableMap.containsKey(key1));
    Assert.assertEquals(immutableMap.containsKey(key2), mutableMap.containsKey(key2));

    Assert.assertEquals(immutableMap.containsValue(value), mutableMap.containsValue(value));
    Assert.assertEquals(immutableMap.containsValue(null), mutableMap.containsValue(null));

    Assert.assertEquals(immutableMap.entrySet(), mutableMap.entrySet());

    Assert.assertEquals(immutableMap.get(key1), mutableMap.get(key1));
    Assert.assertEquals(immutableMap.get(key2), mutableMap.get(key2));

    Assert.assertEquals(immutableMap.isEmpty(), mutableMap.isEmpty());

    Assert.assertEquals(immutableMap.keySet(), mutableMap.keySet());

    try {
      immutableMap.put(key1, value);
      Assert.fail();
    } catch (UnsupportedOperationException e) {
    }

    try {
      immutableMap.putAll(java.util.Collections.singletonMap(key1, value));
      Assert.fail();
    } catch (UnsupportedOperationException e) {
    }

    try {
      immutableMap.remove(key1);
    } catch (UnsupportedOperationException e) {
    }

    Assert.assertEquals(immutableMap.size(), mutableMap.size());

    // Is it OK that this fails?
    // Assert.assertEquals(immutableMap.values(), mutableMap.values());
    Assert.assertEquals(immutableMap.values().size(), mutableMap.values().size());
    if (!mutableMap.isEmpty()) {
      Assert.assertEquals(
          immutableMap.values().iterator().next(), mutableMap.values().iterator().next());
    }

    Assert.assertSame(immutableMap.comparator(), mutableMap.comparator());

    if (!mutableMap.isEmpty()) {
      Assert.assertEquals(immutableMap.firstKey(), mutableMap.firstKey());
      Assert.assertEquals(immutableMap.lastKey(), mutableMap.lastKey());
    } else {
      try {
        immutableMap.firstKey();
        Assert.fail();
      } catch (NoSuchElementException e) {
      }

      try {
        immutableMap.lastKey();
        Assert.fail();
      } catch (NoSuchElementException e) {
      }
    }

    Assert.assertEquals(immutableMap.headMap(key1), mutableMap.headMap(key1));
    Assert.assertEquals(immutableMap.headMap(key2), mutableMap.headMap(key2));

    Assert.assertEquals(immutableMap.subMap(key1, key2), mutableMap.subMap(key1, key2));

    Assert.assertEquals(immutableMap.tailMap(key1), mutableMap.tailMap(key1));
    Assert.assertEquals(immutableMap.tailMap(key2), mutableMap.tailMap(key2));
  }