mirror of
https://github.com/GTNewHorizons/Mantle.git
synced 2026-11-18 11:19:20 +00:00
ImmutableConcatList: A list implementation that iterates over multiple lists, treating them as one without copying any elements
This commit is contained in:
1 parent
2ee481e9b4
commit
1f0abcdcd7
2 files changed
+228
-2
No files matched your search
@@ -21,7 +21,7 @@ import javax.vecmath.Matrix4f;
|
||||
|
||||
public class BakedSimple implements IPerspectiveAwareModel {
|
||||
|
||||
private final ImmutableList<BakedQuad> quads;
|
||||
private final List<BakedQuad> quads;
|
||||
private final ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transforms;
|
||||
private final TextureAtlasSprite particle;
|
||||
private final boolean ambientOcclusion;
|
||||
@@ -29,6 +29,17 @@ public class BakedSimple implements IPerspectiveAwareModel {
|
||||
private final ItemOverrideList overrides;
|
||||
|
||||
public BakedSimple(ImmutableList<BakedQuad> quads, ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transforms, IBakedModel base) {
|
||||
this(
|
||||
(List<BakedQuad>)quads,
|
||||
transforms,
|
||||
base.getParticleTexture(),
|
||||
base.isAmbientOcclusion(),
|
||||
base.isGui3d(),
|
||||
base.getOverrides()
|
||||
);
|
||||
}
|
||||
|
||||
public BakedSimple(List<BakedQuad> quads, ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transforms, IBakedModel base) {
|
||||
this(
|
||||
quads,
|
||||
transforms,
|
||||
@@ -39,7 +50,7 @@ public class BakedSimple implements IPerspectiveAwareModel {
|
||||
);
|
||||
}
|
||||
|
||||
public BakedSimple(ImmutableList<BakedQuad> quads, ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transforms, TextureAtlasSprite particle, boolean ambientOcclusion, boolean isGui3d, ItemOverrideList overrides) {
|
||||
public BakedSimple(List<BakedQuad> quads, ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transforms, TextureAtlasSprite particle, boolean ambientOcclusion, boolean isGui3d, ItemOverrideList overrides) {
|
||||
this.quads = quads;
|
||||
this.particle = particle;
|
||||
this.transforms = transforms;
|
||||
|
||||
@@ -0,0 +1,215 @@
|
||||
package slimeknights.mantle.util;
|
||||
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.UnmodifiableListIterator;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkPositionIndex;
|
||||
|
||||
public class ImmutableConcatList<E> implements List<E> {
|
||||
|
||||
protected final FluentIterable<E> iterable;
|
||||
|
||||
public ImmutableConcatList(List<E>... lists) {
|
||||
iterable = FluentIterable.from(Iterables.concat(lists));
|
||||
}
|
||||
|
||||
public ImmutableConcatList(List<List<E>> lists) {
|
||||
iterable = FluentIterable.from(Iterables.concat(lists));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return iterable.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return iterable.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
return iterable.contains(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<E> iterator() {
|
||||
return iterable.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] toArray() {
|
||||
return iterable.toList().toArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T[] toArray(T[] a) {
|
||||
return iterable.toList().toArray(a);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(E e) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Object o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAll(Collection<?> c) {
|
||||
for (Object e : c)
|
||||
if (!contains(e))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(Collection<? extends E> c) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(int index, Collection<? extends E> c) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAll(Collection<?> c) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll(Collection<?> c) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public E get(int index) {
|
||||
return iterable.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public E set(int index, E element) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(int index, E element) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public E remove(int index) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int indexOf(final Object o) {
|
||||
Iterator<E> iterator = iterable.iterator();
|
||||
for (int i = 0; iterator.hasNext(); i++) {
|
||||
if(o == iterator.next()) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int lastIndexOf(Object o) {
|
||||
Iterator<E> iterator = iterable.iterator();
|
||||
int j = -1;
|
||||
for (int i = 0; iterator.hasNext(); i++) {
|
||||
if(o == iterator.next()) {
|
||||
j = i;
|
||||
}
|
||||
}
|
||||
|
||||
return j;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListIterator<E> listIterator() {
|
||||
return listIterator(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListIterator<E> listIterator(int index) {
|
||||
return new ListItr<E>(this.size(), index) {
|
||||
@Override
|
||||
protected E get(int index) {
|
||||
return ImmutableConcatList.this.get(index);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<E> subList(int fromIndex, int toIndex) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
// basically a copy of AbstractIndexedListIterator
|
||||
private abstract static class ListItr<E> extends UnmodifiableListIterator<E> {
|
||||
|
||||
private final int size;
|
||||
private int position;
|
||||
|
||||
public ListItr(int size, int position) {
|
||||
checkPositionIndex(position, size);
|
||||
this.size = size;
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
protected abstract E get(int index);
|
||||
|
||||
@Override
|
||||
public final boolean hasNext() {
|
||||
return position < size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final E next() {
|
||||
if (!hasNext()) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
return get(position++);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int nextIndex() {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean hasPrevious() {
|
||||
return position > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final E previous() {
|
||||
if (!hasPrevious()) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
return get(--position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int previousIndex() {
|
||||
return position - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user