Replaced all instances of Guava's Optional type with Java 8's Optional type, as discussed in #81. (#90)
This commit is contained in:
committed by
Sebastian Hartte
parent
c2a239a12f
commit
e276aa682f
@@ -19,7 +19,7 @@
|
||||
package appeng.core.features;
|
||||
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import java.util.Optional;
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
@@ -38,7 +38,7 @@ public class BlockDefinition extends ItemDefinition implements IBlockDefinition
|
||||
public BlockDefinition( String registryName, Block block, ItemBlock item )
|
||||
{
|
||||
super( registryName, item );
|
||||
this.block = Optional.fromNullable( block );
|
||||
this.block = Optional.ofNullable( block );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -50,7 +50,7 @@ public class BlockDefinition extends ItemDefinition implements IBlockDefinition
|
||||
@Override
|
||||
public final Optional<ItemBlock> maybeItemBlock()
|
||||
{
|
||||
return this.block.transform( ItemBlock::new );
|
||||
return this.block.map( ItemBlock::new );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -58,12 +58,12 @@ public class BlockDefinition extends ItemDefinition implements IBlockDefinition
|
||||
{
|
||||
Preconditions.checkArgument( stackSize > 0 );
|
||||
|
||||
return this.block.transform( b -> new ItemStack( b, stackSize ) );
|
||||
return this.block.map( b -> new ItemStack( b, stackSize ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isSameAs( final IBlockAccess world, final BlockPos pos )
|
||||
{
|
||||
return this.isEnabled() && world.getBlockState( pos ).getBlock() == this.block.get();
|
||||
return block.isPresent() && world.getBlockState( pos ).getBlock() == this.block.get();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,10 +19,9 @@
|
||||
package appeng.core.features;
|
||||
|
||||
|
||||
import java.util.Optional;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
@@ -34,7 +33,6 @@ import appeng.api.definitions.IItemDefinition;
|
||||
public final class DamagedItemDefinition implements IItemDefinition
|
||||
{
|
||||
private final String identifier;
|
||||
private static final ItemTransformer ITEM_TRANSFORMER = new ItemTransformer();
|
||||
private final Optional<IStackSrc> source;
|
||||
|
||||
public DamagedItemDefinition( @Nonnull final String identifier, @Nonnull final IStackSrc source )
|
||||
@@ -48,7 +46,7 @@ public final class DamagedItemDefinition implements IItemDefinition
|
||||
}
|
||||
else
|
||||
{
|
||||
this.source = Optional.absent();
|
||||
this.source = Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,13 +60,13 @@ public final class DamagedItemDefinition implements IItemDefinition
|
||||
@Override
|
||||
public Optional<Item> maybeItem()
|
||||
{
|
||||
return this.source.transform( ITEM_TRANSFORMER );
|
||||
return this.source.map( IStackSrc::getItem );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ItemStack> maybeStack( final int stackSize )
|
||||
{
|
||||
return this.source.transform( new ItemStackTransformer( stackSize ) );
|
||||
return this.source.map( input -> input.stack( stackSize ));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -88,30 +86,4 @@ public final class DamagedItemDefinition implements IItemDefinition
|
||||
return this.isEnabled() && comparableStack.getItem() == this.source.get().getItem() && comparableStack.getItemDamage() == this.source.get().getDamage();
|
||||
}
|
||||
|
||||
private static class ItemTransformer implements Function<IStackSrc, Item>
|
||||
{
|
||||
@Override
|
||||
public Item apply( final IStackSrc input )
|
||||
{
|
||||
return input.getItem();
|
||||
}
|
||||
}
|
||||
|
||||
private static class ItemStackTransformer implements Function<IStackSrc, ItemStack>
|
||||
{
|
||||
private final int stackSize;
|
||||
|
||||
public ItemStackTransformer( final int stackSize )
|
||||
{
|
||||
Preconditions.checkArgument( stackSize > 0 );
|
||||
|
||||
this.stackSize = stackSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack apply( final IStackSrc input )
|
||||
{
|
||||
return input.stack( this.stackSize );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,10 +19,9 @@
|
||||
package appeng.core.features;
|
||||
|
||||
|
||||
import java.util.Optional;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
@@ -42,7 +41,7 @@ public class ItemDefinition implements IItemDefinition
|
||||
{
|
||||
Preconditions.checkArgument( !Strings.isNullOrEmpty( registryName ), "registryName" );
|
||||
this.identifier = registryName;
|
||||
this.item = Optional.fromNullable( item );
|
||||
this.item = Optional.ofNullable( item );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@@ -61,7 +60,7 @@ public class ItemDefinition implements IItemDefinition
|
||||
@Override
|
||||
public Optional<ItemStack> maybeStack( final int stackSize )
|
||||
{
|
||||
return this.item.transform( new ItemStackTransformer( stackSize ) );
|
||||
return this.item.map( item -> new ItemStack( item, stackSize ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,24 +72,7 @@ public class ItemDefinition implements IItemDefinition
|
||||
@Override
|
||||
public final boolean isSameAs( final ItemStack comparableStack )
|
||||
{
|
||||
return this.isEnabled() && Platform.isSameItemType( comparableStack, this.maybeStack( 1 ).get() );
|
||||
return isEnabled() && Platform.isSameItemType( comparableStack, this.maybeStack( 1 ).get() );
|
||||
}
|
||||
|
||||
private static class ItemStackTransformer implements Function<Item, ItemStack>
|
||||
{
|
||||
private final int stackSize;
|
||||
|
||||
public ItemStackTransformer( final int stackSize )
|
||||
{
|
||||
Preconditions.checkArgument( stackSize > 0 );
|
||||
|
||||
this.stackSize = stackSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack apply( final Item input )
|
||||
{
|
||||
return new ItemStack( input, this.stackSize );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,10 +19,9 @@
|
||||
package appeng.core.features;
|
||||
|
||||
|
||||
import java.util.Optional;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
@@ -38,12 +37,12 @@ public final class TileDefinition extends BlockDefinition implements ITileDefini
|
||||
public TileDefinition( @Nonnull String registryName, AEBaseTileBlock block, ItemBlock item )
|
||||
{
|
||||
super( registryName, block, item );
|
||||
this.block = Optional.fromNullable( block );
|
||||
this.block = Optional.ofNullable( block );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<? extends Class<? extends TileEntity>> maybeEntity()
|
||||
{
|
||||
return this.block.transform( AEBaseTileBlock::getTileEntityClass );
|
||||
return this.block.map( AEBaseTileBlock::getTileEntityClass );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,8 +94,8 @@ public final class InscriberRegistry implements IInscriberRegistry
|
||||
|
||||
this.recipes.add( recipe );
|
||||
|
||||
this.optionals.addAll( recipe.getTopOptional().asSet() );
|
||||
this.optionals.addAll( recipe.getBottomOptional().asSet() );
|
||||
recipe.getTopOptional().ifPresent( optionals::add );
|
||||
recipe.getBottomOptional().ifPresent( optionals::add );
|
||||
|
||||
this.inputs.addAll( recipe.getInputs() );
|
||||
}
|
||||
|
||||
@@ -172,9 +172,6 @@ public final class P2PTunnelRegistry implements IP2PTunnelRegistry
|
||||
|
||||
private void addNewAttunement( final IItemDefinition definition, final TunnelType type )
|
||||
{
|
||||
for( final ItemStack definitionStack : definition.maybeStack( 1 ).asSet() )
|
||||
{
|
||||
this.addNewAttunement( definitionStack, type );
|
||||
}
|
||||
definition.maybeStack( 1 ).ifPresent( definitionStack -> addNewAttunement( definitionStack, type ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import java.util.Optional;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
@@ -47,8 +47,8 @@ public class InscriberRecipe implements IInscriberRecipe
|
||||
this.inputs.addAll( inputs );
|
||||
|
||||
this.output = output;
|
||||
this.maybeTop = Optional.fromNullable( top );
|
||||
this.maybeBot = Optional.fromNullable( bot );
|
||||
this.maybeTop = Optional.ofNullable( top );
|
||||
this.maybeBot = Optional.ofNullable( bot );
|
||||
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user