360 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			360 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
package com.google.common.primitives;
 | 
						|
 | 
						|
import com.google.common.base.Preconditions;
 | 
						|
import java.io.Serializable;
 | 
						|
import java.util.AbstractList;
 | 
						|
import java.util.Arrays;
 | 
						|
import java.util.Collection;
 | 
						|
import java.util.Iterator;
 | 
						|
import java.util.List;
 | 
						|
import java.util.RandomAccess;
 | 
						|
 | 
						|
/* loaded from: classes.dex */
 | 
						|
public final class ImmutableIntArray implements Serializable {
 | 
						|
    private static final ImmutableIntArray EMPTY = new ImmutableIntArray(new int[0]);
 | 
						|
    private final int[] array;
 | 
						|
    private final int end;
 | 
						|
    private final transient int start;
 | 
						|
 | 
						|
    static class AsList extends AbstractList<Integer> implements RandomAccess {
 | 
						|
        private final ImmutableIntArray a;
 | 
						|
 | 
						|
        @Override // java.util.AbstractCollection, java.util.Collection, java.util.List
 | 
						|
        public boolean contains(Object obj) {
 | 
						|
            return indexOf(obj) >= 0;
 | 
						|
        }
 | 
						|
 | 
						|
        @Override // java.util.AbstractList, java.util.Collection, java.util.List
 | 
						|
        public boolean equals(Object obj) {
 | 
						|
            if (obj instanceof AsList) {
 | 
						|
                return this.a.equals(((AsList) obj).a);
 | 
						|
            }
 | 
						|
            if (!(obj instanceof List)) {
 | 
						|
                return false;
 | 
						|
            }
 | 
						|
            List list = (List) obj;
 | 
						|
            if (size() != list.size()) {
 | 
						|
                return false;
 | 
						|
            }
 | 
						|
            int i = this.a.start;
 | 
						|
            for (Object obj2 : list) {
 | 
						|
                if (obj2 instanceof Integer) {
 | 
						|
                    int i2 = i + 1;
 | 
						|
                    if (this.a.array[i] == ((Integer) obj2).intValue()) {
 | 
						|
                        i = i2;
 | 
						|
                    }
 | 
						|
                }
 | 
						|
                return false;
 | 
						|
            }
 | 
						|
            return true;
 | 
						|
        }
 | 
						|
 | 
						|
        @Override // java.util.AbstractList, java.util.Collection, java.util.List
 | 
						|
        public int hashCode() {
 | 
						|
            return this.a.hashCode();
 | 
						|
        }
 | 
						|
 | 
						|
        @Override // java.util.AbstractList, java.util.List
 | 
						|
        public int indexOf(Object obj) {
 | 
						|
            if (obj instanceof Integer) {
 | 
						|
                return this.a.indexOf(((Integer) obj).intValue());
 | 
						|
            }
 | 
						|
            return -1;
 | 
						|
        }
 | 
						|
 | 
						|
        @Override // java.util.AbstractList, java.util.List
 | 
						|
        public int lastIndexOf(Object obj) {
 | 
						|
            if (obj instanceof Integer) {
 | 
						|
                return this.a.lastIndexOf(((Integer) obj).intValue());
 | 
						|
            }
 | 
						|
            return -1;
 | 
						|
        }
 | 
						|
 | 
						|
        @Override // java.util.AbstractCollection, java.util.Collection, java.util.List
 | 
						|
        public int size() {
 | 
						|
            return this.a.length();
 | 
						|
        }
 | 
						|
 | 
						|
        @Override // java.util.AbstractList, java.util.List
 | 
						|
        public List<Integer> subList(int i, int i2) {
 | 
						|
            return this.a.subArray(i, i2).asList();
 | 
						|
        }
 | 
						|
 | 
						|
        @Override // java.util.AbstractCollection
 | 
						|
        public String toString() {
 | 
						|
            return this.a.toString();
 | 
						|
        }
 | 
						|
 | 
						|
        private AsList(ImmutableIntArray immutableIntArray) {
 | 
						|
            this.a = immutableIntArray;
 | 
						|
        }
 | 
						|
 | 
						|
        @Override // java.util.AbstractList, java.util.List
 | 
						|
        public Integer get(int i) {
 | 
						|
            return Integer.valueOf(this.a.get(i));
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    public static Builder builder(int i) {
 | 
						|
        Preconditions.a(i >= 0, "Invalid initialCapacity: %s", i);
 | 
						|
        return new Builder(i);
 | 
						|
    }
 | 
						|
 | 
						|
    public static ImmutableIntArray copyOf(int[] iArr) {
 | 
						|
        return iArr.length == 0 ? EMPTY : new ImmutableIntArray(Arrays.copyOf(iArr, iArr.length));
 | 
						|
    }
 | 
						|
 | 
						|
    private boolean isPartialView() {
 | 
						|
        return this.start > 0 || this.end < this.array.length;
 | 
						|
    }
 | 
						|
 | 
						|
    public static ImmutableIntArray of() {
 | 
						|
        return EMPTY;
 | 
						|
    }
 | 
						|
 | 
						|
    public List<Integer> asList() {
 | 
						|
        return new AsList();
 | 
						|
    }
 | 
						|
 | 
						|
    public boolean contains(int i) {
 | 
						|
        return indexOf(i) >= 0;
 | 
						|
    }
 | 
						|
 | 
						|
    public boolean equals(Object obj) {
 | 
						|
        if (obj == this) {
 | 
						|
            return true;
 | 
						|
        }
 | 
						|
        if (!(obj instanceof ImmutableIntArray)) {
 | 
						|
            return false;
 | 
						|
        }
 | 
						|
        ImmutableIntArray immutableIntArray = (ImmutableIntArray) obj;
 | 
						|
        if (length() != immutableIntArray.length()) {
 | 
						|
            return false;
 | 
						|
        }
 | 
						|
        for (int i = 0; i < length(); i++) {
 | 
						|
            if (get(i) != immutableIntArray.get(i)) {
 | 
						|
                return false;
 | 
						|
            }
 | 
						|
        }
 | 
						|
        return true;
 | 
						|
    }
 | 
						|
 | 
						|
    public int get(int i) {
 | 
						|
        Preconditions.a(i, length());
 | 
						|
        return this.array[this.start + i];
 | 
						|
    }
 | 
						|
 | 
						|
    public int hashCode() {
 | 
						|
        int i = 1;
 | 
						|
        for (int i2 = this.start; i2 < this.end; i2++) {
 | 
						|
            int i3 = this.array[i2];
 | 
						|
            Ints.a(i3);
 | 
						|
            i = (i * 31) + i3;
 | 
						|
        }
 | 
						|
        return i;
 | 
						|
    }
 | 
						|
 | 
						|
    public int indexOf(int i) {
 | 
						|
        for (int i2 = this.start; i2 < this.end; i2++) {
 | 
						|
            if (this.array[i2] == i) {
 | 
						|
                return i2 - this.start;
 | 
						|
            }
 | 
						|
        }
 | 
						|
        return -1;
 | 
						|
    }
 | 
						|
 | 
						|
    public boolean isEmpty() {
 | 
						|
        return this.end == this.start;
 | 
						|
    }
 | 
						|
 | 
						|
    public int lastIndexOf(int i) {
 | 
						|
        int i2;
 | 
						|
        int i3 = this.end;
 | 
						|
        do {
 | 
						|
            i3--;
 | 
						|
            i2 = this.start;
 | 
						|
            if (i3 < i2) {
 | 
						|
                return -1;
 | 
						|
            }
 | 
						|
        } while (this.array[i3] != i);
 | 
						|
        return i3 - i2;
 | 
						|
    }
 | 
						|
 | 
						|
    public int length() {
 | 
						|
        return this.end - this.start;
 | 
						|
    }
 | 
						|
 | 
						|
    Object readResolve() {
 | 
						|
        return isEmpty() ? EMPTY : this;
 | 
						|
    }
 | 
						|
 | 
						|
    public ImmutableIntArray subArray(int i, int i2) {
 | 
						|
        Preconditions.b(i, i2, length());
 | 
						|
        if (i == i2) {
 | 
						|
            return EMPTY;
 | 
						|
        }
 | 
						|
        int[] iArr = this.array;
 | 
						|
        int i3 = this.start;
 | 
						|
        return new ImmutableIntArray(iArr, i + i3, i3 + i2);
 | 
						|
    }
 | 
						|
 | 
						|
    public int[] toArray() {
 | 
						|
        return Arrays.copyOfRange(this.array, this.start, this.end);
 | 
						|
    }
 | 
						|
 | 
						|
    public String toString() {
 | 
						|
        if (isEmpty()) {
 | 
						|
            return "[]";
 | 
						|
        }
 | 
						|
        StringBuilder sb = new StringBuilder(length() * 5);
 | 
						|
        sb.append('[');
 | 
						|
        sb.append(this.array[this.start]);
 | 
						|
        int i = this.start;
 | 
						|
        while (true) {
 | 
						|
            i++;
 | 
						|
            if (i >= this.end) {
 | 
						|
                sb.append(']');
 | 
						|
                return sb.toString();
 | 
						|
            }
 | 
						|
            sb.append(", ");
 | 
						|
            sb.append(this.array[i]);
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    public ImmutableIntArray trimmed() {
 | 
						|
        return isPartialView() ? new ImmutableIntArray(toArray()) : this;
 | 
						|
    }
 | 
						|
 | 
						|
    Object writeReplace() {
 | 
						|
        return trimmed();
 | 
						|
    }
 | 
						|
 | 
						|
    private ImmutableIntArray(int[] iArr) {
 | 
						|
        this(iArr, 0, iArr.length);
 | 
						|
    }
 | 
						|
 | 
						|
    public static ImmutableIntArray copyOf(Collection<Integer> collection) {
 | 
						|
        return collection.isEmpty() ? EMPTY : new ImmutableIntArray(Ints.a(collection));
 | 
						|
    }
 | 
						|
 | 
						|
    public static ImmutableIntArray of(int i) {
 | 
						|
        return new ImmutableIntArray(new int[]{i});
 | 
						|
    }
 | 
						|
 | 
						|
    public static final class Builder {
 | 
						|
        private int[] a;
 | 
						|
        private int b = 0;
 | 
						|
 | 
						|
        Builder(int i) {
 | 
						|
            this.a = new int[i];
 | 
						|
        }
 | 
						|
 | 
						|
        private void b(int i) {
 | 
						|
            int i2 = this.b + i;
 | 
						|
            int[] iArr = this.a;
 | 
						|
            if (i2 > iArr.length) {
 | 
						|
                int[] iArr2 = new int[a(iArr.length, i2)];
 | 
						|
                System.arraycopy(this.a, 0, iArr2, 0, this.b);
 | 
						|
                this.a = iArr2;
 | 
						|
            }
 | 
						|
        }
 | 
						|
 | 
						|
        public Builder a(int i) {
 | 
						|
            b(1);
 | 
						|
            int[] iArr = this.a;
 | 
						|
            int i2 = this.b;
 | 
						|
            iArr[i2] = i;
 | 
						|
            this.b = i2 + 1;
 | 
						|
            return this;
 | 
						|
        }
 | 
						|
 | 
						|
        public Builder a(Iterable<Integer> iterable) {
 | 
						|
            if (iterable instanceof Collection) {
 | 
						|
                a((Collection<Integer>) iterable);
 | 
						|
                return this;
 | 
						|
            }
 | 
						|
            Iterator<Integer> it = iterable.iterator();
 | 
						|
            while (it.hasNext()) {
 | 
						|
                a(it.next().intValue());
 | 
						|
            }
 | 
						|
            return this;
 | 
						|
        }
 | 
						|
 | 
						|
        public Builder a(Collection<Integer> collection) {
 | 
						|
            b(collection.size());
 | 
						|
            for (Integer num : collection) {
 | 
						|
                int[] iArr = this.a;
 | 
						|
                int i = this.b;
 | 
						|
                this.b = i + 1;
 | 
						|
                iArr[i] = num.intValue();
 | 
						|
            }
 | 
						|
            return this;
 | 
						|
        }
 | 
						|
 | 
						|
        private static int a(int i, int i2) {
 | 
						|
            if (i2 < 0) {
 | 
						|
                throw new AssertionError("cannot store more than MAX_VALUE elements");
 | 
						|
            }
 | 
						|
            int i3 = i + (i >> 1) + 1;
 | 
						|
            if (i3 < i2) {
 | 
						|
                i3 = Integer.highestOneBit(i2 - 1) << 1;
 | 
						|
            }
 | 
						|
            if (i3 < 0) {
 | 
						|
                return Integer.MAX_VALUE;
 | 
						|
            }
 | 
						|
            return i3;
 | 
						|
        }
 | 
						|
 | 
						|
        public ImmutableIntArray a() {
 | 
						|
            int i = this.b;
 | 
						|
            return i == 0 ? ImmutableIntArray.EMPTY : new ImmutableIntArray(this.a, 0, i);
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    private ImmutableIntArray(int[] iArr, int i, int i2) {
 | 
						|
        this.array = iArr;
 | 
						|
        this.start = i;
 | 
						|
        this.end = i2;
 | 
						|
    }
 | 
						|
 | 
						|
    public static Builder builder() {
 | 
						|
        return new Builder(10);
 | 
						|
    }
 | 
						|
 | 
						|
    public static ImmutableIntArray copyOf(Iterable<Integer> iterable) {
 | 
						|
        if (iterable instanceof Collection) {
 | 
						|
            return copyOf((Collection<Integer>) iterable);
 | 
						|
        }
 | 
						|
        Builder builder = builder();
 | 
						|
        builder.a(iterable);
 | 
						|
        return builder.a();
 | 
						|
    }
 | 
						|
 | 
						|
    public static ImmutableIntArray of(int i, int i2) {
 | 
						|
        return new ImmutableIntArray(new int[]{i, i2});
 | 
						|
    }
 | 
						|
 | 
						|
    public static ImmutableIntArray of(int i, int i2, int i3) {
 | 
						|
        return new ImmutableIntArray(new int[]{i, i2, i3});
 | 
						|
    }
 | 
						|
 | 
						|
    public static ImmutableIntArray of(int i, int i2, int i3, int i4) {
 | 
						|
        return new ImmutableIntArray(new int[]{i, i2, i3, i4});
 | 
						|
    }
 | 
						|
 | 
						|
    public static ImmutableIntArray of(int i, int i2, int i3, int i4, int i5) {
 | 
						|
        return new ImmutableIntArray(new int[]{i, i2, i3, i4, i5});
 | 
						|
    }
 | 
						|
 | 
						|
    public static ImmutableIntArray of(int i, int i2, int i3, int i4, int i5, int i6) {
 | 
						|
        return new ImmutableIntArray(new int[]{i, i2, i3, i4, i5, i6});
 | 
						|
    }
 | 
						|
 | 
						|
    public static ImmutableIntArray of(int i, int... iArr) {
 | 
						|
        int[] iArr2 = new int[iArr.length + 1];
 | 
						|
        iArr2[0] = i;
 | 
						|
        System.arraycopy(iArr, 0, iArr2, 1, iArr.length);
 | 
						|
        return new ImmutableIntArray(iArr2);
 | 
						|
    }
 | 
						|
}
 |