217 lines
7.2 KiB
Java
217 lines
7.2 KiB
Java
|
package com.discord.utilities.collections;
|
||
|
|
||
|
import d0.d0.f;
|
||
|
import d0.t.c0;
|
||
|
import d0.t.o;
|
||
|
import d0.t.u;
|
||
|
import d0.z.d.g;
|
||
|
import d0.z.d.g0.b;
|
||
|
import d0.z.d.m;
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.Collection;
|
||
|
import java.util.Iterator;
|
||
|
import java.util.List;
|
||
|
import kotlin.jvm.functions.Function1;
|
||
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
||
|
import kotlin.ranges.IntRange;
|
||
|
/* compiled from: ShallowPartitionCollection.kt */
|
||
|
public class ShallowPartitionCollection<E, T extends Collection<E>> implements Collection<E>, b {
|
||
|
public static final Companion Companion = new Companion(null);
|
||
|
private final Function1<E, Integer> partitionStrategy;
|
||
|
private final List<T> partitions;
|
||
|
private int size;
|
||
|
|
||
|
/* compiled from: ShallowPartitionCollection.kt */
|
||
|
public static final class Companion {
|
||
|
private Companion() {
|
||
|
}
|
||
|
|
||
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
||
|
this();
|
||
|
}
|
||
|
|
||
|
public static /* synthetic */ ShallowPartitionCollection withArrayListPartions$default(Companion companion, int i, Function1 function1, int i2, Object obj) {
|
||
|
if ((i2 & 1) != 0) {
|
||
|
i = 40;
|
||
|
}
|
||
|
return companion.withArrayListPartions(i, function1);
|
||
|
}
|
||
|
|
||
|
/* JADX DEBUG: Multi-variable search result rejected for r0v2, resolved type: java.util.ArrayList */
|
||
|
/* JADX WARN: Multi-variable type inference failed */
|
||
|
public final <E> ShallowPartitionCollection<E, ArrayList<E>> withArrayListPartions(int i, Function1<? super E, Integer> function1) {
|
||
|
m.checkNotNullParameter(function1, "partitionStrategy");
|
||
|
IntRange until = f.until(0, i);
|
||
|
ArrayList arrayList = new ArrayList(o.collectionSizeOrDefault(until, 10));
|
||
|
Iterator<Integer> it = until.iterator();
|
||
|
while (it.hasNext()) {
|
||
|
((c0) it).nextInt();
|
||
|
arrayList.add(new ArrayList());
|
||
|
}
|
||
|
return new ShallowPartitionCollection<>(arrayList, function1);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/* JADX DEBUG: Multi-variable search result rejected for r2v0, resolved type: java.util.List<? extends T extends java.util.Collection<E>> */
|
||
|
/* JADX DEBUG: Multi-variable search result rejected for r3v0, resolved type: kotlin.jvm.functions.Function1<? super E, java.lang.Integer> */
|
||
|
/* JADX WARN: Multi-variable type inference failed */
|
||
|
public ShallowPartitionCollection(List<? extends T> list, Function1<? super E, Integer> function1) {
|
||
|
m.checkNotNullParameter(list, "partitions");
|
||
|
m.checkNotNullParameter(function1, "partitionStrategy");
|
||
|
this.partitions = list;
|
||
|
this.partitionStrategy = function1;
|
||
|
Iterator it = list.iterator();
|
||
|
int i = 0;
|
||
|
while (it.hasNext()) {
|
||
|
i += ((Collection) it.next()).size();
|
||
|
}
|
||
|
this.size = i;
|
||
|
}
|
||
|
|
||
|
private final T getPartition(E e) {
|
||
|
return this.partitions.get(this.partitionStrategy.invoke(e).intValue());
|
||
|
}
|
||
|
|
||
|
public static final <E> ShallowPartitionCollection<E, ArrayList<E>> withArrayListPartions(int i, Function1<? super E, Integer> function1) {
|
||
|
return Companion.withArrayListPartions(i, function1);
|
||
|
}
|
||
|
|
||
|
@Override // java.util.Collection
|
||
|
public boolean add(E e) {
|
||
|
boolean add = getPartition(e).add(e);
|
||
|
if (add) {
|
||
|
setSize(size() + 1);
|
||
|
}
|
||
|
return add;
|
||
|
}
|
||
|
|
||
|
/* JADX DEBUG: Multi-variable search result rejected for r3v0, resolved type: com.discord.utilities.collections.ShallowPartitionCollection<E, T extends java.util.Collection<E>> */
|
||
|
/* JADX WARN: Multi-variable type inference failed */
|
||
|
@Override // java.util.Collection
|
||
|
public boolean addAll(Collection<? extends E> collection) {
|
||
|
m.checkNotNullParameter(collection, "elements");
|
||
|
Iterator<T> it = collection.iterator();
|
||
|
while (true) {
|
||
|
boolean z2 = false;
|
||
|
while (true) {
|
||
|
if (!it.hasNext()) {
|
||
|
return z2;
|
||
|
}
|
||
|
if (add(it.next()) || z2) {
|
||
|
z2 = true;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override // java.util.Collection
|
||
|
public void clear() {
|
||
|
for (T t : this.partitions) {
|
||
|
t.clear();
|
||
|
}
|
||
|
setSize(0);
|
||
|
}
|
||
|
|
||
|
/* JADX DEBUG: Multi-variable search result rejected for r2v0, resolved type: java.lang.Object */
|
||
|
/* JADX WARN: Multi-variable type inference failed */
|
||
|
@Override // java.util.Collection
|
||
|
public boolean contains(Object obj) {
|
||
|
return getPartition(obj).contains(obj);
|
||
|
}
|
||
|
|
||
|
@Override // java.util.Collection
|
||
|
public boolean containsAll(Collection<? extends Object> collection) {
|
||
|
m.checkNotNullParameter(collection, "elements");
|
||
|
for (T t : this.partitions) {
|
||
|
collection = u.minus((Iterable) collection, (Iterable) t);
|
||
|
}
|
||
|
return collection.isEmpty();
|
||
|
}
|
||
|
|
||
|
public final Function1<E, Integer> getPartitionStrategy() {
|
||
|
return this.partitionStrategy;
|
||
|
}
|
||
|
|
||
|
public final List<T> getPartitions() {
|
||
|
return this.partitions;
|
||
|
}
|
||
|
|
||
|
public int getSize() {
|
||
|
return this.size;
|
||
|
}
|
||
|
|
||
|
@Override // java.util.Collection
|
||
|
public boolean isEmpty() {
|
||
|
return size() == 0;
|
||
|
}
|
||
|
|
||
|
@Override // java.util.Collection, java.lang.Iterable
|
||
|
public MutablePartitionedIterator<E> iterator() {
|
||
|
return new MutablePartitionedIterator<>(this.partitions.iterator());
|
||
|
}
|
||
|
|
||
|
/* JADX DEBUG: Multi-variable search result rejected for r2v0, resolved type: java.lang.Object */
|
||
|
/* JADX WARN: Multi-variable type inference failed */
|
||
|
@Override // java.util.Collection
|
||
|
public boolean remove(Object obj) {
|
||
|
boolean remove = getPartition(obj).remove(obj);
|
||
|
if (remove) {
|
||
|
setSize(size() - 1);
|
||
|
}
|
||
|
return remove;
|
||
|
}
|
||
|
|
||
|
@Override // java.util.Collection
|
||
|
public boolean removeAll(Collection<? extends Object> collection) {
|
||
|
m.checkNotNullParameter(collection, "elements");
|
||
|
Iterator<T> it = collection.iterator();
|
||
|
while (true) {
|
||
|
boolean z2 = false;
|
||
|
while (true) {
|
||
|
if (!it.hasNext()) {
|
||
|
return z2;
|
||
|
}
|
||
|
if (remove(it.next()) || z2) {
|
||
|
z2 = true;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override // java.util.Collection
|
||
|
public boolean retainAll(Collection<? extends Object> collection) {
|
||
|
m.checkNotNullParameter(collection, "elements");
|
||
|
Iterator<T> it = this.partitions.iterator();
|
||
|
while (true) {
|
||
|
boolean z2 = false;
|
||
|
while (true) {
|
||
|
if (!it.hasNext()) {
|
||
|
return z2;
|
||
|
}
|
||
|
if (((Collection) it.next()).retainAll(collection) || z2) {
|
||
|
z2 = true;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void setSize(int i) {
|
||
|
this.size = i;
|
||
|
}
|
||
|
|
||
|
@Override // java.util.Collection
|
||
|
public final /* bridge */ int size() {
|
||
|
return getSize();
|
||
|
}
|
||
|
|
||
|
@Override // java.util.Collection
|
||
|
public Object[] toArray() {
|
||
|
return g.toArray(this);
|
||
|
}
|
||
|
|
||
|
@Override // java.util.Collection
|
||
|
public <T> T[] toArray(T[] tArr) {
|
||
|
return (T[]) g.toArray(this, tArr);
|
||
|
}
|
||
|
}
|