RangedIBeacon.java 2.92 KB
package com.radiusnetworks.ibeacon.service;

import com.radiusnetworks.ibeacon.IBeacon;
import com.radiusnetworks.ibeacon.IBeaconManager;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;

public class RangedIBeacon
  extends IBeacon
{
  public static long DEFAULT_SAMPLE_EXPIRATION_MILLISECONDS = 20000L;
  private static String a = "RangedIBeacon";
  private static long b = 20000L;
  private boolean c = true;
  private ArrayList<a> d = new ArrayList();
  
  public RangedIBeacon(IBeacon paramIBeacon)
  {
    super(paramIBeacon);
    addMeasurement(Integer.valueOf(this.rssi));
  }
  
  private void a()
  {
    try
    {
      Date localDate = new Date();
      ArrayList localArrayList = new ArrayList();
      Iterator localIterator = this.d.iterator();
      while (localIterator.hasNext())
      {
        a locala = (a)localIterator.next();
        if (localDate.getTime() - locala.b < b) {
          localArrayList.add(locala);
        }
      }
      this.d = localArrayList;
    }
    finally {}
    Collections.sort(this.d);
  }
  
  public static void setSampleExpirationMilliseconds(long paramLong)
  {
    b = paramLong;
  }
  
  public void addMeasurement(Integer paramInteger)
  {
    this.c = true;
    a locala = new a((byte)0);
    locala.a = paramInteger;
    locala.b = new Date().getTime();
    this.d.add(locala);
  }
  
  protected void addRangeMeasurement(Integer paramInteger)
  {
    this.rssi = paramInteger.intValue();
    addMeasurement(paramInteger);
  }
  
  public void commitMeasurements()
  {
    a();
    int n = this.d.size();
    int i;
    int j;
    if (n > 2)
    {
      i = n / 10;
      j = n / 10;
      i += 1;
      j = n - j - 2;
    }
    for (;;)
    {
      int k = 0;
      int m = i;
      while (m <= j)
      {
        k += ((a)this.d.get(m)).a.intValue();
        m += 1;
      }
      j = j - i + 1;
      i = j;
      if (j == 0) {
        i = 1;
      }
      double d1 = k / i;
      if (IBeaconManager.debug) {
        new StringBuilder("Running average rssi based on ").append(n).append(" measurements: ").append(d1);
      }
      this.runningAverageRssi = Double.valueOf(d1);
      if (IBeaconManager.debug) {
        new StringBuilder("calculated new runningAverageRssi:").append(this.runningAverageRssi);
      }
      this.accuracy = null;
      this.proximity = null;
      return;
      j = n - 1;
      i = 0;
    }
  }
  
  public boolean isTracked()
  {
    return this.c;
  }
  
  public boolean noMeasurementsAvailable()
  {
    return this.d.size() == 0;
  }
  
  public void setTracked(boolean paramBoolean)
  {
    this.c = paramBoolean;
  }
  
  final class a
    implements Comparable<a>
  {
    Integer a;
    long b;
    
    private a() {}
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/com/radiusnetworks/ibeacon/service/RangedIBeacon.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */