Example usage for java.util SortedMap containsValue

List of usage examples for java.util SortedMap containsValue

Introduction

In this page you can find the example usage for java.util SortedMap containsValue.

Prototype

boolean containsValue(Object value);

Source Link

Document

Returns true if this map maps one or more keys to the specified value.

Usage

From source file:org.wso2.carbon.metrics.impl.ReporterTest.java

public void testJMXReporter() {
    AttributeList meterAttributes = getAttributes(meterName, "Count");
    SortedMap<String, Object> meterMap = values(meterAttributes);
    assertTrue("Meter is available", meterMap.containsKey("Count"));
    assertTrue("Meter count is one", meterMap.containsValue(1L));

    AttributeList gaugeAttributes = getAttributes(gaugeName, "Value");
    SortedMap<String, Object> gaugeMap = values(gaugeAttributes);
    assertTrue("Gauge is available", gaugeMap.containsKey("Value"));
    assertTrue("Gauge value is one", gaugeMap.containsValue(1));
}

From source file:lti.LaunchRequest.java

private void init(Map<String, String> paramMap) {
    this.lti_message_type = paramMap.get("lti_message_type");
    this.lti_version = paramMap.get("lti_version");
    this.resource_link_id = paramMap.get("resource_link_id");
    this.resource_link_title = paramMap.get("resource_link_title");
    this.resource_link_description = paramMap.get("resource_link_description");
    this.user_id = paramMap.get("user_id");
    this.user_image = paramMap.get("user_image");
    this.roles = paramMap.get("roles");
    this.role_scope_mentor = paramMap.get("role_scope_mentor");
    this.lis_person_name_given = paramMap.get("lis_person_name_given");
    this.lis_person_name_family = paramMap.get("lis_person_name_family");
    this.lis_person_name_full = paramMap.get("lis_person_name_full");
    this.lis_person_contact_email_primary = paramMap.get("lis_person_contact_email_primary");
    this.lis_outcome_service_url = paramMap.get("lis_outcome_service_url");
    this.lis_result_sourcedid = paramMap.get("lis_result_sourcedid");
    this.context_id = paramMap.get("context_id");
    this.context_type = paramMap.get("context_type");
    this.context_title = paramMap.get("context_title");
    this.context_label = paramMap.get("context_label");
    this.launch_presentation_locale = paramMap.get("launch_presentation_locale");
    this.launch_presentation_document_target = paramMap.get("launch_presentation_document_target");
    this.launch_presentation_css_url = paramMap.get("launch_presentation_css_url");
    this.launch_presentation_width = paramMap.get("launch_presentation_width");
    this.launch_presentation_width = paramMap.get("launch_presentation_width");
    this.launch_presentation_return_url = paramMap.get("launch_presentation_return_url");
    this.tool_consumer_info_product_family_code = paramMap.get("tool_consumer_info_product_family_code");
    this.tool_consumer_info_version = paramMap.get("tool_consumer_info_version");
    this.tool_consumer_instance_guid = paramMap.get("tool_consumer_instance_guid");
    this.tool_consumer_instance_name = paramMap.get("tool_consumer_instance_name");
    this.tool_consumer_instance_description = paramMap.get("tool_consumer_instance_description");
    this.tool_consumer_instance_url = paramMap.get("tool_consumer_instance_url");
    this.tool_consumer_instance_contact_email = paramMap.get("tool_consumer_instance_contact_email");
    this.oauth_consumer_key = paramMap.get("oauth_consumer_key");
    this.oauth_timestamp = paramMap.get("oauth_timestamp");
    this.oauth_nonce = paramMap.get("oauth_nonce");
    this.oauth_signature = paramMap.get("oauth_signature");
    this.oauth_signature_method = paramMap.get("oauth_signature_method");
    this.oauth_version = paramMap.get("oauth_version");
    this.oauth_callback = paramMap.get("oauth_callback");

    // I'm not excited about this solution, but the only way to find unknown
    // params// ww  w.  j a  v  a  2 s.  co m
    // is to check to see if they already exist. Get the sorted map at this
    // point
    // and check
    SortedMap<String, String> currentSM = this.toSortedMap();

    if (paramMap != null && !paramMap.isEmpty()) {
        Set<String> keys = paramMap.keySet();
        if (keys != null && !keys.isEmpty()) {
            for (Map.Entry<String, String> entry : paramMap.entrySet()) {
                if (entry.getKey() != null && entry.getKey().startsWith("custom_")) {
                    if (this.custom == null) {
                        this.custom = new HashMap<>();
                    }

                    this.custom.put(entry.getKey(), entry.getValue());
                } else if (entry.getKey() != null && entry.getKey().startsWith("ext_")) {
                    if (this.ext == null) {
                        this.ext = new HashMap<>();
                    }

                    this.ext.put(entry.getKey(), entry.getValue());
                } else {

                    // If we don't have the key at this point, it's likely a
                    // unknown type that we didn't account for. We still need
                    // to add it for the oauth comparison
                    if (currentSM != null && !currentSM.containsValue(entry.getKey())) {
                        if (this.extra == null) {
                            this.extra = new HashMap<>();
                        }
                        this.extra.put(entry.getKey(), entry.getValue());
                    }
                }
            }
        }
    }
}

From source file:com.google.gwt.emultest.java.util.TreeMapTest.java

/**
 * Test method for 'java.util.Map.put(Object, Object)'. This test shows some
 * bad behavior of the TreeMap class before JDK 7. A mapping with null key can
 * be put in but several methods are are unusable afterward.
 *
 * A SortedMap with natural ordering (no comparator) is supposed to throw a
 * null pointer exception if a null keys are "not supported". For a natural
 * ordered TreeMap before JDK 7, a null pointer exception is not thrown. But,
 * the map is left in a state where any other key based methods result in a
 * null pointer exception./*  ww w.j a  v  a 2s.com*/
 *
 * @see java.util.Map#put(Object, Object)
 */
public void testPut_nullKey() {
    K[] keys = getSortedKeys();
    V[] values = getSortedValues();
    SortedMap<K, V> sortedMap = createNavigableMap();

    if (useNullKey()) {
        assertNull(sortedMap.put(null, values[0]));
        assertTrue(sortedMap.containsValue(values[0]));

        // the map methods the continue to function
        sortedMap.containsValue(null);
        sortedMap.containsValue(values[0]);
        sortedMap.entrySet();
        sortedMap.equals(createMap());
        sortedMap.hashCode();
        sortedMap.isEmpty();
        sortedMap.keySet();
        sortedMap.putAll(createMap());
        sortedMap.size();
        sortedMap.values();

        // all of the sorted map methods still function
        sortedMap.comparator();
        sortedMap.firstKey();
        sortedMap.lastKey();
        sortedMap.subMap(getLessThanMinimumKey(), getGreaterThanMaximumKey());
        sortedMap.headMap(getLessThanMinimumKey());
        sortedMap.tailMap(getLessThanMinimumKey());
    } else if (TestUtils.getJdkVersion() > 6) {
        // nulls are rejected immediately and don't poison the map anymore
        try {
            assertNull(sortedMap.put(null, values[0]));
            fail("should have thrown");
        } catch (NullPointerException e) {
            // expected outcome
        }
        try {
            assertNull(sortedMap.put(null, values[1]));
            fail("expected exception adding second null");
        } catch (NullPointerException e) {
            // expected outcome
        }
        try {
            sortedMap.containsKey(null);
            fail("expected exception on containsKey(null)");
        } catch (NullPointerException e) {
            // expected outcome
        }
        sortedMap.containsKey(keys[0]);
        try {
            sortedMap.get(null);
            fail("expected exception on get(null)");
        } catch (NullPointerException e) {
            // expected outcome
        }
        sortedMap.get(keys[0]);
        try {
            sortedMap.remove(null);
        } catch (NullPointerException e) {
            // expected
        }
        sortedMap.remove(keys[0]);
    } else {
        // before JDK 7, nulls poisoned the map
        try {
            assertNull(sortedMap.put(null, values[0]));
            // note: first null added is not required to throw NPE since no
            // comparisons are needed
        } catch (NullPointerException e) {
            // expected outcome
        }
        try {
            assertNull(sortedMap.put(null, values[1]));
            fail("expected exception adding second null");
        } catch (NullPointerException e) {
            // expected outcome
        }
        try {
            sortedMap.containsKey(null);
            fail("expected exception on containsKey(null)");
        } catch (NullPointerException e) {
            // expected outcome
        }
        try {
            sortedMap.containsKey(keys[0]);
            fail("expected exception on contains(key)");
        } catch (NullPointerException e) {
            // expected outcome
        }
        try {
            sortedMap.get(null);
            fail("expected exception on get(null)");
        } catch (NullPointerException e) {
            // expected outcome
        }
        try {
            sortedMap.get(keys[0]);
            fail("expected exception on get(key)");
        } catch (NullPointerException e) {
            // expected outcome
        }
        try {
            sortedMap.remove(null);
            fail("expected exception on remove(null)");
        } catch (NullPointerException e) {
            // expected outcome
        }
        try {
            sortedMap.remove(keys[0]);
            fail("expected exception on remove(key)");
        } catch (NullPointerException e) {
            // expected outcome
        }
    }
}

From source file:com.google.gwt.emultest.java.util.TreeMapTest.java

public void testSubMap_entrySet() {
    K[] keys = getSortedKeys();/* w w  w .  ja v  a 2 s.com*/
    V[] values = getSortedValues();
    NavigableMap<K, V> map = createNavigableMap();
    map.put(keys[0], values[0]);
    map.put(keys[1], values[1]);
    map.put(keys[2], values[2]);
    map.put(keys[3], values[3]);

    SortedMap<K, V> subMap = map.subMap(keys[1], keys[3]);
    Set<Entry<K, V>> entries = subMap.entrySet();
    assertEquals(2, subMap.size());
    assertEquals(subMap.size(), entries.size());
    assertFalse(entries.contains(new SimpleEntry<K, V>(keys[0], values[0])));
    assertTrue(entries.contains(new SimpleEntry<K, V>(keys[1], values[1])));
    assertTrue(entries.contains(new SimpleEntry<K, V>(keys[2], values[2])));
    assertFalse(entries.contains(new SimpleEntry<K, V>(keys[3], values[3])));

    entries.remove(new SimpleEntry<K, V>(keys[1], values[1]));
    assertEquals(3, map.size());
    assertEquals(subMap.size(), entries.size());
    assertFalse(entries.contains(new SimpleEntry<K, V>(keys[1], values[1])));
    assertFalse(subMap.containsKey(keys[1]));
    assertFalse(subMap.containsValue(values[1]));

    entries.clear();
    assertEquals(2, map.size());
    assertEquals(subMap.size(), entries.size());
    assertTrue(entries.isEmpty());
    assertTrue(subMap.isEmpty());

    subMap.put(keys[2], values[2]);
    assertEquals(1, subMap.size());
    assertEquals(subMap.size(), entries.size());

    subMap.put(keys[1], values[1]);
    Iterator<Entry<K, V>> it = entries.iterator();
    while (it.hasNext()) {
        Map.Entry<K, V> entry = it.next();
        subMap.containsKey(entry.getKey());
        subMap.containsValue(entry.getValue());
        it.remove();
    }
    try {
        it.next();
        fail("should throw NoSuchElementException");
    } catch (NoSuchElementException expected) {
    }
    assertEquals(2, map.size());
    assertEquals(0, subMap.size());
    assertEquals(subMap.size(), entries.size());

    map = createNavigableMap();
    Set<Entry<K, V>> entrySet = map.entrySet();
    map.put(keys[0], values[0]);
    map.put(keys[1], values[1]);
    map.put(keys[2], values[2]);
    assertEquals(map.size(), entrySet.size());
    _assertEquals(entrySet, map.entrySet());
    map.clear();
    assertEquals(map.size(), entrySet.size());
    _assertEquals(entrySet, map.entrySet());
    map.put(keys[0], values[0]);
    assertEquals(map.size(), entrySet.size());
    _assertEquals(entrySet, map.entrySet());
    entrySet.clear();
    assertEquals(map.size(), entrySet.size());
    _assertEquals(entrySet, map.entrySet());
}

From source file:com.google.gwt.emultest.java.util.TreeMapTest.java

public void testHeadMapLjava_lang_ObjectZL() {
    K[] keys = getSortedKeys();/*from w  ww .  j  a  v a 2 s. c o m*/
    V[] values = getSortedValues();
    NavigableMap<K, V> map = createNavigableMap();
    for (int i = 0; i < keys.length; i++) {
        map.put(keys[i], values[i]);
    }

    // normal case
    SortedMap<K, V> subMap = map.headMap(keys[2], true);
    assertEquals(3, subMap.size());
    subMap = map.headMap(keys[3], true);
    assertEquals(4, subMap.size());
    for (int i = 0; i < 4; i++) {
        assertEquals(values[i], subMap.get(keys[i]));
    }
    subMap = map.headMap(keys[2], false);
    assertEquals(2, subMap.size());
    assertNull(subMap.get(keys[3]));

    // Exceptions
    assertEquals(0, map.headMap(keys[0], false).size());

    try {
        map.headMap(null, true);
        assertTrue("expected exception", useNullKey());
    } catch (NullPointerException e) {
        assertFalse("unexpected NPE", useNullKey());
    }

    try {
        map.headMap(null, false);
        assertTrue("expected exception", useNullKey());
    } catch (NullPointerException e) {
        assertFalse("unexpected NPE", useNullKey());
    }

    subMap = map.headMap(keys[2]);
    assertEquals(2, subMap.size());
    try {
        subMap.put(keys[2], values[2]);
        fail("should throw IllegalArgumentException");
    } catch (IllegalArgumentException expected) {
    }
    assertEquals(keys.length, map.size());
    subMap = map.headMap(keys[2], true);
    assertEquals(3, subMap.size());
    subMap.remove(keys[1]);
    assertFalse(subMap.containsKey(keys[1]));
    assertFalse(subMap.containsValue(values[1]));
    assertFalse(map.containsKey(keys[1]));
    assertFalse(map.containsValue(values[1]));
    assertEquals(2, subMap.size());
    assertEquals(keys.length - 1, map.size());

    subMap.put(keys[1], values[1]);

    try {
        subMap.subMap(keys[1], keys[3]);
        fail("should throw IllegalArgumentException");
    } catch (IllegalArgumentException expected) {
    }
    try {
        subMap.subMap(keys[3], keys[1]);
        fail("should throw IllegalArgumentException");
    } catch (IllegalArgumentException expected) {
    }

    if (useNullKey() && useNullValue()) {
        map.put(null, null);

        subMap = map.headMap(null, true);
        assertEquals(1, subMap.size());
        assertTrue(subMap.containsValue(null));
        assertNull(subMap.get(null));

        subMap = map.subMap(null, false, keys[2], true);
        assertEquals(3, subMap.size());

        Set<K> keySet = subMap.keySet();
        assertEquals(3, keySet.size());

        Set<Map.Entry<K, V>> entrySet = subMap.entrySet();
        assertEquals(3, entrySet.size());

        Collection<V> valueCollection = subMap.values();
        assertEquals(3, valueCollection.size());

        map.remove(null);
    }

    // head map of head map
    NavigableMap<K, V> headMap = map.headMap(keys[3], true);
    assertEquals(4, headMap.size());
    headMap = headMap.headMap(keys[3], false);
    assertEquals(3, headMap.size());
    headMap = headMap.headMap(keys[2], false);
    assertEquals(2, headMap.size());
    headMap = headMap.tailMap(keys[0], false);
    assertEquals(1, headMap.size());
    headMap = headMap.tailMap(keys[1], false);
    assertEquals(0, headMap.size());
}

From source file:org.codetrack.database.file.FileProject.java

/**
 * Verify if item is saved in the project graph
 * @param itemClass - class of item object
 * @param item - item instance/* w ww .j a v a  2s . co m*/
 * @param <T> - generic class
 * @return true if item is in the project data graph
 */
public <T> boolean containsItem(Class itemClass, T item) {

    SortedMap<String, ProjectItem> map = lazyMap(item.getClass());

    if (MapUtils.isNotEmpty(map)) {
        return map.containsValue(item);
    } else
        return false;

}