package com.worklight.location.internal;

import com.worklight.location.api.WLDeviceContext;
import com.worklight.location.api.geo.WLGeoPosition;
import com.worklight.location.api.wifi.WLWifiLocation;
import com.worklight.location.internal.nativeImpl.LocationUtils;
import org.json.JSONException;
import org.json.JSONObject;

public class DeviceContextImpl
  implements WLDeviceContext, Cloneable
{
  private static final DeviceContextJSONFactory jsonFactory = new DeviceContextJSONFactory();
  private WLGeoPosition geoPosition = null;
  private Long lastModified = null;
  private Integer timezoneOffset = null;
  private long version = 0L;
  private WLWifiLocation wifiPosition = null;

  private void internalUpdateLastModified(AbstractPosition paramAbstractPosition)
  {
    if ((paramAbstractPosition == null) || (paramAbstractPosition.getTimestamp() == null))
      return;
    if (this.lastModified == null)
    {
      this.lastModified = paramAbstractPosition.getTimestamp();
      return;
    }
    this.lastModified = Long.valueOf(Math.max(this.lastModified.longValue(), paramAbstractPosition.getTimestamp().longValue()));
  }

  private void updateLastModified()
  {
    try
    {
      this.lastModified = null;
      internalUpdateLastModified(this.geoPosition);
      internalUpdateLastModified(this.wifiPosition);
      if (this.lastModified == null);
      for (this.timezoneOffset = null; ; this.timezoneOffset = Integer.valueOf(-LocationUtils.getTimeZoneOffset()))
      {
        this.version = (1L + this.version);
        return;
      }
    }
    finally
    {
    }
  }

  public void addToEvent(JSONObject paramJSONObject)
  {
    try
    {
      Object localObject = getJSON();
      if (localObject == null)
        localObject = JSONObject.NULL;
      paramJSONObject.put("deviceContext", localObject);
      return;
    }
    catch (JSONException localJSONException)
    {
      localJSONException.printStackTrace();
      throw new AssertionError(localJSONException.getMessage());
    }
  }

  public void clearGeoPosition()
  {
    try
    {
      this.version = (1L + this.version);
      this.geoPosition = null;
      updateLastModified();
      return;
    }
    finally
    {
      localObject = finally;
      throw localObject;
    }
  }

  public void clearWifiPosition()
  {
    try
    {
      this.version = (1L + this.version);
      this.wifiPosition = null;
      updateLastModified();
      return;
    }
    finally
    {
      localObject = finally;
      throw localObject;
    }
  }

  public DeviceContextImpl clone()
  {
    try
    {
      DeviceContextImpl localDeviceContextImpl = new DeviceContextImpl();
      localDeviceContextImpl.geoPosition = this.geoPosition;
      localDeviceContextImpl.wifiPosition = this.wifiPosition;
      localDeviceContextImpl.lastModified = this.lastModified;
      localDeviceContextImpl.timezoneOffset = this.timezoneOffset;
      localDeviceContextImpl.version = this.version;
      return localDeviceContextImpl;
    }
    finally
    {
      localObject = finally;
      throw localObject;
    }
  }

  public boolean equals(Object paramObject)
  {
    if (this == paramObject);
    DeviceContextImpl localDeviceContextImpl;
    do
    {
      do
      {
        return true;
        if (paramObject == null)
          return false;
        if (getClass() != paramObject.getClass())
          return false;
        localDeviceContextImpl = (DeviceContextImpl)paramObject;
        if (this.geoPosition == null)
        {
          if (localDeviceContextImpl.geoPosition != null)
            return false;
        }
        else if (!this.geoPosition.equals(localDeviceContextImpl.geoPosition))
          return false;
        if (this.lastModified == null)
        {
          if (localDeviceContextImpl.lastModified != null)
            return false;
        }
        else if (!this.lastModified.equals(localDeviceContextImpl.lastModified))
          return false;
        if (this.timezoneOffset == null)
        {
          if (localDeviceContextImpl.timezoneOffset != null)
            return false;
        }
        else if (!this.timezoneOffset.equals(localDeviceContextImpl.timezoneOffset))
          return false;
        if (this.version != localDeviceContextImpl.version)
          return false;
        if (this.wifiPosition != null)
          break;
      }
      while (localDeviceContextImpl.wifiPosition == null);
      return false;
    }
    while (this.wifiPosition.equals(localDeviceContextImpl.wifiPosition));
    return false;
  }

  public WLGeoPosition getGeoPosition()
  {
    return this.geoPosition;
  }

  public JSONObject getJSON()
  {
    DeviceContextImpl localDeviceContextImpl = clone();
    try
    {
      JSONObject localJSONObject = jsonFactory.buildJson(localDeviceContextImpl);
      return localJSONObject;
    }
    catch (JSONException localJSONException)
    {
      localJSONException.printStackTrace();
      throw new AssertionError(localJSONException.getMessage());
    }
  }

  public Long getLastModified()
  {
    return this.lastModified;
  }

  public Integer getTimezoneOffset()
  {
    return this.timezoneOffset;
  }

  public long getVersion()
  {
    return this.version;
  }

  public WLWifiLocation getWifiLocation()
  {
    return this.wifiPosition;
  }

  public int hashCode()
  {
    int i;
    int k;
    label26: int n;
    label44: int i1;
    int i2;
    if (this.geoPosition == null)
    {
      i = 0;
      int j = 31 * (i + 31);
      if (this.lastModified != null)
        break label102;
      k = 0;
      int m = 31 * (j + k);
      if (this.timezoneOffset != null)
        break label113;
      n = 0;
      i1 = 31 * (31 * (m + n) + (int)(this.version ^ this.version >>> 32));
      WLWifiLocation localWLWifiLocation = this.wifiPosition;
      i2 = 0;
      if (localWLWifiLocation != null)
        break label125;
    }
    while (true)
    {
      return i1 + i2;
      i = this.geoPosition.hashCode();
      break;
      label102: k = this.lastModified.hashCode();
      break label26;
      label113: n = this.timezoneOffset.hashCode();
      break label44;
      label125: i2 = this.wifiPosition.hashCode();
    }
  }

  public boolean isEmpty()
  {
    return (this.geoPosition == null) && (this.wifiPosition == null);
  }

  public void setGeoPosition(WLGeoPosition paramWLGeoPosition)
  {
    if (paramWLGeoPosition == null)
      try
      {
        throw new IllegalArgumentException("wLGeoPosition is null");
      }
      finally
      {
      }
    this.geoPosition = paramWLGeoPosition;
    updateLastModified();
  }

  public void setWifiPosition(WLWifiLocation paramWLWifiLocation)
  {
    if (paramWLWifiLocation == null)
      try
      {
        throw new IllegalArgumentException("wifiPosition is null");
      }
      finally
      {
      }
    this.wifiPosition = paramWLWifiLocation;
    updateLastModified();
  }
}

/* Location:           C:\Documents and Settings\Cesar Cabello Cea\Mis documentos\Downloads\apk-downloader\com.ikea.kompis-6_dex2jar.jar
 * Qualified Name:     com.worklight.location.internal.DeviceContextImpl
 * JD-Core Version:    0.6.2
 */