Java Code Examples for androidx.collection.ArrayMap#put()

The following examples show how to use androidx.collection.ArrayMap#put() . 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: HealthStatsMetricsTest.java    From Battery-Metrics with MIT License 6 votes vote down vote up
@Test
public void testSumArrayMaps() {
  ArrayMap<String, Long> a = new ArrayMap<>();
  a.put("a", 1L);
  a.put("c", 2L);

  ArrayMap<String, Long> b = new ArrayMap<>();
  b.put("b", 1L);
  b.put("c", 3L);

  ArrayMap<String, Long> sum = HealthStatsMetrics.opArrayMaps(OP_SUM, a, b);
  assertThat(sum.get("a")).isEqualTo(1);
  assertThat(sum.get("b")).isEqualTo(1);
  assertThat(sum.get("c")).isEqualTo(5);
  assertThat(sum.size()).isEqualTo(3);
}
 
Example 2
Source File: HealthStatsMetricsTest.java    From Battery-Metrics with MIT License 6 votes vote down vote up
@Test
public void testSum() {
  HealthStatsMetrics a = createTestMetrics();
  HealthStatsMetrics b = createTestMetrics();
  HealthStatsMetrics sum = a.sum(b, null);
  HealthStatsMetrics expectedSum = new HealthStatsMetrics();
  expectedSum.dataType = TEST_DATATYPE;
  expectedSum.measurement.put(123, 2000L);
  expectedSum.measurements.put(234, new ArrayMap<String, Long>());
  expectedSum.measurements.get(234).put("measurements", 4000L);
  expectedSum.timer.put(345, new HealthStatsMetrics.TimerMetrics(10, 4000));
  ArrayMap<String, HealthStatsMetrics.TimerMetrics> timersValues = new ArrayMap<>();
  timersValues.put("timers", new HealthStatsMetrics.TimerMetrics(12, 6000));
  expectedSum.timers.put(456, timersValues);
  ArrayMap<String, HealthStatsMetrics> value = new ArrayMap<>();
  value.put("stats", new HealthStatsMetrics(expectedSum));
  expectedSum.stats.put(1234, value);
  assertThat(sum).isEqualTo(expectedSum);
}
 
Example 3
Source File: HealthStatsMetricsTest.java    From Battery-Metrics with MIT License 6 votes vote down vote up
@Test
public void testDiff() {
  HealthStatsMetrics a = createTestMetrics();
  HealthStatsMetrics b = createTestMetrics();
  HealthStatsMetrics diff = a.diff(b, null);
  HealthStatsMetrics expectedDiff = new HealthStatsMetrics();
  expectedDiff.dataType = TEST_DATATYPE;
  expectedDiff.measurement.put(123, 0L);
  expectedDiff.measurements.put(234, new ArrayMap<String, Long>());
  expectedDiff.measurements.get(234).put("measurements", 0L);
  expectedDiff.timer.put(345, new HealthStatsMetrics.TimerMetrics(0, 0));
  ArrayMap<String, HealthStatsMetrics.TimerMetrics> timersValues = new ArrayMap<>();
  timersValues.put("timers", new HealthStatsMetrics.TimerMetrics(0, 0));
  expectedDiff.timers.put(456, timersValues);
  ArrayMap<String, HealthStatsMetrics> value = new ArrayMap<>();
  value.put("stats", new HealthStatsMetrics(expectedDiff));
  expectedDiff.stats.put(1234, value);
  assertThat(diff).isEqualTo(expectedDiff);
}
 
Example 4
Source File: HealthStatsMetricsSerializerTest.java    From Battery-Metrics with MIT License 6 votes vote down vote up
private HealthStatsMetrics createTestMetricsWithoutStats() {
  HealthStatsMetrics metrics = new HealthStatsMetrics();
  metrics.dataType = "test";

  metrics.measurement.put(123, 1000L);
  metrics.measurement.put(345, 1001L);

  metrics.measurements.put(234, new ArrayMap<String, Long>());
  metrics.measurements.get(234).put("measurements", 2000L);
  metrics.measurements.put(345, new ArrayMap<String, Long>());
  metrics.measurements.get(345).put("measurements_second", 3000L);

  metrics.timer.put(345, new HealthStatsMetrics.TimerMetrics(5, 2000));
  metrics.timer.put(123, new HealthStatsMetrics.TimerMetrics(8, 9000));

  ArrayMap<String, HealthStatsMetrics.TimerMetrics> timersValues = new ArrayMap<>();
  timersValues.put("timers", new HealthStatsMetrics.TimerMetrics(6, 3000));
  metrics.timers.put(456, timersValues);

  ArrayMap<String, HealthStatsMetrics.TimerMetrics> secondTimers = new ArrayMap<>();
  timersValues.put("timers_two", new HealthStatsMetrics.TimerMetrics(7, 8000));
  metrics.timers.put(123, timersValues);

  return metrics;
}
 
Example 5
Source File: ServiceDetailFragment.java    From BonjourBrowser with Apache License 2.0 6 votes vote down vote up
private void updateIPRecords(BonjourService service) {
    ArrayMap<String, String> metaInfo = new ArrayMap<>();
    for (InetAddress inetAddress : service.getInetAddresses()) {
        if (inetAddress instanceof Inet4Address) {
            metaInfo.put("Address IPv4", service.getInet4Address().getHostAddress() + ":" + service.getPort());
        }
        else {
            metaInfo.put("Address IPv6", service.getInet6Address().getHostAddress() + ":" + service.getPort());
        }
    }
    mAdapter.swapIPRecords(metaInfo);
    mAdapter.notifyDataSetChanged();
    if (isAdded()) {
        ((ServiceDetailListener)getActivity()).onServiceUpdated(mService);
    }
}
 
Example 6
Source File: BasePresenterSelector.java    From LeanbackTvSample with MIT License 5 votes vote down vote up
/**
 * Adds a presenter to be used for the given class.
 * @param cls item 类型
 * @param presenter presenter
 * @param childType  当包含多个相同{@param cls}时,并且presenter不同,则通过子item{@param childType}区分
 */
public void addClassPresenter(Class<?> cls, Presenter presenter, Class<?> childType) {
    ArrayMap<Class<?>, Presenter> classPresenterArrayMap = mClassMap.get(cls);
    if (classPresenterArrayMap == null) {
        classPresenterArrayMap = new ArrayMap<>();
    }
    classPresenterArrayMap.put(childType, presenter);
    mClassMap.put(cls, classPresenterArrayMap);
    if (!mPresenters.contains(presenter)) {
        mPresenters.add(presenter);
    }
}
 
Example 7
Source File: HealthStatsMetricsTest.java    From Battery-Metrics with MIT License 5 votes vote down vote up
@Test
public void testDiffArrayMaps() {
  ArrayMap<String, Long> a = new ArrayMap<>();
  a.put("a", 1L);
  a.put("c", 2L);

  ArrayMap<String, Long> b = new ArrayMap<>();
  b.put("b", 1L);
  b.put("c", 3L);

  ArrayMap<String, Long> sum = HealthStatsMetrics.opArrayMaps(OP_DIFF, a, b);
  assertThat(sum.get("a")).isEqualTo(1);
  assertThat(sum.get("c")).isEqualTo(-1);
  assertThat(sum.size()).isEqualTo(2);
}
 
Example 8
Source File: HealthStatsMetricsTest.java    From Battery-Metrics with MIT License 5 votes vote down vote up
private HealthStatsMetrics createTestMetrics() {
  HealthStatsMetrics metrics = createTestMetricsWithoutStats();
  ArrayMap<String, HealthStatsMetrics> value = new ArrayMap<>();
  value.put("stats", createTestMetricsWithoutStats());
  metrics.stats.put(1234, value);
  return metrics;
}
 
Example 9
Source File: HealthStatsMetricsTest.java    From Battery-Metrics with MIT License 5 votes vote down vote up
private HealthStatsMetrics createTestMetricsWithoutStats() {
  HealthStatsMetrics metrics = new HealthStatsMetrics();
  metrics.dataType = TEST_DATATYPE;
  metrics.measurement.put(123, 1000L);
  metrics.measurements.put(234, new ArrayMap<String, Long>());
  metrics.measurements.get(234).put("measurements", 2000L);
  metrics.timer.put(345, new HealthStatsMetrics.TimerMetrics(5, 2000));
  ArrayMap<String, HealthStatsMetrics.TimerMetrics> timersValues = new ArrayMap<>();
  timersValues.put("timers", new HealthStatsMetrics.TimerMetrics(6, 3000));
  metrics.timers.put(456, timersValues);
  return metrics;
}
 
Example 10
Source File: HealthStatsMetricsSerializerTest.java    From Battery-Metrics with MIT License 5 votes vote down vote up
@Override
protected HealthStatsMetrics createInitializedInstance() {
  HealthStatsMetrics metrics = createTestMetricsWithoutStats();
  ArrayMap<String, HealthStatsMetrics> value = new ArrayMap<>();
  value.put("stats", createTestMetricsWithoutStats());
  value.put("moreStats", createTestMetricsWithoutStats());
  metrics.stats.put(1234, value);

  ArrayMap<String, HealthStatsMetrics> secondValue = new ArrayMap<>();
  value.put("stats_2", createTestMetricsWithoutStats());
  metrics.stats.put(3456, secondValue);

  return metrics;
}
 
Example 11
Source File: AuthorizationException.java    From AppAuth-Android with Apache License 2.0 5 votes vote down vote up
private static Map<String, AuthorizationException> exceptionMapByString(
        AuthorizationException... exceptions) {
    ArrayMap<String, AuthorizationException> map =
            new ArrayMap<>(exceptions != null ? exceptions.length : 0);

    if (exceptions != null) {
        for (AuthorizationException ex : exceptions) {
            if (ex.error != null) {
                map.put(ex.error, ex);
            }
        }
    }

    return Collections.unmodifiableMap(map);
}
 
Example 12
Source File: AliasManager.java    From prayer-times-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onPrefsChanged(@NonNull String key) {
    if (key.equals(Preferences.LANGUAGE.getKey())) {
        PackageManager pm = getContext().getPackageManager();
        
        PackageInfo info;
        try {
            info = pm.getPackageInfo(getContext().getApplicationContext().getPackageName(),
                    PackageManager.GET_ACTIVITIES | PackageManager.GET_DISABLED_COMPONENTS);
        } catch (PackageManager.NameNotFoundException e) {
            Crashlytics.logException(e);
            throw new RuntimeException(e);
        }
        String prefix = "com.metinkale.prayer.alias";
        ArrayMap<String, String> aliases = new ArrayMap<>();
        for (ActivityInfo ai : info.activities) {
            if (ai.name.startsWith(prefix)) {
                aliases.put(new Locale(ai.name.substring(prefix.length())).getLanguage(), ai.name);
            }
        }
        
        String bestAlias = "Default";
        LocaleListCompat locales = LocaleUtils.getLocalesCompat();
        for (int i = 0; i < locales.size(); i++) {
            String lang = locales.get(i).getLanguage();
            if (aliases.containsKey(lang)) {
                bestAlias = lang;
                break;
            }
        }
        
        for (Map.Entry<String, String> entry : aliases.entrySet()) {
            if (bestAlias.equals(entry.getKey())) {
                //enable
                pm.setComponentEnabledSetting(new ComponentName(getContext(), entry.getValue()), PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                        PackageManager.DONT_KILL_APP);
            } else if (!bestAlias.equals(entry.getKey())) {
                //disable
                pm.setComponentEnabledSetting(new ComponentName(getContext(), entry.getValue()), PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                        PackageManager.DONT_KILL_APP);
            }
        }
        
        
    }
}
 
Example 13
Source File: AliasManager.java    From prayer-times-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onPrefsChanged(@NonNull String key) {
    if (key.equals(Preferences.LANGUAGE.getKey())) {
        PackageManager pm = getContext().getPackageManager();
        
        PackageInfo info;
        try {
            info = pm.getPackageInfo(getContext().getApplicationContext().getPackageName(),
                    PackageManager.GET_ACTIVITIES | PackageManager.GET_DISABLED_COMPONENTS);
        } catch (PackageManager.NameNotFoundException e) {
            Crashlytics.logException(e);
            throw new RuntimeException(e);
        }
        String prefix = "com.metinkale.prayer.alias";
        ArrayMap<String, String> aliases = new ArrayMap<>();
        for (ActivityInfo ai : info.activities) {
            if (ai.name.startsWith(prefix)) {
                aliases.put(new Locale(ai.name.substring(prefix.length())).getLanguage(), ai.name);
            }
        }
        
        String bestAlias = "Default";
        LocaleListCompat locales = LocaleUtils.getLocalesCompat();
        for (int i = 0; i < locales.size(); i++) {
            String lang = locales.get(i).getLanguage();
            if (aliases.containsKey(lang)) {
                bestAlias = lang;
                break;
            }
        }
        
        for (Map.Entry<String, String> entry : aliases.entrySet()) {
            if (bestAlias.equals(entry.getKey())) {
                //enable
                pm.setComponentEnabledSetting(new ComponentName(getContext(), entry.getValue()), PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                        PackageManager.DONT_KILL_APP);
            } else if (!bestAlias.equals(entry.getKey())) {
                //disable
                pm.setComponentEnabledSetting(new ComponentName(getContext(), entry.getValue()), PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                        PackageManager.DONT_KILL_APP);
            }
        }
        
        
    }
}