mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-17 10:59:17 +00:00
📍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:
@@ -26,8 +26,7 @@ package com.iluwatar.observer;
|
||||
import com.iluwatar.observer.generic.GHobbits;
|
||||
import com.iluwatar.observer.generic.GOrcs;
|
||||
import com.iluwatar.observer.generic.GWeather;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* The Observer pattern is a software design pattern in which an object, called the subject,
|
||||
@@ -40,10 +39,9 @@ import org.slf4j.LoggerFactory;
|
||||
* <p>In this example {@link Weather} has a state that can be observed. The {@link Orcs} and {@link
|
||||
* Hobbits} register as observers and receive notifications when the {@link Weather} changes.
|
||||
*/
|
||||
@Slf4j
|
||||
public class App {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||
|
||||
/**
|
||||
* Program entry point.
|
||||
*
|
||||
|
||||
@@ -23,18 +23,16 @@
|
||||
|
||||
package com.iluwatar.observer;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Hobbits.
|
||||
*/
|
||||
@Slf4j
|
||||
public class Hobbits implements WeatherObserver {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Hobbits.class);
|
||||
|
||||
@Override
|
||||
public void update(WeatherType currentWeather) {
|
||||
LOGGER.info("The hobbits are facing " + currentWeather.getDescription() + " weather now");
|
||||
LOGGER.info("The hobbits are facing {} weather now", currentWeather.getDescription());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,16 +23,14 @@
|
||||
|
||||
package com.iluwatar.observer;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Orcs.
|
||||
*/
|
||||
@Slf4j
|
||||
public class Orcs implements WeatherObserver {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Orcs.class);
|
||||
|
||||
@Override
|
||||
public void update(WeatherType currentWeather) {
|
||||
LOGGER.info("The orcs are facing " + currentWeather.getDescription() + " weather now");
|
||||
|
||||
@@ -25,17 +25,15 @@ package com.iluwatar.observer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Weather can be observed by implementing {@link WeatherObserver} interface and registering as
|
||||
* listener.
|
||||
*/
|
||||
@Slf4j
|
||||
public class Weather {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Weather.class);
|
||||
|
||||
private WeatherType currentWeather;
|
||||
private final List<WeatherObserver> observers;
|
||||
|
||||
|
||||
@@ -24,16 +24,14 @@
|
||||
package com.iluwatar.observer.generic;
|
||||
|
||||
import com.iluwatar.observer.WeatherType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* GHobbits.
|
||||
*/
|
||||
@Slf4j
|
||||
public class GHobbits implements Race {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(GHobbits.class);
|
||||
|
||||
@Override
|
||||
public void update(GWeather weather, WeatherType weatherType) {
|
||||
LOGGER.info("The hobbits are facing " + weatherType.getDescription() + " weather now");
|
||||
|
||||
@@ -24,16 +24,14 @@
|
||||
package com.iluwatar.observer.generic;
|
||||
|
||||
import com.iluwatar.observer.WeatherType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* GOrcs.
|
||||
*/
|
||||
@Slf4j
|
||||
public class GOrcs implements Race {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(GOrcs.class);
|
||||
|
||||
@Override
|
||||
public void update(GWeather weather, WeatherType weatherType) {
|
||||
LOGGER.info("The orcs are facing " + weatherType.getDescription() + " weather now");
|
||||
|
||||
@@ -24,16 +24,14 @@
|
||||
package com.iluwatar.observer.generic;
|
||||
|
||||
import com.iluwatar.observer.WeatherType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* GWeather.
|
||||
*/
|
||||
@Slf4j
|
||||
public class GWeather extends Observable<GWeather, Race, WeatherType> {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(GWeather.class);
|
||||
|
||||
private WeatherType currentWeather;
|
||||
|
||||
public GWeather() {
|
||||
|
||||
Reference in New Issue
Block a user