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

Commit 1a6a620e authored by Jeff Sharkey's avatar Jeff Sharkey Committed by Android (Google) Code Review
Browse files

Merge "Add generic sugar for ArrayMap and ArraySet."

parents b31e370a 43f4263a
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;
    }
}