package com.google.android.m4b.maps.ao;

import com.google.android.m4b.maps.bc.ba;
import com.google.android.m4b.maps.bc.bg;
import com.google.android.m4b.maps.bc.o;
import com.google.android.m4b.maps.bm.a.d;
import com.google.android.m4b.maps.bo.e;
import com.google.android.m4b.maps.bq.q;
import com.google.android.m4b.maps.bq.u;
import com.google.android.m4b.maps.model.Tile;
import com.google.android.m4b.maps.model.TileProvider;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

public final class t
{

  @VisibleForTesting
  private static q b = new u();

  @VisibleForTesting
  final Set<b> a = Collections.synchronizedSet(new HashSet());
  private final a.d c;
  private final TileProvider d;
  private final ScheduledExecutorService e;
  private final Set<ba> f = Collections.synchronizedSet(new HashSet());
  private volatile e g;
  private final com.google.android.m4b.maps.bm.a h;
  private volatile a i;

  public t(TileProvider paramTileProvider, String paramString, ScheduledExecutorService paramScheduledExecutorService)
  {
    Preconditions.checkNotNull(paramTileProvider);
    Preconditions.checkNotNull(paramScheduledExecutorService);
    this.d = paramTileProvider;
    com.google.android.m4b.maps.bk.a locala = a(Integer.valueOf(paramString.replaceAll("\\D", "")).intValue());
    this.c = new a.d(bg.t, null, locala);
    this.e = paramScheduledExecutorService;
    com.google.android.m4b.maps.bm.a.a(new com.google.android.m4b.maps.z.b());
    this.h = com.google.android.m4b.maps.bm.a.a();
  }

  @VisibleForTesting
  private static com.google.android.m4b.maps.bk.a a(int paramInt)
  {
    int[] arrayOfInt1 = new int[32];
    int j = 0;
    int k = 0;
    int m;
    if (j < 32)
    {
      if ((paramInt & 1 << j) == 0)
        break label61;
      m = k + 1;
      arrayOfInt1[k] = j;
    }
    while (true)
    {
      j++;
      k = m;
      break;
      int[] arrayOfInt2 = new int[k];
      System.arraycopy(arrayOfInt1, 0, arrayOfInt2, 0, k);
      return com.google.android.m4b.maps.bk.a.a(arrayOfInt2);
      label61: m = k;
    }
  }

  private q a(ba paramba, boolean paramBoolean)
  {
    if (this.g == null)
      return null;
    return this.h.a(this.g, this.c, paramba, paramBoolean);
  }

  private void a(ba paramba, q paramq, e parame)
  {
    if (this.h != null)
      this.h.a(parame, this.c, paramba, paramq);
    this.f.remove(paramba);
    if (paramq != null);
    for (boolean bool = true; ; bool = false)
    {
      a locala = this.i;
      if (locala != null)
        locala.b(bool);
      return;
    }
  }

  public final q a(ba paramba)
  {
    return a(paramba, false);
  }

  public final void a()
  {
    if (this.g != null);
    for (boolean bool = true; ; bool = false)
    {
      Preconditions.checkState(bool);
      this.h.d(this.g, this.c);
      return;
    }
  }

  public final void a(a parama)
  {
    boolean bool = true;
    if (this.i == null)
    {
      if (parama != null);
      while (true)
      {
        Preconditions.checkArgument(bool);
        this.i = parama;
        return;
        bool = false;
      }
    }
    if (parama == null);
    while (true)
    {
      Preconditions.checkArgument(bool);
      break;
      bool = false;
    }
  }

  public final void a(e parame)
  {
    Preconditions.checkNotNull(parame, "state must not be null.");
    this.g = parame;
  }

  public final void a(List<q> paramList)
  {
    if (this.g != null);
    ArrayList localArrayList;
    for (boolean bool = true; ; bool = false)
    {
      Preconditions.checkState(bool);
      localArrayList = new ArrayList(paramList.size());
      Iterator localIterator = paramList.iterator();
      while (localIterator.hasNext())
      {
        q localq = (q)localIterator.next();
        if (localq != b)
          localArrayList.add(localq.b());
      }
    }
    this.h.a(this.g, this.c, localArrayList);
  }

  public final void a(boolean paramBoolean)
  {
    e locale = this.g;
    if (locale != null)
      this.h.a(locale, this.c);
  }

  public final q b(ba paramba)
  {
    q localq = a(paramba, true);
    if (localq != null)
      return localq;
    if (this.f.add(paramba))
      this.e.execute(new b(paramba, new Random()));
    return null;
  }

  public final void b()
  {
    if (this.g != null);
    for (boolean bool = true; ; bool = false)
    {
      Preconditions.checkState(bool);
      if (com.google.android.m4b.maps.am.b.a)
        this.h.c(this.g, this.c);
      return;
    }
  }

  public final void b(List<q> paramList)
  {
    if (this.g != null);
    ArrayList localArrayList;
    for (boolean bool = true; ; bool = false)
    {
      Preconditions.checkState(bool);
      localArrayList = new ArrayList(paramList.size());
      Iterator localIterator = paramList.iterator();
      while (localIterator.hasNext())
      {
        q localq = (q)localIterator.next();
        if (localq != b)
          localArrayList.add(localq.b());
      }
    }
    this.h.b(this.g, this.c, localArrayList);
  }

  public final void b(boolean paramBoolean)
  {
    this.h.a(paramBoolean);
  }

  public final void c()
  {
    if (this.g != null)
      this.h.b(this.g, this.c);
  }

  public final void d()
  {
    this.h.b();
  }

  public static abstract interface a
  {
    public abstract void b(boolean paramBoolean);
  }

  @VisibleForTesting
  final class b
    implements Runnable
  {
    private final Random a;
    private final ba b;
    private ScheduledFuture c = null;
    private int d = 0;

    public b(ba paramRandom, Random arg3)
    {
      this.b = paramRandom;
      Object localObject;
      this.a = localObject;
      t.this.a.add(this);
    }

    private void a(Tile paramTile)
    {
      boolean bool1 = true;
      try
      {
        boolean bool2;
        if (paramTile.width > 0)
          bool2 = bool1;
        while (true)
        {
          Preconditions.checkArgument(bool2, "width of tile image must be positive");
          if (paramTile.height > 0)
            Preconditions.checkArgument(bool1, "height of tile image must be positive");
          try
          {
            o localo = new o(this.b, 0, paramTile.width, paramTile.height, paramTile.data, bg.t);
            this.c = null;
            t.this.a.remove(this);
            t.a(t.this, this.b, localo);
            return;
            bool2 = false;
            continue;
            bool1 = false;
          }
          catch (IOException localIOException)
          {
            while (true)
              b();
          }
        }
      }
      finally
      {
      }
    }

    private void b()
    {
      try
      {
        this.c = null;
        t.this.a.remove(this);
        t.a(t.this, this.b);
        return;
      }
      finally
      {
        localObject = finally;
        throw localObject;
      }
    }

    public final void a()
    {
      try
      {
        if (this.c != null)
        {
          this.c.cancel(false);
          this.c = null;
        }
        return;
      }
      finally
      {
        localObject = finally;
        throw localObject;
      }
    }

    public final void run()
    {
      while (true)
      {
        Tile localTile;
        try
        {
          localTile = t.a(t.this).getTile(this.b.c(), this.b.d(), this.b.b());
          if (localTile == null)
          {
            int i = this.d;
            this.d = (i + 1);
            long l = ()(200.0D * Math.pow(2.0D, i) + this.a.nextInt(100));
            if (l < 300000L)
            {
              this.c = t.b(t.this).schedule(this, l, TimeUnit.MILLISECONDS);
              return;
            }
            b();
            continue;
          }
        }
        finally
        {
        }
        if (localTile == TileProvider.NO_TILE)
          b();
        else
          a(localTile);
      }
    }
  }
}

/* Location:           C:\Documents and Settings\Cesar Cabello Cea\Mis documentos\Downloads\apk-downloader\com.ikea.kompis-6_dex2jar.jar
 * Qualified Name:     com.google.android.m4b.maps.ao.t
 * JD-Core Version:    0.6.2
 */