refactoring: Issue #2377: The repository code has been refactored to use the recor… (#2505)

* Issue #2377: The repository code has been refactored to use the record class

* Issue #2377: Refactored according to the rules defined for the repo code

* Issue #2377: Refactored according to the rules defined for the repo code

* Issue #2377: Refactored according to the rules defined for the repo code
This commit is contained in:
Mughees Qasim
2023-05-06 12:08:12 +03:00
committed by GitHub
parent c0e1603f90
commit 3ae6b07590
26 changed files with 244 additions and 293 deletions
@@ -25,48 +25,13 @@
package com.iluwatar.builder;
/**
* Hero, the class with many parameters.
* Hero,the record class.
*/
public final class Hero {
private final Profession profession;
private final String name;
private final HairType hairType;
private final HairColor hairColor;
private final Armor armor;
private final Weapon weapon;
public record Hero(Profession profession, String name, HairType hairType, HairColor hairColor, Armor armor, Weapon weapon) {
private Hero(Builder builder) {
this.profession = builder.profession;
this.name = builder.name;
this.hairColor = builder.hairColor;
this.hairType = builder.hairType;
this.weapon = builder.weapon;
this.armor = builder.armor;
}
public Profession getProfession() {
return profession;
}
public String getName() {
return name;
}
public HairType getHairType() {
return hairType;
}
public HairColor getHairColor() {
return hairColor;
}
public Armor getArmor() {
return armor;
}
public Weapon getWeapon() {
return weapon;
this(builder.profession, builder.name, builder.hairType, builder.hairColor, builder.armor, builder.weapon);
}
@Override
@@ -69,12 +69,12 @@ class HeroTest {
assertNotNull(hero);
assertNotNull(hero.toString());
assertEquals(Profession.WARRIOR, hero.getProfession());
assertEquals(heroName, hero.getName());
assertEquals(Armor.CHAIN_MAIL, hero.getArmor());
assertEquals(Weapon.SWORD, hero.getWeapon());
assertEquals(HairType.LONG_CURLY, hero.getHairType());
assertEquals(HairColor.BLOND, hero.getHairColor());
assertEquals(Profession.WARRIOR, hero.profession());
assertEquals(heroName, hero.name());
assertEquals(Armor.CHAIN_MAIL, hero.armor());
assertEquals(Weapon.SWORD, hero.weapon());
assertEquals(HairType.LONG_CURLY, hero.hairType());
assertEquals(HairColor.BLOND, hero.hairColor());
}