📍Use lombok, reformat, and optimize the code (#1560)

* Use lombok, reformat, and optimize the code

* Fix merge conflicts and some sonar issues

Co-authored-by: va1m <va1m@email.com>
This commit is contained in:
va1m
2021-03-13 13:19:21 +01:00
committed by GitHub
parent 0e26a6adb5
commit 5cf2fe009b
681 changed files with 2472 additions and 4966 deletions

View File

@ -23,8 +23,7 @@
package com.iluwatar.prototype;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
/**
* The Prototype pattern is a creational design pattern in software development. It is used when the
@ -36,10 +35,9 @@ import org.slf4j.LoggerFactory;
* <p>In this example we have a factory class ({@link HeroFactoryImpl}) producing objects by
* cloning the existing ones. The factory's prototype objects are given as constructor parameters.
*/
@Slf4j
public class App {
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
/**
* Program entry point.
*

View File

@ -23,29 +23,20 @@
package com.iluwatar.prototype;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
/**
* Beast.
*/
@EqualsAndHashCode
@NoArgsConstructor
public abstract class Beast implements Prototype {
public Beast() {
}
public Beast(Beast source) {
}
@Override
public abstract Beast copy();
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
return getClass() == obj.getClass();
}
}

View File

@ -23,17 +23,18 @@
package com.iluwatar.prototype;
import lombok.EqualsAndHashCode;
import lombok.RequiredArgsConstructor;
/**
* ElfBeast.
*/
@EqualsAndHashCode(callSuper = true)
@RequiredArgsConstructor
public class ElfBeast extends Beast {
private final String helpType;
public ElfBeast(String helpType) {
this.helpType = helpType;
}
public ElfBeast(ElfBeast elfBeast) {
super(elfBeast);
this.helpType = elfBeast.helpType;
@ -49,22 +50,4 @@ public class ElfBeast extends Beast {
return "Elven eagle helps in " + helpType;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
var other = (ElfBeast) obj;
if (helpType == null) {
return other.helpType == null;
}
return helpType.equals(other.helpType);
}
}

View File

@ -23,17 +23,18 @@
package com.iluwatar.prototype;
import lombok.EqualsAndHashCode;
import lombok.RequiredArgsConstructor;
/**
* ElfMage.
*/
@EqualsAndHashCode(callSuper = true)
@RequiredArgsConstructor
public class ElfMage extends Mage {
private final String helpType;
public ElfMage(String helpType) {
this.helpType = helpType;
}
public ElfMage(ElfMage elfMage) {
super(elfMage);
this.helpType = elfMage.helpType;
@ -49,21 +50,4 @@ public class ElfMage extends Mage {
return "Elven mage helps in " + helpType;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
var other = (ElfMage) obj;
if (helpType == null) {
return other.helpType == null;
}
return helpType.equals(other.helpType);
}
}

View File

@ -23,9 +23,12 @@
package com.iluwatar.prototype;
import lombok.EqualsAndHashCode;
/**
* ElfWarlord.
*/
@EqualsAndHashCode
public class ElfWarlord extends Warlord {
private final String helpType;
@ -48,22 +51,4 @@ public class ElfWarlord extends Warlord {
public String toString() {
return "Elven warlord helps in " + helpType;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
var other = (ElfWarlord) obj;
if (helpType == null) {
return other.helpType == null;
}
return helpType.equals(other.helpType);
}
}

View File

@ -23,24 +23,18 @@
package com.iluwatar.prototype;
import lombok.RequiredArgsConstructor;
/**
* Concrete factory class.
*/
@RequiredArgsConstructor
public class HeroFactoryImpl implements HeroFactory {
private final Mage mage;
private final Warlord warlord;
private final Beast beast;
/**
* Constructor.
*/
public HeroFactoryImpl(Mage mage, Warlord warlord, Beast beast) {
this.mage = mage;
this.warlord = warlord;
this.beast = beast;
}
/**
* Create mage.
*/

View File

@ -23,29 +23,20 @@
package com.iluwatar.prototype;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
/**
* Mage.
*/
@EqualsAndHashCode
@NoArgsConstructor
public abstract class Mage implements Prototype {
public Mage() {
}
public Mage(Mage source) {
}
@Override
public abstract Mage copy();
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
return getClass() == obj.getClass();
}
}

View File

@ -23,17 +23,18 @@
package com.iluwatar.prototype;
import lombok.EqualsAndHashCode;
import lombok.RequiredArgsConstructor;
/**
* OrcBeast.
*/
@EqualsAndHashCode(callSuper = false)
@RequiredArgsConstructor
public class OrcBeast extends Beast {
private final String weapon;
public OrcBeast(String weapon) {
this.weapon = weapon;
}
public OrcBeast(OrcBeast orcBeast) {
super(orcBeast);
this.weapon = orcBeast.weapon;
@ -49,23 +50,4 @@ public class OrcBeast extends Beast {
return "Orcish wolf attacks with " + weapon;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
var other = (OrcBeast) obj;
if (weapon == null) {
return other.weapon == null;
}
return weapon.equals(other.weapon);
}
}

View File

@ -23,17 +23,18 @@
package com.iluwatar.prototype;
import lombok.EqualsAndHashCode;
import lombok.RequiredArgsConstructor;
/**
* OrcMage.
*/
@EqualsAndHashCode(callSuper = true)
@RequiredArgsConstructor
public class OrcMage extends Mage {
private final String weapon;
public OrcMage(String weapon) {
this.weapon = weapon;
}
public OrcMage(OrcMage orcMage) {
super(orcMage);
this.weapon = orcMage.weapon;
@ -49,21 +50,4 @@ public class OrcMage extends Mage {
return "Orcish mage attacks with " + weapon;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
var other = (OrcMage) obj;
if (weapon == null) {
return other.weapon == null;
}
return weapon.equals(other.weapon);
}
}

View File

@ -23,17 +23,18 @@
package com.iluwatar.prototype;
import lombok.EqualsAndHashCode;
import lombok.RequiredArgsConstructor;
/**
* OrcWarlord.
*/
@EqualsAndHashCode(callSuper = true)
@RequiredArgsConstructor
public class OrcWarlord extends Warlord {
private final String weapon;
public OrcWarlord(String weapon) {
this.weapon = weapon;
}
public OrcWarlord(OrcWarlord orcWarlord) {
super(orcWarlord);
this.weapon = orcWarlord.weapon;
@ -49,21 +50,4 @@ public class OrcWarlord extends Warlord {
return "Orcish warlord attacks with " + weapon;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!super.equals(obj)) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
var other = (OrcWarlord) obj;
if (weapon == null) {
return other.weapon == null;
}
return weapon.equals(other.weapon);
}
}

View File

@ -23,29 +23,20 @@
package com.iluwatar.prototype;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
/**
* Warlord.
*/
@EqualsAndHashCode
@NoArgsConstructor
public abstract class Warlord implements Prototype {
public Warlord() {
}
public Warlord(Warlord source) {
}
@Override
public abstract Warlord copy();
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
return getClass() == obj.getClass();
}
}

View File

@ -23,10 +23,10 @@
package com.iluwatar.prototype;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import org.junit.jupiter.api.Test;
/**
* Application test
*/

View File

@ -39,7 +39,7 @@ import org.junit.jupiter.params.provider.MethodSource;
* @param <P> Prototype
* @author Jeroen Meulemeester
*/
public class PrototypeTest<P extends Prototype> {
class PrototypeTest<P extends Prototype> {
static Collection<Object[]> dataProvider() {
return List.of(
new Object[]{new OrcBeast("axe"), "Orcish wolf attacks with axe"},
@ -53,7 +53,7 @@ public class PrototypeTest<P extends Prototype> {
@ParameterizedTest
@MethodSource("dataProvider")
public void testPrototype(P testedPrototype, String expectedToString) {
void testPrototype(P testedPrototype, String expectedToString) {
assertEquals(expectedToString, testedPrototype.toString());
final var clone = testedPrototype.copy();