package com.worklight.location.internal.events.storage;

import com.worklight.location.internal.nativeImpl.LocationUtils;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class Chunk
{
  private final long maxChunkSize;
  private int size;
  private final List<String> strings = new ArrayList();

  public Chunk(long paramLong)
  {
    if (paramLong < 0L)
      throw new IllegalArgumentException("Chunk size can't be negative");
    this.maxChunkSize = paramLong;
  }

  public Chunk(JSONArray paramJSONArray, long paramLong)
    throws JSONException
  {
    for (int i = 0; i < paramJSONArray.length(); i++)
    {
      String str = paramJSONArray.getString(i);
      this.strings.add(str);
      this.size += LocationUtils.getByteLength(str);
    }
    if (paramLong < 0L)
    {
      this.maxChunkSize = this.size;
      return;
    }
    this.maxChunkSize = paramLong;
  }

  public boolean add(JSONObject paramJSONObject)
  {
    String str = paramJSONObject.toString();
    int i = LocationUtils.getByteLength(str);
    if ((this.size == 0) || (i + this.size < this.maxChunkSize))
    {
      this.size = (i + this.size);
      this.strings.add(str);
      return true;
    }
    return false;
  }

  public Chunk createNewChunk()
  {
    return new Chunk(this.maxChunkSize);
  }

  public Chunk createNewChunk(long paramLong)
  {
    return new Chunk(paramLong);
  }

  public long currentChunkSize()
  {
    return this.size;
  }

  public JSONObject get(int paramInt)
  {
    try
    {
      JSONObject localJSONObject = new JSONObject((String)this.strings.get(paramInt));
      return localJSONObject;
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
      throw new AssertionError(localException.getMessage());
    }
  }

  List<String> getStrings()
  {
    return this.strings;
  }

  public long maxChunkSize()
  {
    return this.maxChunkSize;
  }

  public int numberOfEvents()
  {
    return this.strings.size();
  }
}

/* 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.events.storage.Chunk
 * JD-Core Version:    0.6.2
 */