<commit_before>package com.gildedrose;

class GildedRose {
  private static final int QUALITY_FLOOR = 0;
  private static final int QUALITY_CEILING = 50;
  private static final String AGED_BRIE = "Aged Brie";
  private static final String BACKSTAGE_PASSES_TO_A_TAFKAL80ETC_CONCERT = "Backstage passes to a TAFKAL80ETC concert";
  private static final String SULFURAS_HAND_OF_RAGNAROS = "Sulfuras, Hand of Ragnaros";
  Item[] items;

  public GildedRose(Item[] items) {
    this.items = items;
    for (Item item : items) {
      item.quality = (item.quality < 0) ? 0 : item.quality;
    }
  }

  public void updateQuality() {
    for (Item item : items) {
      updateItem(item);
    }
  }

  private void updateItem(Item item) {
    if (!isAgedBrie(item) && !isBackstagePass(item)) {
      if (item.quality > QUALITY_FLOOR) {
        if (!isSulfurasHandOfRagnaros(item)) {
          decrementQuality(item);
        }
      }
    } else {
      if (item.quality < QUALITY_CEILING) {
        incrementQuality(item);

        if (isBackstagePass(item)) {
          if (item.sellIn < 11) {
            if (item.quality < QUALITY_CEILING) {
              incrementQuality(item);
            }
          }

          if (item.sellIn < 6) {
            if (item.quality < QUALITY_CEILING) {
              incrementQuality(item);
            }
          }
        }
      }
    }

    if (!isSulfurasHandOfRagnaros(item)) {
      item.sellIn = item.sellIn - 1;
    }

    if (item.sellIn < 0) {
      if (!isAgedBrie(item)) {
        if (!isBackstagePass(item)) {
          if (item.quality > QUALITY_FLOOR) {
            if (!isSulfurasHandOfRagnaros(item)) {
              decrementQuality(item);
            }
          }
        } else {
          makeWorthless(item);
        }
      } else {
        if (item.quality < QUALITY_CEILING) {
          incrementQuality(item);
        }
      }
    }
  }

  private boolean isSulfurasHandOfRagnaros(Item item) {
    return item.name.equals(SULFURAS_HAND_OF_RAGNAROS);
  }

  private boolean isAgedBrie(Item item) {
    return item.name.equals(AGED_BRIE);
  }

  private boolean isBackstagePass(Item item) {
    return item.name.equals(BACKSTAGE_PASSES_TO_A_TAFKAL80ETC_CONCERT);
  }

  private void makeWorthless(Item item) {
    item.quality = item.quality - item.quality;
  }

  private void incrementQuality(Item item) {
    item.quality = item.quality + 1;
  }

  private void decrementQuality(Item item) {
    item.quality = item.quality - 1;
  }<commit_msg>refactor: extracted decrementeDaysRemainingToSell()<commit_after>package com.gildedrose;

class GildedRose {
  private static final int QUALITY_FLOOR = 0;
  private static final int QUALITY_CEILING = 50;
  private static final String AGED_BRIE = "Aged Brie";
  private static final String BACKSTAGE_PASSES_TO_A_TAFKAL80ETC_CONCERT = "Backstage passes to a TAFKAL80ETC concert";
  private static final String SULFURAS_HAND_OF_RAGNAROS = "Sulfuras, Hand of Ragnaros";
  Item[] items;

  public GildedRose(Item[] items) {
    this.items = items;
    for (Item item : items) {
      item.quality = (item.quality < 0) ? 0 : item.quality;
    }
  }

  public void updateQuality() {
    for (Item item : items) {
      updateItem(item);
    }
  }

  private void updateItem(Item item) {
    if (!isAgedBrie(item) && !isBackstagePass(item)) {
      if (item.quality > QUALITY_FLOOR) {
        if (!isSulfurasHandOfRagnaros(item)) {
          decrementQuality(item);
        }
      }
    } else {
      if (item.quality < QUALITY_CEILING) {
        incrementQuality(item);

        if (isBackstagePass(item)) {
          if (item.sellIn < 11) {
            if (item.quality < QUALITY_CEILING) {
              incrementQuality(item);
            }
          }

          if (item.sellIn < 6) {
            if (item.quality < QUALITY_CEILING) {
              incrementQuality(item);
            }
          }
        }
      }
    }

    if (!isSulfurasHandOfRagnaros(item)) {
      decrementDaysRemainingToSell(item);
    }

    if (item.sellIn < 0) {
      if (!isAgedBrie(item)) {
        if (!isBackstagePass(item)) {
          if (item.quality > QUALITY_FLOOR) {
            if (!isSulfurasHandOfRagnaros(item)) {
              decrementQuality(item);
            }
          }
        } else {
          makeWorthless(item);
        }
      } else {
        if (item.quality < QUALITY_CEILING) {
          incrementQuality(item);
        }
      }
    }
  }

  private void decrementDaysRemainingToSell(Item item) {
    item.sellIn = item.sellIn - 1;
  }

  private boolean isSulfurasHandOfRagnaros(Item item) {
    return item.name.equals(SULFURAS_HAND_OF_RAGNAROS);
  }

  private boolean isAgedBrie(Item item) {
    return item.name.equals(AGED_BRIE);
  }

  private boolean isBackstagePass(Item item) {
    return item.name.equals(BACKSTAGE_PASSES_TO_A_TAFKAL80ETC_CONCERT);
  }

  private void makeWorthless(Item item) {
    item.quality = item.quality - item.quality;
  }

  private void incrementQuality(Item item) {
    item.quality = item.quality + 1;
  }

  private void decrementQuality(Item item) {
    item.quality = item.quality - 1;
  }
{'fraction_non_alphanumeric': 0.10283275126115639, 'fraction_numerical': 0.006984866123399301, 'mean_word_length': 2.3279535183989672, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '360723', 'n_tokens_mistral': 1844, 'n_tokens_neox': 1748, 'n_words': 337}