Example usage for android.support.v4.util SimpleArrayMap isEmpty

List of usage examples for android.support.v4.util SimpleArrayMap isEmpty

Introduction

In this page you can find the example usage for android.support.v4.util SimpleArrayMap isEmpty.

Prototype

public boolean isEmpty() 

Source Link

Usage

From source file:org.bubenheimer.android.preference.SharedPreferencesUtility.java

@UiThread
public static void unregisterOnSharedPreferenceChangeListener(@NonNull final Context context,
        @NonNull final SharedPreferences prefs, @NonNull final OnSharedPreferenceChangeListener listener,
        @StringRes final int... resIds) {
    final SimpleArrayMap<String, Pair<Integer, ? extends List<OnSharedPreferenceChangeListener>>> prefsEntry = masterMap
            .get(prefs);/*from  w  ww  . j av  a  2s  . c  om*/
    if (prefsEntry == null) {
        Log.w(TAG, "Shared preferences not registered: ", prefs);
        return;
    }
    final int cnt = resIds.length;
    //noinspection ForLoopReplaceableByForEach
    for (int i = 0; i < cnt; ++i) {
        final int resId = resIds[i];
        final String key = context.getString(resId);
        final Pair<Integer, ? extends List<OnSharedPreferenceChangeListener>> pair = prefsEntry.get(key);
        if (pair == null) {
            Log.w(TAG, "Shared preference not registered: ", key, " - ", prefs);
            return;
        }
        final List<OnSharedPreferenceChangeListener> list = pair.second;
        if (!list.remove(listener)) {
            Log.w(TAG, "Listener not registered: ", key, " - ", prefs);
            return;
        }
        if (list.isEmpty()) {
            prefsEntry.remove(key);
        }
    }
    if (prefsEntry.isEmpty()) {
        masterMap.remove(prefs);
        prefs.unregisterOnSharedPreferenceChangeListener(masterListener);
    }
}

From source file:com.firebase.jobdispatcher.GooglePlayReceiver.java

@Override
protected void onJobFinished(@NonNull JobParameters js, @JobResult int result) {
    synchronized (this) {
        SimpleArrayMap<String, JobCallback> map = callbacks.get(js.getService());
        if (map == null) {
            return;
        }/* w w w . j  av  a2s.  c o m*/

        JobCallback callback = map.remove(js.getTag());
        if (callback != null) {
            Log.i(TAG, "sending jobFinished for " + js.getTag() + " = " + result);
            callback.jobFinished(result);
        }

        if (map.isEmpty()) {
            callbacks.remove(js.getService());
        }
    }
}

From source file:com.facebook.litho.dataflow.DataFlowGraph.java

private void regenerateSortedNodes() {
    mSortedNodes.clear();/*  w w  w. j a va 2  s . co  m*/

    if (mBindings.size() == 0) {
        return;
    }

    final ArraySet<ValueNode> leafNodes = ComponentsPools.acquireArraySet();
    final SimpleArrayMap<ValueNode, Integer> nodesToOutputsLeft = new SimpleArrayMap<>();

    for (int i = 0, bindingsSize = mBindingToNodes.size(); i < bindingsSize; i++) {
        final ArraySet<ValueNode> nodes = mBindingToNodes.valueAt(i);
        for (int j = 0, nodesSize = nodes.size(); j < nodesSize; j++) {
            final ValueNode node = nodes.valueAt(j);
            final int outputCount = node.getOutputCount();
            if (outputCount == 0) {
                leafNodes.add(node);
            } else {
                nodesToOutputsLeft.put(node, outputCount);
            }
        }
    }

    if (!nodesToOutputsLeft.isEmpty() && leafNodes.isEmpty()) {
        throw new DetectedCycleException("Graph has nodes, but they represent a cycle with no leaf nodes!");
    }

    final ArrayDeque<ValueNode> nodesToProcess = ComponentsPools.acquireArrayDeque();
    nodesToProcess.addAll(leafNodes);

    while (!nodesToProcess.isEmpty()) {
        final ValueNode next = nodesToProcess.pollFirst();
        mSortedNodes.add(next);
        for (int i = 0, count = next.getInputCount(); i < count; i++) {
            final ValueNode input = next.getInputAt(i);
            final int outputsLeft = nodesToOutputsLeft.get(input) - 1;
            nodesToOutputsLeft.put(input, outputsLeft);
            if (outputsLeft == 0) {
                nodesToProcess.addLast(input);
            } else if (outputsLeft < 0) {
                throw new DetectedCycleException("Detected cycle.");
            }
        }
    }

    int expectedTotalNodes = nodesToOutputsLeft.size() + leafNodes.size();
    if (mSortedNodes.size() != expectedTotalNodes) {
        throw new DetectedCycleException(
                "Had unreachable nodes in graph -- this likely means there was a cycle");
    }

    Collections.reverse(mSortedNodes);
    mIsDirty = false;

    ComponentsPools.release(nodesToProcess);
    ComponentsPools.release(leafNodes);
}