Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Side by Side Diff: device/sensors/android/java/src/org/chromium/device/sensors/SensorConfigurations.java

Issue 2051083002: WIP : Generic Sensor API implementation Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.device.sensors;
6
7 import org.chromium.mojom.device.sensors.SensorConfiguration;
8
9 import java.util.ArrayList;
10 import java.util.Collections;
11 import java.util.Comparator;
12 import java.util.List;
13
14 /**
15 * Generic list of configurations.
16 */
17 public class SensorConfigurations extends ArrayList<SensorConfiguration> {
18 private final Comparator<SensorConfiguration> mComparator;
19
20 SensorConfigurations() {
21 super();
22 mComparator = new SensorConfigurationComparator();
23 }
24
25 SensorConfigurations(Comparator<SensorConfiguration> comparator) {
26 super();
27 mComparator = comparator;
28 }
29
30 private static class SensorConfigurationComparator implements Comparator<Sen sorConfiguration> {
31 @Override
32 public int compare(SensorConfiguration lhs, SensorConfiguration rhs) {
33 if (lhs.frequency == rhs.frequency)
34 return 0;
35 else if (rhs.frequency > lhs.frequency)
36 return 1;
37 else
38 return -1;
39 }
40 };
41
42 public boolean add(SensorConfiguration configuration) {
43 if (configuration == null) return false;
44 boolean result = super.add(configuration);
45 if (result) Collections.sort(this, mComparator);
46 return result;
47 }
48
49 public boolean remove(SensorConfiguration configuration) {
50 if (configuration == null) return false;
51 if (!super.remove(configuration)) return false;
52 Collections.sort(this, mComparator);
53 return true;
54 }
55 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698