mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-08-05 08:23:06 +00:00
* 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:
@@ -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());
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user