Replaced normal for loops with foreach loops which is less error prone when just iterating over collection/array

This commit is contained in:
thatsIch 2014-09-29 09:23:02 +02:00
parent 72106c877d
commit caffaef835
15 changed files with 88 additions and 60 deletions

View file

@ -359,28 +359,32 @@ public abstract class AEBaseContainer extends Container
tis = shiftStoreItem( tis ); tis = shiftStoreItem( tis );
// target slots in the container... // target slots in the container...
for (int x = 0; x < this.inventorySlots.size(); x++) for (Object inventorySlot : this.inventorySlots)
{ {
AppEngSlot cs = (AppEngSlot) this.inventorySlots.get( x ); AppEngSlot cs = (AppEngSlot) inventorySlot;
if ( !(cs.isPlayerSide()) && !(cs instanceof SlotFake) && !(cs instanceof SlotCraftingMatrix) ) if ( !(cs.isPlayerSide()) && !(cs instanceof SlotFake) && !(cs instanceof SlotCraftingMatrix) )
{ {
if ( cs.isItemValid( tis ) ) if ( cs.isItemValid( tis ) )
{
selectedSlots.add( cs ); selectedSlots.add( cs );
}
} }
} }
} }
else else
{ {
// target slots in the container... // target slots in the container...
for (int x = 0; x < this.inventorySlots.size(); x++) for (Object inventorySlot : this.inventorySlots)
{ {
AppEngSlot cs = (AppEngSlot) this.inventorySlots.get( x ); AppEngSlot cs = (AppEngSlot) inventorySlot;
if ( (cs.isPlayerSide()) && !(cs instanceof SlotFake) && !(cs instanceof SlotCraftingMatrix) ) if ( (cs.isPlayerSide()) && !(cs instanceof SlotFake) && !(cs instanceof SlotCraftingMatrix) )
{ {
if ( cs.isItemValid( tis ) ) if ( cs.isItemValid( tis ) )
{
selectedSlots.add( cs ); selectedSlots.add( cs );
}
} }
} }
} }
@ -393,15 +397,17 @@ public abstract class AEBaseContainer extends Container
if ( tis != null ) if ( tis != null )
{ {
// target slots in the container... // target slots in the container...
for (int x = 0; x < this.inventorySlots.size(); x++) for (Object inventorySlot : this.inventorySlots)
{ {
AppEngSlot cs = (AppEngSlot) this.inventorySlots.get( x ); AppEngSlot cs = (AppEngSlot) inventorySlot;
ItemStack dest = cs.getStack(); ItemStack dest = cs.getStack();
if ( !(cs.isPlayerSide()) && cs instanceof SlotFake ) if ( !(cs.isPlayerSide()) && cs instanceof SlotFake )
{ {
if ( Platform.isSameItemPrecise( dest, tis ) ) if ( Platform.isSameItemPrecise( dest, tis ) )
{
return null; return null;
}
else if ( dest == null ) else if ( dest == null )
{ {
cs.putStack( tis.copy() ); cs.putStack( tis.copy() );
@ -562,12 +568,14 @@ public abstract class AEBaseContainer extends Container
if ( Platform.isServer() ) if ( Platform.isServer() )
{ {
for (int i = 0; i < this.crafters.size(); ++i) for (Object crafter : this.crafters)
{ {
ICrafting icrafting = (ICrafting) this.crafters.get( i ); ICrafting icrafting = (ICrafting) crafter;
for (SyncDat sd : syncData.values()) for (SyncDat sd : syncData.values())
{
sd.tick( icrafting ); sd.tick( icrafting );
}
} }
} }

View file

@ -242,9 +242,9 @@ public class ContainerCellWorkbench extends ContainerUpgradeable
ItemStack is = workBench.getInventoryByName( "cell" ).getStackInSlot( 0 ); ItemStack is = workBench.getInventoryByName( "cell" ).getStackInSlot( 0 );
if ( Platform.isServer() ) if ( Platform.isServer() )
{ {
for (int i = 0; i < this.crafters.size(); ++i) for (Object crafter : this.crafters)
{ {
ICrafting icrafting = (ICrafting) this.crafters.get( i ); ICrafting icrafting = (ICrafting) crafter;
if ( prevStack != is ) if ( prevStack != is )
{ {

View file

@ -152,11 +152,11 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IConfigMa
if ( sideLocal != sideRemote ) if ( sideLocal != sideRemote )
{ {
clientCM.putSetting( set, sideLocal ); clientCM.putSetting( set, sideLocal );
for (int j = 0; j < this.crafters.size(); ++j) for (Object crafter : this.crafters)
{ {
try try
{ {
NetworkHandler.instance.sendTo( new PacketValueConfig( set.name(), sideLocal.name() ), (EntityPlayerMP) this.crafters.get( j ) ); NetworkHandler.instance.sendTo( new PacketValueConfig( set.name(), sideLocal.name() ), (EntityPlayerMP) crafter );
} }
catch (IOException e) catch (IOException e)
{ {

View file

@ -262,9 +262,9 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
List<ItemStack> list = new ArrayList<ItemStack>( 3 ); List<ItemStack> list = new ArrayList<ItemStack>( 3 );
boolean hasValue = false; boolean hasValue = false;
for (int x = 0; x < outputSlots.length; x++) for (OptionalSlotFake outputSlot : outputSlots)
{ {
ItemStack out = outputSlots[x].getStack(); ItemStack out = outputSlot.getStack();
if ( out != null && out.stackSize > 0 ) if ( out != null && out.stackSize > 0 )
{ {
list.add( out ); list.add( out );
@ -395,9 +395,9 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
{ {
if ( s == patternSlotOUT && Platform.isServer() ) if ( s == patternSlotOUT && Platform.isServer() )
{ {
for (int i = 0; i < this.crafters.size(); ++i) for (Object crafter : this.crafters)
{ {
ICrafting icrafting = (ICrafting) this.crafters.get( i ); ICrafting icrafting = (ICrafting) crafter;
for (Object g : inventorySlots) for (Object g : inventorySlots)
{ {

View file

@ -134,9 +134,9 @@ public class ContainerSecurity extends ContainerMEMonitorable implements IAEAppE
wirelessOut.putStack( term ); wirelessOut.putStack( term );
// update the two slots in question... // update the two slots in question...
for (int i = 0; i < this.crafters.size(); ++i) for (Object crafter : this.crafters)
{ {
ICrafting icrafting = (ICrafting) this.crafters.get( i ); ICrafting icrafting = (ICrafting) crafter;
((EntityPlayerMP) icrafting).sendSlotContents( this, wirelessIn.slotNumber, wirelessIn.getStack() ); ((EntityPlayerMP) icrafting).sendSlotContents( this, wirelessIn.slotNumber, wirelessIn.getStack() );
((EntityPlayerMP) icrafting).sendSlotContents( this, wirelessOut.slotNumber, wirelessOut.getStack() ); ((EntityPlayerMP) icrafting).sendSlotContents( this, wirelessOut.slotNumber, wirelessOut.getStack() );
} }

View file

@ -150,10 +150,12 @@ public class MultiCraftingTracker
jobs[slot] = l; jobs[slot] = l;
boolean hasStuff = false; boolean hasStuff = false;
for (int x = 0; x < jobs.length; x++) for (Future<ICraftingJob> job : jobs)
{ {
if ( jobs[x] != null ) if ( job != null )
{
hasStuff = true; hasStuff = true;
}
} }
if ( hasStuff == false ) if ( hasStuff == false )

View file

@ -55,9 +55,8 @@ public class NEICraftingHandler implements IOverlayHandler
if ( gui instanceof GuiCraftingTerm || gui instanceof GuiPatternTerm ) if ( gui instanceof GuiCraftingTerm || gui instanceof GuiPatternTerm )
{ {
for (int i = 0; i < ingredients.size(); i++)// identify slots for (PositionedStack positionedStack : ingredients)
{ {
PositionedStack positionedStack = ingredients.get( i );
int col = (positionedStack.relx - 25) / 18; int col = (positionedStack.relx - 25) / 18;
int row = (positionedStack.rely - 6) / 18; int row = (positionedStack.rely - 6) / 18;
if ( positionedStack.items != null && positionedStack.items.length > 0 ) if ( positionedStack.items != null && positionedStack.items.length > 0 )
@ -76,9 +75,13 @@ public class NEICraftingHandler implements IOverlayHandler
for (int x = 0; x < positionedStack.items.length; x++) for (int x = 0; x < positionedStack.items.length; x++)
{ {
if ( Platform.isRecipePrioritized( positionedStack.items[x] ) ) if ( Platform.isRecipePrioritized( positionedStack.items[x] ) )
{
list.add( 0, positionedStack.items[x] ); list.add( 0, positionedStack.items[x] );
}
else else
{
list.add( positionedStack.items[x] ); list.add( positionedStack.items[x] );
}
} }
for (ItemStack is : list) for (ItemStack is : list)

View file

@ -89,22 +89,26 @@ public class ItemEncodedPattern extends AEBaseItem implements ICraftingPatternIt
String with = GuiText.With.getLocal() + ": "; String with = GuiText.With.getLocal() + ": ";
boolean first = true; boolean first = true;
for (int x = 0; x < out.length; x++) for (IAEItemStack anOut : out)
{ {
if ( out[x] == null ) if ( anOut == null )
{
continue; continue;
}
l.add( (first ? label : and) + out[x].getStackSize() + " " + Platform.getItemDisplayName( out[x] ) ); l.add( (first ? label : and) + anOut.getStackSize() + " " + Platform.getItemDisplayName( anOut ) );
first = false; first = false;
} }
first = true; first = true;
for (int x = 0; x < in.length; x++) for (IAEItemStack anIn : in)
{ {
if ( in[x] == null ) if ( anIn == null )
{
continue; continue;
}
l.add( (first ? with : and) + in[x].getStackSize() + " " + Platform.getItemDisplayName( in[x] ) ); l.add( (first ? with : and) + anIn.getStackSize() + " " + Platform.getItemDisplayName( anIn ) );
first = false; first = false;
} }
} }

View file

@ -595,10 +595,12 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
IAEItemStack[] input = details.getInputs(); IAEItemStack[] input = details.getInputs();
double sum = 0; double sum = 0;
for (int x = 0; x < input.length; x++) for (IAEItemStack anInput : input)
{ {
if ( input[x] != null ) if ( anInput != null )
sum += input[x].getStackSize(); {
sum += anInput.getStackSize();
}
} }
// power... // power...

View file

@ -35,9 +35,13 @@ public class Shaped implements ICraftHandler, IWebsiteSerializer
cols = input.get( 0 ).size(); cols = input.get( 0 ).size();
if ( cols <= 3 && cols >= 1 ) if ( cols <= 3 && cols >= 1 )
{ {
for (int x = 0; x < input.size(); x++) for (List<IIngredient> anInput : input)
if ( input.get( x ).size() != cols ) {
if ( anInput.size() != cols )
{
throw new RecipeError( "all rows in a shaped crafting recipe must contain the same number of ingredients." ); throw new RecipeError( "all rows in a shaped crafting recipe must contain the same number of ingredients." );
}
}
inputs = input; inputs = input;
this.output = output.get( 0 ).get( 0 ); this.output = output.get( 0 ).get( 0 );

View file

@ -61,18 +61,19 @@ public class Shapeless implements ICraftHandler, IWebsiteSerializer
@Override @Override
public boolean canCraft(ItemStack reqOutput) throws RegistrationError, MissingIngredientError { public boolean canCraft(ItemStack reqOutput) throws RegistrationError, MissingIngredientError {
for ( int y = 0; y < inputs.size(); y++ ) for (IIngredient i : inputs)
{ {
IIngredient i = inputs.get(y); if ( !i.isAir() )
if ( !i.isAir() ) {
for (ItemStack r : i.getItemStackSet())
{ {
for ( ItemStack r : i.getItemStackSet() ) if ( Platform.isSameItemPrecise( r, reqOutput ) )
{ {
if ( Platform.isSameItemPrecise( r, reqOutput) ) return false;
return false;
} }
} }
} }
}
return Platform.isSameItemPrecise( output.getItemStack(),reqOutput ); return Platform.isSameItemPrecise( output.getItemStack(),reqOutput );
} }

View file

@ -576,10 +576,8 @@ public class Platform
CraftingManager cm = CraftingManager.getInstance(); CraftingManager cm = CraftingManager.getInstance();
List<IRecipe> rl = cm.getRecipeList(); List<IRecipe> rl = cm.getRecipeList();
for (int x = 0; x < rl.size(); ++x) for (IRecipe r : rl)
{ {
IRecipe r = rl.get( x );
if ( r.matches( par1InventoryCrafting, par2World ) ) if ( r.matches( par1InventoryCrafting, par2World ) )
{ {
return r; return r;

View file

@ -89,10 +89,13 @@ public class AdaptorISpecialInventory extends InventoryAdaptor
if ( slots == null ) if ( slots == null )
return false; return false;
int s = slots.length; for (int slot : slots)
for (int x = 0; x < s; x++) {
if ( i.getStackInSlot( slots[x] ) != null ) if ( i.getStackInSlot( slot ) != null )
{
return true; return true;
}
}
return false; return false;
} }

View file

@ -52,16 +52,18 @@ public class AdaptorList extends InventoryAdaptor
@Override @Override
public ItemStack simulateSimilarRemove(int how_many, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination dest) public ItemStack simulateSimilarRemove(int how_many, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination dest)
{ {
int s = i.size(); for (ItemStack is : i)
for (int x = 0; x < s; x++)
{ {
ItemStack is = i.get( x );
if ( is != null && (filter == null || Platform.isSameItemFuzzy( is, filter, fuzzyMode )) ) if ( is != null && (filter == null || Platform.isSameItemFuzzy( is, filter, fuzzyMode )) )
{ {
if ( how_many > is.stackSize ) if ( how_many > is.stackSize )
{
how_many = is.stackSize; how_many = is.stackSize;
}
if ( dest != null && !dest.canInsert( is ) ) if ( dest != null && !dest.canInsert( is ) )
{
how_many = 0; how_many = 0;
}
if ( how_many > 0 ) if ( how_many > 0 )
{ {
@ -109,16 +111,18 @@ public class AdaptorList extends InventoryAdaptor
@Override @Override
public ItemStack simulateRemove(int how_many, ItemStack filter, IInventoryDestination dest) public ItemStack simulateRemove(int how_many, ItemStack filter, IInventoryDestination dest)
{ {
int s = i.size(); for (ItemStack is : i)
for (int x = 0; x < s; x++)
{ {
ItemStack is = i.get( x );
if ( is != null && (filter == null || Platform.isSameItemPrecise( is, filter )) ) if ( is != null && (filter == null || Platform.isSameItemPrecise( is, filter )) )
{ {
if ( how_many > is.stackSize ) if ( how_many > is.stackSize )
{
how_many = is.stackSize; how_many = is.stackSize;
}
if ( dest != null && !dest.canInsert( is ) ) if ( dest != null && !dest.canInsert( is ) )
{
how_many = 0; how_many = 0;
}
if ( how_many > 0 ) if ( how_many > 0 )
{ {
@ -142,10 +146,8 @@ public class AdaptorList extends InventoryAdaptor
ItemStack left = A.copy(); ItemStack left = A.copy();
int s = i.size(); for (ItemStack is : i)
for (int x = 0; x < s; x++)
{ {
ItemStack is = i.get( x );
if ( Platform.isSameItem( is, left ) ) if ( Platform.isSameItem( is, left ) )
{ {
is.stackSize += left.stackSize; is.stackSize += left.stackSize;
@ -166,13 +168,12 @@ public class AdaptorList extends InventoryAdaptor
@Override @Override
public boolean containsItems() public boolean containsItems()
{ {
for (ItemStack is : i)
int s = i.size();
for (int x = 0; x < s; x++)
{ {
ItemStack is = i.get( x );
if ( is != null ) if ( is != null )
{
return true; return true;
}
} }
return false; return false;
} }

View file

@ -16,11 +16,13 @@ public class WrapperInventoryRange implements IInventory
if ( s.length > 0 ) if ( s.length > 0 )
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (int i = 0; i < s.length; i++) for (int value : s)
{ {
if ( sb.length() > 0 ) if ( sb.length() > 0 )
{
sb.append( separator ); sb.append( separator );
sb.append( s[i] ); }
sb.append( value );
} }
return sb.toString(); return sb.toString();
} }