Utils ported

This commit is contained in:
Sebastian Hartte
2020-06-28 13:28:14 +02:00
parent fee5b7fdfc
commit 46955643b9
105 changed files with 239 additions and 379 deletions
@@ -1,55 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.util.iterators;
import java.util.Iterator;
import appeng.api.storage.data.IAEItemStack;
import appeng.tile.inventory.AppEngInternalAEInventory;
public final class AEInvIterator implements Iterator<IAEItemStack> {
private final AppEngInternalAEInventory inventory;
private final int size;
private int counter = 0;
public AEInvIterator(final AppEngInternalAEInventory inventory) {
this.inventory = inventory;
this.size = this.inventory.getSlots();
}
@Override
public boolean hasNext() {
return this.counter < this.size;
}
@Override
public IAEItemStack next() {
final IAEItemStack result = this.inventory.getAEStackInSlot(this.counter);
this.counter++;
return result;
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
}
@@ -1,48 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.util.iterators;
import java.util.Iterator;
public final class ChainedIterator<T> implements Iterator<T> {
private final T[] list;
private int offset = 0;
public ChainedIterator(final T... list) {
this.list = list;
}
@Override
public boolean hasNext() {
return this.offset < this.list.length;
}
@Override
public T next() {
final T result = this.list[this.offset];
this.offset++;
return result;
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
}
@@ -1,54 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.util.iterators;
import java.util.Iterator;
import alexiil.mc.lib.attributes.item.FixedItemInv;
import net.minecraft.item.ItemStack;
public final class InvIterator implements Iterator<ItemStack> {
private final FixedItemInv inventory;
private final int size;
private int counter = 0;
public InvIterator(final FixedItemInv inventory) {
this.inventory = inventory;
this.size = this.inventory.getSlotCount();
}
@Override
public boolean hasNext() {
return this.counter < this.size;
}
@Override
public ItemStack next() {
final ItemStack result = this.inventory.getInvStack(this.counter);
this.counter++;
return result;
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
}
@@ -1,39 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.util.iterators;
import java.util.Iterator;
public class NullIterator<T> implements Iterator<T> {
@Override
public boolean hasNext() {
return false;
}
@Override
public T next() {
return null;
}
@Override
public void remove() {
}
}
@@ -1,49 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.util.iterators;
import java.util.Iterator;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.util.AEPartLocation;
public final class ProxyNodeIterator implements Iterator<IGridNode> {
private final Iterator<IGridHost> hosts;
public ProxyNodeIterator(final Iterator<IGridHost> hosts) {
this.hosts = hosts;
}
@Override
public boolean hasNext() {
return this.hosts.hasNext();
}
@Override
public IGridNode next() {
final IGridHost host = this.hosts.next();
return host.getGridNode(AEPartLocation.INTERNAL);
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
}
@@ -1,54 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.util.iterators;
import java.util.Iterator;
import net.minecraft.item.ItemStack;
import appeng.util.inv.ItemSlot;
public class StackToSlotIterator implements Iterator<ItemSlot> {
private final ItemSlot iss = new ItemSlot();
private final Iterator<ItemStack> is;
private int x = 0;
public StackToSlotIterator(final Iterator<ItemStack> is) {
this.is = is;
}
@Override
public boolean hasNext() {
return this.is.hasNext();
}
@Override
public ItemSlot next() {
this.iss.setSlot(this.x);
this.x++;
this.iss.setItemStack(this.is.next());
return this.iss;
}
@Override
public void remove() {
// uhh no.
}
}