Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.gildedrose;
- class GildedRose{
- Item[] items;
- private static final String AGED_BRIE = "Aged Brie";
- private static final String SULFURAS_HAND_RAGNAROS = "Sulfuras, Hand of Ragnaros";
- private static final String BACKSTAGE_PASS_CONCERT = "Backstage passes to a TAFKAL80ETC concert";
- private static final int LOWEST_QUALITY_VALUE_POSSIBLE = 0;
- private static final int HIGHEST_QUALITY_VALUE_POSSIBLE = 50;
- public GildedRose(Item[] items){
- this.items = items;
- }
- /*
- Méthode qui renvoi un boolean répresentant
- le test de la qualité par rapport à la valeur maximale de la Qualité
- */
- private boolean isQualityValueUnderHighest(Item item){
- return item.quality < HIGHEST_QUALITY_VALUE_POSSIBLE;
- }
- /*
- Incrémenter de 1 la valeur de qualité d'un objet
- */
- private IncrementByOneItemQualityValue(Item item){
- return item.quality + 1;
- }
- /*
- Décrementer de 1 la valeur de qualité d'un objet
- */
- private DecrementByOneItemQualityValue(Item item){
- return item.quality - 1;
- }
- public void updateQuality() {
- /*
- Modification de la boucle for
- Au lieu d'utiliser les étapes d'initialisation, de test et d'incrementation
- Nous itérons sur chaque élement
- */
- for (Item item : items) {
- if (!item.name.equals(AGED_BRIE)
- && !item.name.equals(BACKSTAGE_PASS_CONCERT)) {
- if (item.quality > LOWEST_QUALITY_VALUE_POSSIBLE) {
- if (!item.name.equals(SULFURAS_HAND_RAGNAROS)) {
- DecrementByOneItemQualityValue(item);
- }
- }
- } else {
- if (isQualityValueUnderHighest(item)) {
- IncrementByOneItemQualityValue(item)
- if (item.name.equals(BACKSTAGE_PASS_CONCERT)) {
- if (item.sellIn < 11) {
- if (isQualityValueUnderHighest(item)) {
- IncrementByOneItemQualityValue(item)
- }
- }
- if (item.sellIn < 6) {
- if (isQualityValueUnderHighest(item)) {
- IncrementByOneItemQualityValue(item)
- }
- }
- }
- }
- }
- if (!item.name.equals(SULFURAS_HAND_RAGNAROS)) {
- item.sellIn = item.sellIn - 1;
- }
- if (item.sellIn < LOWEST_QUALITY_VALUE_POSSIBLE) {
- if (!item.name.equals(AGED_BRIE)) {
- if (!item.name.equals(BACKSTAGE_PASS_CONCERT)) {
- if (item.quality > LOWEST_QUALITY_VALUE_POSSIBLE) {
- if (!item.name.equals(SULFURAS_HAND_RAGNAROS)) {
- DecrementByOneItemQualityValue(item);
- }
- }
- } else {
- item.quality = item.quality - item.quality;
- }
- } else {
- if (isQualityValueUnderHighest(item)) {
- IncrementByOneItemQualityValue(item)
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement