CircularIntArray.java 3.09 KB
package android.support.v4.util;

public final class CircularIntArray
{
  private int[] a;
  private int b;
  private int c;
  private int d;
  
  public CircularIntArray()
  {
    this(8);
  }
  
  public CircularIntArray(int paramInt)
  {
    if (paramInt <= 0) {
      throw new IllegalArgumentException("capacity must be >= 1");
    }
    if (paramInt > 1073741824) {
      throw new IllegalArgumentException("capacity must be <= 2^30");
    }
    int i = paramInt;
    if (Integer.bitCount(paramInt) != 1) {
      i = Integer.highestOneBit(paramInt - 1) << 1;
    }
    this.d = (i - 1);
    this.a = new int[i];
  }
  
  private void a()
  {
    int i = this.a.length;
    int j = i - this.b;
    int k = i << 1;
    if (k < 0) {
      throw new RuntimeException("Max array capacity exceeded");
    }
    int[] arrayOfInt = new int[k];
    System.arraycopy(this.a, this.b, arrayOfInt, 0, j);
    System.arraycopy(this.a, 0, arrayOfInt, j, this.b);
    this.a = arrayOfInt;
    this.b = 0;
    this.c = i;
    this.d = (k - 1);
  }
  
  public final void addFirst(int paramInt)
  {
    this.b = (this.b - 1 & this.d);
    this.a[this.b] = paramInt;
    if (this.b == this.c) {
      a();
    }
  }
  
  public final void addLast(int paramInt)
  {
    this.a[this.c] = paramInt;
    this.c = (this.c + 1 & this.d);
    if (this.c == this.b) {
      a();
    }
  }
  
  public final void clear()
  {
    this.c = this.b;
  }
  
  public final int get(int paramInt)
  {
    if ((paramInt < 0) || (paramInt >= size())) {
      throw new ArrayIndexOutOfBoundsException();
    }
    return this.a[(this.b + paramInt & this.d)];
  }
  
  public final int getFirst()
  {
    if (this.b == this.c) {
      throw new ArrayIndexOutOfBoundsException();
    }
    return this.a[this.b];
  }
  
  public final int getLast()
  {
    if (this.b == this.c) {
      throw new ArrayIndexOutOfBoundsException();
    }
    return this.a[(this.c - 1 & this.d)];
  }
  
  public final boolean isEmpty()
  {
    return this.b == this.c;
  }
  
  public final int popFirst()
  {
    if (this.b == this.c) {
      throw new ArrayIndexOutOfBoundsException();
    }
    int i = this.a[this.b];
    this.b = (this.b + 1 & this.d);
    return i;
  }
  
  public final int popLast()
  {
    if (this.b == this.c) {
      throw new ArrayIndexOutOfBoundsException();
    }
    int i = this.c - 1 & this.d;
    int j = this.a[i];
    this.c = i;
    return j;
  }
  
  public final void removeFromEnd(int paramInt)
  {
    if (paramInt <= 0) {
      return;
    }
    if (paramInt > size()) {
      throw new ArrayIndexOutOfBoundsException();
    }
    this.c = (this.c - paramInt & this.d);
  }
  
  public final void removeFromStart(int paramInt)
  {
    if (paramInt <= 0) {
      return;
    }
    if (paramInt > size()) {
      throw new ArrayIndexOutOfBoundsException();
    }
    this.b = (this.b + paramInt & this.d);
  }
  
  public final int size()
  {
    return this.c - this.b & this.d;
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/android/support/v4/util/CircularIntArray.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */