Search in sources :

Example 6 with EnumMap

use of java.util.EnumMap in project gradle by gradle.

the class JvmLocalLibraryMetaDataAdapter method createLocalComponentMetaData.

@Override
@SuppressWarnings("unchecked")
public DefaultLibraryLocalComponentMetadata createLocalComponentMetaData(Binary selectedBinary, String projectPath, boolean toAssembly) {
    EnumMap<UsageKind, Iterable<DependencySpec>> dependenciesPerUsage = new EnumMap<UsageKind, Iterable<DependencySpec>>(UsageKind.class);
    EnumMap<UsageKind, List<PublishArtifact>> artifacts = new EnumMap<UsageKind, List<PublishArtifact>>(UsageKind.class);
    initializeUsages(dependenciesPerUsage, artifacts);
    if (selectedBinary instanceof JarBinarySpecInternal) {
        JarBinarySpecInternal jarBinarySpec = (JarBinarySpecInternal) selectedBinary;
        createJarBinarySpecLocalComponentMetaData(artifacts, jarBinarySpec, dependenciesPerUsage, toAssembly);
    }
    if (selectedBinary instanceof WithJvmAssembly) {
        // a local component that provides a JVM assembly
        JvmAssembly assembly = ((WithJvmAssembly) selectedBinary).getAssembly();
        createJvmAssemblyLocalComponentMetaData(artifacts, assembly, dependenciesPerUsage, toAssembly);
    }
    return createResolvedMetaData((BinarySpecInternal) selectedBinary, projectPath, dependenciesPerUsage, artifacts);
}
Also used : JarBinarySpecInternal(org.gradle.jvm.internal.JarBinarySpecInternal) WithJvmAssembly(org.gradle.jvm.internal.WithJvmAssembly) WithJvmAssembly(org.gradle.jvm.internal.WithJvmAssembly) JvmAssembly(org.gradle.jvm.internal.JvmAssembly) DependencySpec(org.gradle.platform.base.DependencySpec) LinkedList(java.util.LinkedList) List(java.util.List) PublishArtifact(org.gradle.api.artifacts.PublishArtifact) DefaultPublishArtifact(org.gradle.api.internal.artifacts.publish.DefaultPublishArtifact) EnumMap(java.util.EnumMap)

Example 7 with EnumMap

use of java.util.EnumMap in project j2objc by google.

the class EnumMapTest method test_entrySet.

/**
     * @tests java.util.EnumMap#entrySet()
     */
@SuppressWarnings({ "unchecked", "boxing" })
public void test_entrySet() {
    EnumMap enumSizeMap = new EnumMap(Size.class);
    enumSizeMap.put(Size.Middle, 1);
    enumSizeMap.put(Size.Big, null);
    MockEntry mockEntry = new MockEntry(Size.Middle, 1);
    Set set = enumSizeMap.entrySet();
    Set set1 = enumSizeMap.entrySet();
    //$NON-NLS-1$
    assertSame("Should be same", set1, set);
    try {
        set.add(mockEntry);
        //$NON-NLS-1$
        fail("Should throw UnsupportedOperationException");
    } catch (UnsupportedOperationException e) {
    // Expected
    }
    assertTrue("Returned false for contained object", //$NON-NLS-1$
    set.contains(mockEntry));
    mockEntry = new MockEntry(Size.Middle, null);
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(mockEntry));
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(Size.Small));
    mockEntry = new MockEntry(new Integer(1), 1);
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(mockEntry));
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(new Integer(1)));
    mockEntry = new MockEntry(Size.Big, null);
    assertTrue("Returned false for contained object", //$NON-NLS-1$
    set.contains(mockEntry));
    assertTrue("Returned false when the object can be removed", //$NON-NLS-1$
    set.remove(mockEntry));
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(mockEntry));
    assertFalse("Returned true when the object can not be removed", //$NON-NLS-1$
    set.remove(mockEntry));
    mockEntry = new MockEntry(new Integer(1), 1);
    assertFalse("Returned true when the object can not be removed", //$NON-NLS-1$
    set.remove(mockEntry));
    assertFalse("Returned true when the object can not be removed", //$NON-NLS-1$
    set.remove(new Integer(1)));
    // The set is backed by the map so changes to one are reflected by the
    // other.
    enumSizeMap.put(Size.Big, 3);
    mockEntry = new MockEntry(Size.Big, 3);
    assertTrue("Returned false for contained object", //$NON-NLS-1$
    set.contains(mockEntry));
    enumSizeMap.remove(Size.Big);
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(mockEntry));
    //$NON-NLS-1$
    assertEquals("Wrong size", 1, set.size());
    set.clear();
    //$NON-NLS-1$
    assertEquals("Wrong size", 0, set.size());
    enumSizeMap = new EnumMap(Size.class);
    enumSizeMap.put(Size.Middle, 1);
    enumSizeMap.put(Size.Big, null);
    set = enumSizeMap.entrySet();
    Collection c = new ArrayList();
    c.add(new MockEntry(Size.Middle, 1));
    //$NON-NLS-1$
    assertTrue("Return wrong value", set.containsAll(c));
    //$NON-NLS-1$
    assertTrue("Remove does not success", set.removeAll(c));
    enumSizeMap.put(Size.Middle, 1);
    c.add(new MockEntry(Size.Big, 3));
    //$NON-NLS-1$
    assertTrue("Remove does not success", set.removeAll(c));
    //$NON-NLS-1$
    assertFalse("Should return false", set.removeAll(c));
    //$NON-NLS-1$
    assertEquals("Wrong size", 1, set.size());
    enumSizeMap = new EnumMap(Size.class);
    enumSizeMap.put(Size.Middle, 1);
    enumSizeMap.put(Size.Big, null);
    set = enumSizeMap.entrySet();
    c = new ArrayList();
    c.add(new MockEntry(Size.Middle, 1));
    c.add(new MockEntry(Size.Big, 3));
    //$NON-NLS-1$
    assertTrue("Retain does not success", set.retainAll(c));
    //$NON-NLS-1$
    assertEquals("Wrong size", 1, set.size());
    //$NON-NLS-1$
    assertFalse("Should return false", set.retainAll(c));
    enumSizeMap = new EnumMap(Size.class);
    enumSizeMap.put(Size.Middle, 1);
    enumSizeMap.put(Size.Big, null);
    set = enumSizeMap.entrySet();
    Object[] array = set.toArray();
    //$NON-NLS-1$
    assertEquals("Wrong length", 2, array.length);
    Map.Entry entry = (Map.Entry) array[0];
    //$NON-NLS-1$
    assertEquals("Wrong key", Size.Middle, entry.getKey());
    //$NON-NLS-1$
    assertEquals("Wrong value", 1, entry.getValue());
    Object[] array1 = new Object[10];
    array1 = set.toArray();
    //$NON-NLS-1$
    assertEquals("Wrong length", 2, array1.length);
    entry = (Map.Entry) array[0];
    //$NON-NLS-1$
    assertEquals("Wrong key", Size.Middle, entry.getKey());
    //$NON-NLS-1$
    assertEquals("Wrong value", 1, entry.getValue());
    array1 = new Object[10];
    array1 = set.toArray(array1);
    //$NON-NLS-1$
    assertEquals("Wrong length", 10, array1.length);
    entry = (Map.Entry) array[1];
    //$NON-NLS-1$
    assertEquals("Wrong key", Size.Big, entry.getKey());
    //$NON-NLS-1$
    assertNull("Should be null", array1[2]);
    set = enumSizeMap.entrySet();
    //$NON-NLS-1$
    Integer integer = new Integer("1");
    assertFalse("Returned true when the object can not be removed", //$NON-NLS-1$
    set.remove(integer));
    assertTrue("Returned false when the object can be removed", //$NON-NLS-1$
    set.remove(entry));
    enumSizeMap = new EnumMap(Size.class);
    enumSizeMap.put(Size.Middle, 1);
    enumSizeMap.put(Size.Big, null);
    set = enumSizeMap.entrySet();
    Iterator iter = set.iterator();
    entry = (Map.Entry) iter.next();
    //$NON-NLS-1$
    assertTrue("Returned false for contained object", set.contains(entry));
    mockEntry = new MockEntry(Size.Middle, 2);
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(mockEntry));
    mockEntry = new MockEntry(new Integer(2), 2);
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(mockEntry));
    entry = (Map.Entry) iter.next();
    //$NON-NLS-1$
    assertTrue("Returned false for contained object", set.contains(entry));
    enumSizeMap.put(Size.Middle, 1);
    enumSizeMap.remove(Size.Big);
    mockEntry = new MockEntry(Size.Big, null);
    //$NON-NLS-1$
    assertEquals("Wrong size", 1, set.size());
    //$NON-NLS-1$
    assertFalse("Returned true for uncontained object", set.contains(mockEntry));
    enumSizeMap.put(Size.Big, 2);
    mockEntry = new MockEntry(Size.Big, 2);
    assertTrue("Returned false for contained object", //$NON-NLS-1$
    set.contains(mockEntry));
    iter.remove();
    try {
        iter.remove();
        //$NON-NLS-1$
        fail("Should throw IllegalStateException");
    } catch (IllegalStateException e) {
    // Expected
    }
    try {
        entry.setValue(2);
        //$NON-NLS-1$
        fail("Should throw IllegalStateException");
    } catch (IllegalStateException e) {
    // Expected
    }
    try {
        set.contains(entry);
        //$NON-NLS-1$
        fail("Should throw IllegalStateException");
    } catch (IllegalStateException e) {
    // Expected
    }
    enumSizeMap = new EnumMap(Size.class);
    enumSizeMap.put(Size.Middle, 1);
    enumSizeMap.put(Size.Big, null);
    set = enumSizeMap.entrySet();
    iter = set.iterator();
    entry = (Map.Entry) iter.next();
    //$NON-NLS-1$
    assertEquals("Wrong key", Size.Middle, entry.getKey());
    //$NON-NLS-1$
    assertTrue("Returned false for contained object", set.contains(entry));
    enumSizeMap.put(Size.Middle, 3);
    //$NON-NLS-1$
    assertTrue("Returned false for contained object", set.contains(entry));
    entry.setValue(2);
    //$NON-NLS-1$
    assertTrue("Returned false for contained object", set.contains(entry));
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.remove(new Integer(1)));
    iter.next();
    //The following test case fails on RI.
    //$NON-NLS-1$
    assertEquals("Wrong key", Size.Middle, entry.getKey());
    set.clear();
    //$NON-NLS-1$
    assertEquals("Wrong size", 0, set.size());
    enumSizeMap = new EnumMap(Size.class);
    enumSizeMap.put(Size.Middle, 1);
    enumSizeMap.put(Size.Big, null);
    set = enumSizeMap.entrySet();
    iter = set.iterator();
    mockEntry = new MockEntry(Size.Middle, 1);
    //$NON-NLS-1$
    assertFalse("Wrong result", entry.equals(mockEntry));
    try {
        iter.remove();
        //$NON-NLS-1$
        fail("Should throw IllegalStateException");
    } catch (IllegalStateException e) {
    // Expected
    }
    entry = (Map.Entry) iter.next();
    //$NON-NLS-1$
    assertEquals("Wrong key", Size.Middle, entry.getKey());
    //$NON-NLS-1$
    assertTrue("Should return true", entry.equals(mockEntry));
    //$NON-NLS-1$
    assertEquals("Should be equal", mockEntry.hashCode(), entry.hashCode());
    mockEntry = new MockEntry(Size.Big, 1);
    //$NON-NLS-1$
    assertFalse("Wrong result", entry.equals(mockEntry));
    entry = (Map.Entry) iter.next();
    //$NON-NLS-1$
    assertFalse("Wrong result", entry.equals(mockEntry));
    //$NON-NLS-1$
    assertEquals("Wrong key", Size.Big, entry.getKey());
    iter.remove();
    //$NON-NLS-1$
    assertFalse("Wrong result", entry.equals(mockEntry));
    //$NON-NLS-1$
    assertEquals("Wrong size", 1, set.size());
    try {
        iter.remove();
        //$NON-NLS-1$
        fail("Should throw IllegalStateException");
    } catch (IllegalStateException e) {
    // Expected
    }
    try {
        iter.next();
        //$NON-NLS-1$
        fail("Should throw NoSuchElementException");
    } catch (NoSuchElementException e) {
    // Expected
    }
}
Also used : Set(java.util.Set) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Collection(java.util.Collection) EnumMap(java.util.EnumMap) EnumMap(java.util.EnumMap) Map(java.util.Map) HashMap(java.util.HashMap) NoSuchElementException(java.util.NoSuchElementException)

Example 8 with EnumMap

use of java.util.EnumMap in project j2objc by google.

the class EnumMapTest method test_keySet.

/**
     * @tests java.util.EnumMap#keySet()
     */
@SuppressWarnings({ "unchecked", "boxing" })
public void test_keySet() {
    EnumMap enumSizeMap = new EnumMap(Size.class);
    enumSizeMap.put(Size.Middle, 2);
    enumSizeMap.put(Size.Big, null);
    Set set = enumSizeMap.keySet();
    Set set1 = enumSizeMap.keySet();
    //$NON-NLS-1$
    assertSame("Should be same", set1, set);
    try {
        set.add(Size.Big);
        //$NON-NLS-1$
        fail("Should throw UnsupportedOperationException");
    } catch (UnsupportedOperationException e) {
    // Expected
    }
    assertTrue("Returned false for contained object", //$NON-NLS-1$
    set.contains(Size.Middle));
    assertTrue("Returned false for contained object", //$NON-NLS-1$
    set.contains(Size.Big));
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(Size.Small));
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(new Integer(1)));
    assertTrue("Returned false when the object can be removed", //$NON-NLS-1$
    set.remove(Size.Big));
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(Size.Big));
    assertFalse("Returned true when the object can not be removed", //$NON-NLS-1$
    set.remove(Size.Big));
    assertFalse("Returned true when the object can not be removed", //$NON-NLS-1$
    set.remove(new Integer(1)));
    // The set is backed by the map so changes to one are reflected by the
    // other.
    enumSizeMap.put(Size.Big, 3);
    assertTrue("Returned false for contained object", //$NON-NLS-1$
    set.contains(Size.Big));
    enumSizeMap.remove(Size.Big);
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(Size.Big));
    //$NON-NLS-1$
    assertEquals("Wrong size", 1, set.size());
    set.clear();
    //$NON-NLS-1$
    assertEquals("Wrong size", 0, set.size());
    enumSizeMap = new EnumMap(Size.class);
    enumSizeMap.put(Size.Middle, 1);
    enumSizeMap.put(Size.Big, null);
    set = enumSizeMap.keySet();
    Collection c = new ArrayList();
    c.add(Size.Big);
    //$NON-NLS-1$
    assertTrue("Should return true", set.containsAll(c));
    c.add(Size.Small);
    //$NON-NLS-1$
    assertFalse("Should return false", set.containsAll(c));
    //$NON-NLS-1$
    assertTrue("Should return true", set.removeAll(c));
    //$NON-NLS-1$
    assertEquals("Wrong size", 1, set.size());
    //$NON-NLS-1$
    assertFalse("Should return false", set.removeAll(c));
    //$NON-NLS-1$
    assertEquals("Wrong size", 1, set.size());
    try {
        set.addAll(c);
        //$NON-NLS-1$
        fail("Should throw UnsupportedOperationException");
    } catch (UnsupportedOperationException e) {
    // Expected
    }
    enumSizeMap.put(Size.Big, null);
    //$NON-NLS-1$
    assertEquals("Wrong size", 2, set.size());
    //$NON-NLS-1$
    assertTrue("Should return true", set.retainAll(c));
    //$NON-NLS-1$
    assertEquals("Wrong size", 1, set.size());
    //$NON-NLS-1$
    assertFalse("Should return false", set.retainAll(c));
    assertEquals(1, set.size());
    Object[] array = set.toArray();
    //$NON-NLS-1$
    assertEquals("Wrong length", 1, array.length);
    //$NON-NLS-1$
    assertEquals("Wrong key", Size.Big, array[0]);
    enumSizeMap = new EnumMap(Size.class);
    enumSizeMap.put(Size.Middle, 1);
    enumSizeMap.put(Size.Big, null);
    set = enumSizeMap.keySet();
    c = new ArrayList();
    c.add(Color.Blue);
    //$NON-NLS-1$
    assertFalse("Should return false", set.remove(c));
    //$NON-NLS-1$
    assertEquals("Wrong size", 2, set.size());
    //$NON-NLS-1$
    assertTrue("Should return true", set.retainAll(c));
    //$NON-NLS-1$
    assertEquals("Wrong size", 0, set.size());
    enumSizeMap = new EnumMap(Size.class);
    enumSizeMap.put(Size.Middle, 1);
    enumSizeMap.put(Size.Big, null);
    set = enumSizeMap.keySet();
    Iterator iter = set.iterator();
    Enum enumKey = (Enum) iter.next();
    //$NON-NLS-1$
    assertTrue("Returned false for contained object", set.contains(enumKey));
    enumKey = (Enum) iter.next();
    //$NON-NLS-1$
    assertTrue("Returned false for contained object", set.contains(enumKey));
    enumSizeMap.remove(Size.Big);
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(enumKey));
    iter.remove();
    try {
        iter.remove();
        //$NON-NLS-1$
        fail("Should throw IllegalStateException");
    } catch (IllegalStateException e) {
    // Expected
    }
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(enumKey));
    iter = set.iterator();
    enumKey = (Enum) iter.next();
    //$NON-NLS-1$
    assertTrue("Returned false for contained object", set.contains(enumKey));
    enumSizeMap.put(Size.Middle, 3);
    //$NON-NLS-1$
    assertTrue("Returned false for contained object", set.contains(enumKey));
    enumSizeMap = new EnumMap(Size.class);
    enumSizeMap.put(Size.Middle, 1);
    enumSizeMap.put(Size.Big, null);
    set = enumSizeMap.keySet();
    iter = set.iterator();
    try {
        iter.remove();
        //$NON-NLS-1$
        fail("Should throw IllegalStateException");
    } catch (IllegalStateException e) {
    // Expected
    }
    enumKey = (Enum) iter.next();
    //$NON-NLS-1$
    assertEquals("Wrong key", Size.Middle, enumKey);
    //$NON-NLS-1$
    assertSame("Wrong key", Size.Middle, enumKey);
    //$NON-NLS-1$
    assertFalse("Returned true for unequal object", iter.equals(enumKey));
    iter.remove();
    assertFalse("Returned true for uncontained object", //$NON-NLS-1$
    set.contains(enumKey));
    try {
        iter.remove();
        //$NON-NLS-1$
        fail("Should throw IllegalStateException");
    } catch (IllegalStateException e) {
    // Expected
    }
    //$NON-NLS-1$
    assertEquals("Wrong size", 1, set.size());
    enumKey = (Enum) iter.next();
    //$NON-NLS-1$
    assertEquals("Wrong key", Size.Big, enumKey);
    iter.remove();
    try {
        iter.next();
        //$NON-NLS-1$
        fail("Should throw NoSuchElementException");
    } catch (NoSuchElementException e) {
    // Expected
    }
}
Also used : Set(java.util.Set) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Collection(java.util.Collection) EnumMap(java.util.EnumMap) NoSuchElementException(java.util.NoSuchElementException)

Example 9 with EnumMap

use of java.util.EnumMap in project j2objc by google.

the class EnumMapTest method test_ConstructorLjava_util_EnumMap.

/**
     * @tests java.util.EnumMap#EnumMap(EnumMap)
     */
@SuppressWarnings({ "unchecked", "boxing" })
public void test_ConstructorLjava_util_EnumMap() {
    EnumMap enumMap;
    EnumMap enumColorMap = null;
    try {
        enumMap = new EnumMap(enumColorMap);
        //$NON-NLS-1$
        fail("Expected NullPointerException");
    } catch (NullPointerException e) {
    // Expected
    }
    enumColorMap = new EnumMap<Color, Double>(Color.class);
    Double double1 = new Double(1);
    enumColorMap.put(Color.Green, 2);
    enumColorMap.put(Color.Blue, double1);
    enumMap = new EnumMap(enumColorMap);
    //$NON-NLS-1$
    assertEquals("Constructor fails", 2, enumMap.get(Color.Green));
    //$NON-NLS-1$
    assertSame("Constructor fails", double1, enumMap.get(Color.Blue));
    //$NON-NLS-1$
    assertNull("Constructor fails", enumMap.get(Color.Red));
    enumMap.put(Color.Red, 1);
    //$NON-NLS-1$
    assertEquals("Wrong value", 1, enumMap.get(Color.Red));
    try {
        enumMap.put(Size.Middle, 2);
        //$NON-NLS-1$
        fail("Expected ClassCastException");
    } catch (ClassCastException e) {
    // Expected
    }
}
Also used : EnumMap(java.util.EnumMap)

Example 10 with EnumMap

use of java.util.EnumMap in project j2objc by google.

the class EnumMapTest method test_containsValueLjava_lang_Object.

/**
     * @tests java.util.EnumMap#containsValue(Object)
     */
@SuppressWarnings({ "unchecked", "boxing" })
public void test_containsValueLjava_lang_Object() {
    EnumMap enumSizeMap = new EnumMap(Size.class);
    Double double1 = new Double(3);
    Double double2 = new Double(3);
    assertFalse("Returned true for uncontained value", //$NON-NLS-1$
    enumSizeMap.containsValue(double1));
    enumSizeMap.put(Size.Middle, 2);
    enumSizeMap.put(Size.Small, double1);
    assertTrue("Returned false for contained value", //$NON-NLS-1$
    enumSizeMap.containsValue(double1));
    assertTrue("Returned false for contained value", //$NON-NLS-1$
    enumSizeMap.containsValue(double2));
    assertTrue("Returned false for contained value", //$NON-NLS-1$
    enumSizeMap.containsValue(2));
    assertFalse("Returned true for uncontained value", //$NON-NLS-1$
    enumSizeMap.containsValue(1));
    assertFalse("Returned true for uncontained value", //$NON-NLS-1$
    enumSizeMap.containsValue(null));
    enumSizeMap.put(Size.Big, null);
    assertTrue("Returned false for contained value", //$NON-NLS-1$
    enumSizeMap.containsValue(null));
}
Also used : EnumMap(java.util.EnumMap)

Aggregations

EnumMap (java.util.EnumMap)156 Map (java.util.Map)30 HashMap (java.util.HashMap)23 Collection (java.util.Collection)22 ArrayList (java.util.ArrayList)21 Test (org.junit.Test)18 DecodeHintType (com.google.zxing.DecodeHintType)17 List (java.util.List)14 IOException (java.io.IOException)12 EncodeHintType (com.google.zxing.EncodeHintType)11 BitMatrix (com.google.zxing.common.BitMatrix)11 Set (java.util.Set)11 Occur (org.apache.lucene.search.BooleanClause.Occur)10 Iterator (java.util.Iterator)9 ImmutableMap (com.google.common.collect.ImmutableMap)7 TreeMap (java.util.TreeMap)7 NoSuchElementException (java.util.NoSuchElementException)6 Bundle (android.os.Bundle)5 QRCodeWriter (com.google.zxing.qrcode.QRCodeWriter)5 URL (java.net.URL)5