MerchantRecipeConverter.java 文件源码

java
阅读 23 收藏 0 点赞 0 评论 0

项目:SimpleEgg 作者:
/**
 * Takes in a String produced by
 * {@link #toString(MerchantRecipe) toString(MerchantRecipe)} and converts
 * it to a MerchantRecipe.
 * @param string - The String to convert.
 * @return A MerchantRecipe with the attributes specified in the String.
 * @throws IllegalArgumentException If the String has an unexpected number
 * of attributes.
 */
public static MerchantRecipe fromString(String string) throws IllegalArgumentException {
    String[] attributes = string.split(" ");

    if (attributes.length != 5) {
        throw new IllegalArgumentException("Input string has an unexpected number of attributes!");
    }

    String resultString = attributes[0], ingredientString = attributes[1], usesString = attributes[2], maxUsesString = attributes[3], experienceString = attributes[4];

    ItemStack result = itemStackListFromString(resultString).get(0);
    ArrayList<ItemStack> ingredients = itemStackListFromString(ingredientString);
    int uses = Integer.parseInt(usesString);
    int maxUses = Integer.parseInt(maxUsesString);
    boolean experience = Boolean.parseBoolean(experienceString);
    MerchantRecipe ret = new MerchantRecipe(result, uses, maxUses, experience);
    ret.setIngredients(ingredients);
    return ret;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号