From 37f51db0d97bf9865b0c8748012bc55e94327060 Mon Sep 17 00:00:00 2001 From: yueh Date: Mon, 15 Jun 2015 19:47:45 +0200 Subject: [PATCH] Changed to immutable list to prevent direct modifcations --- .../api/features/IInscriberRegistry.java | 27 ++++++++++----- .../registries/InscriberRegistry.java | 33 +++++++++++++++---- 2 files changed, 44 insertions(+), 16 deletions(-) diff --git a/src/api/java/appeng/api/features/IInscriberRegistry.java b/src/api/java/appeng/api/features/IInscriberRegistry.java index c8882849..330dc4de 100644 --- a/src/api/java/appeng/api/features/IInscriberRegistry.java +++ b/src/api/java/appeng/api/features/IInscriberRegistry.java @@ -1,11 +1,15 @@ + package appeng.api.features; +import java.util.Collection; import java.util.List; import java.util.Set; import javax.annotation.Nonnull; +import com.google.common.base.Optional; + import net.minecraft.item.ItemStack; @@ -13,22 +17,26 @@ import net.minecraft.item.ItemStack; * Lets you manipulate Inscriber Recipes, by adding or editing existing ones. * * @author thatsIch - * @version rv2 + * @version rv3 * @since rv2 */ public interface IInscriberRegistry { /** - * Current list of registered recipes, you can modify this if you want too. - * Will never contain a null recipe + * An immutable copy of currently registered recipes. + * + * Use the provided methods to actually modify the inscriber recipes. + * + * @see IInscriberRegistry#addRecipe(IInscriberRecipe) + * @see IInscriberRegistry#removeRecipe(IInscriberRecipe) * * @return currentlyRegisteredRecipes */ @Nonnull - List getRecipes(); + Collection getRecipes(); /** - * Optional items which are used in the top or bottom slot + * Optional items which are used in the top or bottom slot. * * @return set of all optional items */ @@ -36,7 +44,7 @@ public interface IInscriberRegistry Set getOptionals(); /** - * Get all registered items which are valid inputs + * Get all registered items which are valid inputs. * * @return set of all input items */ @@ -44,7 +52,7 @@ public interface IInscriberRegistry Set getInputs(); /** - * Extensible way to create an inscriber recipe + * Extensible way to create an inscriber recipe. * * @return builder for inscriber recipes */ @@ -62,9 +70,10 @@ public interface IInscriberRegistry void addRecipe( IInscriberRecipe recipe ); /** - * Removes a recipe from the registry + * Removes all equal recipes from the registry. * - * @param toBeRemovedRecipe to be removed recipe, can be null, makes just no sense + * @param toBeRemovedRecipe to be removed recipe, can be null, makes just no sense. */ void removeRecipe( IInscriberRecipe toBeRemovedRecipe ); + } diff --git a/src/main/java/appeng/core/features/registries/InscriberRegistry.java b/src/main/java/appeng/core/features/registries/InscriberRegistry.java index 8c0fce82..9c985370 100644 --- a/src/main/java/appeng/core/features/registries/InscriberRegistry.java +++ b/src/main/java/appeng/core/features/registries/InscriberRegistry.java @@ -1,8 +1,27 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2015, 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 . + */ + package appeng.core.features.registries; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -20,12 +39,12 @@ import appeng.core.features.registries.entries.InscriberRecipe; /** * @author thatsIch - * @version rv2 + * @version rv3 * @since rv2 */ public final class InscriberRegistry implements IInscriberRegistry { - private final List recipes; + private final Set recipes; private final Set optionals; private final Set inputs; @@ -33,14 +52,14 @@ public final class InscriberRegistry implements IInscriberRegistry { this.inputs = new HashSet(); this.optionals = new HashSet(); - this.recipes = new ArrayList(); + this.recipes = new HashSet(); } @Nonnull @Override - public List getRecipes() + public Collection getRecipes() { - return this.recipes; + return Collections.unmodifiableCollection( this.recipes ); } @Nonnull @@ -167,11 +186,11 @@ public final class InscriberRegistry implements IInscriberRegistry { throw new IllegalStateException( "Output must be defined." ); } - if ( this.topOptional == null && this.bottomOptional == null ) + if( this.topOptional == null && this.bottomOptional == null ) { throw new IllegalStateException( "One optional must be defined." ); } - if ( this.type == null ) + if( this.type == null ) { throw new IllegalStateException( "Process type must be defined." ); }