Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 43f4263a authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Add generic sugar for ArrayMap and ArraySet.

Change-Id: Id749bd41f2e53664c00a0199c14babd2b63087fb
parent b28f8c82
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.google.android.collect;

import android.util.ArrayMap;

import java.util.HashMap;

/**
@@ -30,4 +32,11 @@ public class Maps {
    public static <K, V> HashMap<K, V> newHashMap() {
        return new HashMap<K, V>();
    }

    /**
     * Creates a {@code ArrayMap} instance.
     */
    public static <K, V> ArrayMap<K, V> newArrayMap() {
        return new ArrayMap<K, V>();
    }
}
+18 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.google.android.collect;

import android.util.ArraySet;

import java.util.Collections;
import java.util.EnumSet;
import java.util.HashSet;
@@ -90,4 +92,20 @@ public class Sets {
        return set;
    }

    /**
     * Creates a {@code ArraySet} instance.
     */
    public static <E> ArraySet<E> newArraySet() {
        return new ArraySet<E>();
    }

    /**
     * Creates a {@code ArraySet} instance containing the given elements.
     */
    public static <E> ArraySet<E> newArraySet(E... elements) {
        int capacity = elements.length * 4 / 3 + 1;
        ArraySet<E> set = new ArraySet<E>(capacity);
        Collections.addAll(set, elements);
        return set;
    }
}