androidx.collection.SimpleArrayMap Java Examples

The following examples show how to use androidx.collection.SimpleArrayMap. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CompositeMetricsCollector.java    From Battery-Metrics with MIT License 6 votes vote down vote up
/**
 * Gets the snapshot for all the metrics and returns a CompositeMetrics object with the value.
 *
 * <p>Snapshots are only taken of metrics requested in the composite metrics objects; any
 * snapshots that fail or are not supported by this collector are marked invalid. The underlying
 * collectors are expected to report any errors they might encounter.
 *
 * @param snapshot snapshot to reuse
 * @return whether _any_ underlying snapshot succeeded
 */
@Override
@ThreadSafe(enableChecks = false)
public boolean getSnapshot(CompositeMetrics snapshot) {
  checkNotNull(snapshot, "Null value passed to getSnapshot!");
  boolean result = false;
  SimpleArrayMap<Class<? extends SystemMetrics>, SystemMetrics> snapshotMetrics =
      snapshot.getMetrics();
  for (int i = 0, size = snapshotMetrics.size(); i < size; i++) {
    Class<? extends SystemMetrics> metricsClass = snapshotMetrics.keyAt(i);
    SystemMetricsCollector collector = mMetricsCollectorMap.get(metricsClass);
    boolean snapshotResult = false;
    if (collector != null) {
      SystemMetrics metric = snapshot.getMetric(metricsClass);
      snapshotResult = collector.getSnapshot(metric);
    }
    snapshot.setIsValid(metricsClass, snapshotResult);
    result |= snapshotResult;
  }

  return result;
}
 
Example #2
Source File: ExtendableSavedState.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
private ExtendableSavedState(@NonNull Parcel in, ClassLoader loader) {
  super(in, loader);

  int size = in.readInt();

  String[] keys = new String[size];
  in.readStringArray(keys);

  Bundle[] states = new Bundle[size];
  in.readTypedArray(states, Bundle.CREATOR);

  extendableStates = new SimpleArrayMap<>(size);
  for (int i = 0; i < size; i++) {
    extendableStates.put(keys[i], states[i]);
  }
}
 
Example #3
Source File: MusicRepositoryImpl.java    From klingar with Apache License 2.0 6 votes vote down vote up
private Single<SimpleArrayMap<Integer, PlexItem>> browseHeaders(MediaType mt) {
  return media.firstCharacter(mt.uri(), mt.libraryKey(), mt.mediaKey())
      .flatMap(DIRS)
      .toList()
      .map(dirs -> {
        SimpleArrayMap<Integer, PlexItem> headers = new SimpleArrayMap<>();

        int offset = 0;
        for (int i = 0; i < dirs.size(); ++i) {
          headers.put(offset, Header.builder().title(dirs.get(i).title).build());
          offset += dirs.get(i).size;
        }

        return headers;
      });
}
 
Example #4
Source File: Utilities.java    From Battery-Metrics with MIT License 5 votes vote down vote up
/**
 * Check for equality between simple array maps: the equals function was broken in old versions of
 * the android support library.
 *
 * <p>This was fixed by commit goo.gl/nRWXvR
 */
public static <K, V> boolean simpleArrayMapEquals(
    SimpleArrayMap<K, V> a, SimpleArrayMap<K, V> b) {
  if (a == b) {
    return true;
  }

  int aSize = a.size();
  int bSize = b.size();
  if (aSize != bSize) {
    return false;
  }

  for (int i = 0; i < aSize; i++) {
    K aKey = a.keyAt(i);
    V aValue = a.valueAt(i);

    V bValue = b.get(aKey);

    if (aValue == null) {
      if (bValue != null || !b.containsKey(aKey)) {
        return false;
      }
    } else if (!aValue.equals(bValue)) {
      return false;
    }
  }

  return true;
}
 
Example #5
Source File: AppWakeupMetricsTest.java    From Battery-Metrics with MIT License 5 votes vote down vote up
private static void verifyKeyAndReason(SimpleArrayMap<String, WakeupDetails> map) {
  for (int i = 0; i < map.size(); i++) {
    assertThat(map.keyAt(i)).isEqualTo("key-" + i);
    assertThat(map.valueAt(i).reason)
        .isEqualTo(i % 2 == 0 ? WakeupReason.ALARM : WakeupReason.JOB_SCHEDULER);
  }
}
 
Example #6
Source File: ArraySet.java    From litho with Apache License 2.0 4 votes vote down vote up
public ArraySet() {
  mMap = new SimpleArrayMap<>();
}
 
Example #7
Source File: ArraySet.java    From litho with Apache License 2.0 4 votes vote down vote up
public ArraySet(int capacity) {
  mMap = new SimpleArrayMap<>(capacity);
}
 
Example #8
Source File: ArraySet.java    From litho with Apache License 2.0 4 votes vote down vote up
public ArraySet(@Nullable Collection<? extends E> set) {
  mMap = new SimpleArrayMap<>();
  if (set != null) {
    addAll(set);
  }
}
 
Example #9
Source File: DataFlowGraph.java    From litho with Apache License 2.0 4 votes vote down vote up
@GuardedBy("this")
private void regenerateSortedNodes() {
  mSortedNodes.clear();

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

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

  for (int i = 0, bindingsSize = mBindings.size(); i < bindingsSize; i++) {
    final ArrayList<ValueNode> nodes = mBindings.get(i).getAllNodes();
    for (int j = 0, nodesSize = nodes.size(); j < nodesSize; j++) {
      final ValueNode node = nodes.get(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 = new ArrayDeque<>();
  nodesToProcess.addAll(leafNodes);

  while (!nodesToProcess.isEmpty()) {
    final ValueNode next = nodesToProcess.pollFirst();
    mSortedNodes.add(next);
    NodeState nodeState = mNodeStates.get(next);
    if (nodeState == null) {
      String message =
          next.getClass().getSimpleName() + " : InputNames " + next.buildDebugInputsString();
      // Added for debugging T67342661
      ComponentsReporter.emitMessage(
          ComponentsReporter.LogLevel.ERROR, STATE_NOT_INTIALIZED_FOR_VALUE_NODE, message);
    }
    for (ValueNode input : next.getAllInputs()) {
      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;
}
 
Example #10
Source File: CompositeMetrics.java    From Battery-Metrics with MIT License 4 votes vote down vote up
public SimpleArrayMap<Class<? extends SystemMetrics>, SystemMetrics> getMetrics() {
  return mMetricsMap;
}
 
Example #11
Source File: ExtendableSavedState.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
public ExtendableSavedState(Parcelable superState) {
  super(superState);
  extendableStates = new SimpleArrayMap<>();
}
 
Example #12
Source File: NetworkLastFmStore.java    From Jockey with Apache License 2.0 4 votes vote down vote up
public NetworkLastFmStore(LastFmService service) {
    mService = service;
    mCachedArtistInfo = new SimpleArrayMap<>();
}