📍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:
@ -24,8 +24,7 @@
|
||||
package com.iluwatar.tolerantreader;
|
||||
|
||||
import java.io.IOException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Tolerant Reader is an integration pattern that helps creating robust communication systems. The
|
||||
@ -40,10 +39,9 @@ import org.slf4j.LoggerFactory;
|
||||
* schema. Fortunately the reading method has been designed with the Tolerant Reader pattern and
|
||||
* does not break even though {@link RainbowFishV2} has new fields that are serialized.
|
||||
*/
|
||||
@Slf4j
|
||||
public class App {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||
|
||||
/**
|
||||
* Program entry point.
|
||||
*/
|
||||
@ -63,7 +61,7 @@ public class App {
|
||||
LOGGER.info(
|
||||
"fishV2 name={} age={} length={} weight={} sleeping={} hungry={} angry={}",
|
||||
fishV2.getName(), fishV2.getAge(), fishV2.getLengthMeters(), fishV2.getWeightTons(),
|
||||
fishV2.getHungry(), fishV2.getAngry(), fishV2.getSleeping());
|
||||
fishV2.isHungry(), fishV2.isAngry(), fishV2.isSleeping());
|
||||
RainbowFishSerializer.writeV2(fishV2, "fish2.out");
|
||||
// Read V2 with V1 method
|
||||
var deserializedFishV2 = RainbowFishSerializer.readV1("fish2.out");
|
||||
|
@ -24,10 +24,14 @@
|
||||
package com.iluwatar.tolerantreader;
|
||||
|
||||
import java.io.Serializable;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
/**
|
||||
* RainbowFish is the initial schema.
|
||||
*/
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public class RainbowFish implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@ -37,30 +41,4 @@ public class RainbowFish implements Serializable {
|
||||
private final int lengthMeters;
|
||||
private final int weightTons;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public RainbowFish(String name, int age, int lengthMeters, int weightTons) {
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
this.lengthMeters = lengthMeters;
|
||||
this.weightTons = weightTons;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public int getLengthMeters() {
|
||||
return lengthMeters;
|
||||
}
|
||||
|
||||
public int getWeightTons() {
|
||||
return weightTons;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -51,8 +51,8 @@ public final class RainbowFishSerializer {
|
||||
var map = Map.of(
|
||||
"name", rainbowFish.getName(),
|
||||
"age", String.format("%d", rainbowFish.getAge()),
|
||||
LENGTH_METERS, String.format("%d", rainbowFish.getLengthMeters()),
|
||||
WEIGHT_TONS, String.format("%d", rainbowFish.getWeightTons())
|
||||
LENGTH_METERS, String.format("%d", rainbowFish.getLengthMeters()),
|
||||
WEIGHT_TONS, String.format("%d", rainbowFish.getWeightTons())
|
||||
);
|
||||
|
||||
try (var fileOut = new FileOutputStream(filename);
|
||||
@ -68,11 +68,11 @@ public final class RainbowFishSerializer {
|
||||
var map = Map.of(
|
||||
"name", rainbowFish.getName(),
|
||||
"age", String.format("%d", rainbowFish.getAge()),
|
||||
LENGTH_METERS, String.format("%d", rainbowFish.getLengthMeters()),
|
||||
WEIGHT_TONS, String.format("%d", rainbowFish.getWeightTons()),
|
||||
"angry", Boolean.toString(rainbowFish.getAngry()),
|
||||
"hungry", Boolean.toString(rainbowFish.getHungry()),
|
||||
"sleeping", Boolean.toString(rainbowFish.getSleeping())
|
||||
LENGTH_METERS, String.format("%d", rainbowFish.getLengthMeters()),
|
||||
WEIGHT_TONS, String.format("%d", rainbowFish.getWeightTons()),
|
||||
"angry", Boolean.toString(rainbowFish.isAngry()),
|
||||
"hungry", Boolean.toString(rainbowFish.isHungry()),
|
||||
"sleeping", Boolean.toString(rainbowFish.isSleeping())
|
||||
);
|
||||
|
||||
try (var fileOut = new FileOutputStream(filename);
|
||||
|
@ -23,9 +23,12 @@
|
||||
|
||||
package com.iluwatar.tolerantreader;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* RainbowFishV2 is the evolved schema.
|
||||
*/
|
||||
@Getter
|
||||
public class RainbowFishV2 extends RainbowFish {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@ -49,15 +52,4 @@ public class RainbowFishV2 extends RainbowFish {
|
||||
this.angry = angry;
|
||||
}
|
||||
|
||||
public boolean getSleeping() {
|
||||
return sleeping;
|
||||
}
|
||||
|
||||
public boolean getHungry() {
|
||||
return hungry;
|
||||
}
|
||||
|
||||
public boolean getAngry() {
|
||||
return angry;
|
||||
}
|
||||
}
|
||||
|
@ -46,9 +46,9 @@ class RainbowFishV2Test {
|
||||
assertEquals(1, fish.getAge());
|
||||
assertEquals(2, fish.getLengthMeters());
|
||||
assertEquals(3, fish.getWeightTons());
|
||||
assertFalse(fish.getSleeping());
|
||||
assertTrue(fish.getHungry());
|
||||
assertFalse(fish.getAngry());
|
||||
assertFalse(fish.isSleeping());
|
||||
assertTrue(fish.isHungry());
|
||||
assertFalse(fish.isAngry());
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user