Skip to content

Commit

Permalink
#Notifiers: switch from CopyOnWriteArrayList to a CopyOnWriteArraySet
Browse files Browse the repository at this point in the history
  • Loading branch information
ost-ct committed Jun 23, 2016
1 parent 6a9842a commit 9f1d67b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 165 deletions.
14 changes: 7 additions & 7 deletions src/main/java/org/altbeacon/beacon/BeaconIntentProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
*/
package org.altbeacon.beacon;

import org.altbeacon.beacon.logging.LogManager;
import org.altbeacon.beacon.service.MonitoringData;
import org.altbeacon.beacon.service.RangingData;

import android.annotation.TargetApi;
import android.app.IntentService;
import android.content.Intent;

import java.util.List;
import org.altbeacon.beacon.logging.LogManager;
import org.altbeacon.beacon.service.MonitoringData;
import org.altbeacon.beacon.service.RangingData;

import java.util.Set;

/**
* Converts internal intents to notifier callbacks
Expand Down Expand Up @@ -61,7 +61,7 @@ protected void onHandleIntent(Intent intent) {
if (rangingData.getBeacons() == null) {
LogManager.w(TAG, "Ranging data has a null beacons collection");
}
List<RangeNotifier> notifiers = BeaconManager.getInstanceForApplication(this).getRangingNotifiers();
Set<RangeNotifier> notifiers = BeaconManager.getInstanceForApplication(this).getRangingNotifiers();
java.util.Collection<Beacon> beacons = rangingData.getBeacons();
if (notifiers != null) {
for(RangeNotifier notifier : notifiers){
Expand All @@ -79,7 +79,7 @@ protected void onHandleIntent(Intent intent) {

if (monitoringData != null) {
LogManager.d(TAG, "got monitoring data");
List<MonitorNotifier> notifiers = BeaconManager.getInstanceForApplication(this).getMonitoringNotifiers();
Set<MonitorNotifier> notifiers = BeaconManager.getInstanceForApplication(this).getMonitoringNotifiers();
if (notifiers != null) {
for(MonitorNotifier notifier : notifiers) {
LogManager.d(TAG, "Calling monitoring notifier: %s", notifier);
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/org/altbeacon/beacon/BeaconManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;

/**
* A class used to set up interaction with beacons from an <code>Activity</code> or <code>Service</code>.
Expand Down Expand Up @@ -109,9 +110,9 @@ public class BeaconManager {
protected static BeaconManager client = null;
private final ConcurrentMap<BeaconConsumer, ConsumerInfo> consumers = new ConcurrentHashMap<BeaconConsumer,ConsumerInfo>();
private Messenger serviceMessenger = null;
protected final List<RangeNotifier> rangeNotifiers = new CopyOnWriteArrayList<>();
protected final Set<RangeNotifier> rangeNotifiers = new CopyOnWriteArraySet<>();
protected RangeNotifier dataRequestNotifier = null;
protected List<MonitorNotifier> monitorNotifiers = new CopyOnWriteArrayList<>();
protected Set<MonitorNotifier> monitorNotifiers = new CopyOnWriteArraySet<>();
private final ArrayList<Region> monitoredRegions = new ArrayList<Region>();
private final ArrayList<Region> rangedRegions = new ArrayList<Region>();
private final List<BeaconParser> beaconParsers = new CopyOnWriteArrayList<>();
Expand Down Expand Up @@ -704,7 +705,7 @@ private String callbackPackageName() {
public MonitorNotifier getMonitoringNotifier() {
synchronized (monitorNotifiers) {
if (monitorNotifiers.size() > 0) {
return monitorNotifiers.get(0);
return monitorNotifiers.iterator().next();
}
return null;
}
Expand All @@ -713,7 +714,7 @@ public MonitorNotifier getMonitoringNotifier() {
/**
* @return the list of registered monitorNotifier
*/
public List<MonitorNotifier> getMonitoringNotifiers(){
public Set<MonitorNotifier> getMonitoringNotifiers(){
return monitorNotifiers;
}

Expand All @@ -725,7 +726,7 @@ public List<MonitorNotifier> getMonitoringNotifiers(){
public RangeNotifier getRangingNotifier() {
synchronized (rangeNotifiers) {
if (rangeNotifiers.size() > 0) {
return rangeNotifiers.get(0);
return rangeNotifiers.iterator().next();
}
return null;
}
Expand All @@ -734,7 +735,7 @@ public RangeNotifier getRangingNotifier() {
/**
* @return the list of registered rangeNotifier
*/
public List<RangeNotifier> getRangingNotifiers(){
public Set<RangeNotifier> getRangingNotifiers(){
return rangeNotifiers;
}

Expand Down
48 changes: 0 additions & 48 deletions src/main/java/org/altbeacon/beacon/notifier/RegionFilter.java

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 9f1d67b

Please sign in to comment.