* #984 for unitofwork, tolerantreader, twin * #984 for unitofwork, tolerantreader, twin * #987 for visitor, value-object, unitofwork, typeobjectpattern, tolerantreader, twin, tranpoline
This commit is contained in:
parent
c7fee7bb07
commit
fadad43f8b
@ -52,24 +52,24 @@ public class App {
|
|||||||
*/
|
*/
|
||||||
public static void main(String[] args) throws IOException, ClassNotFoundException {
|
public static void main(String[] args) throws IOException, ClassNotFoundException {
|
||||||
// Write V1
|
// Write V1
|
||||||
RainbowFish fishV1 = new RainbowFish("Zed", 10, 11, 12);
|
var fishV1 = new RainbowFish("Zed", 10, 11, 12);
|
||||||
LOGGER.info("fishV1 name={} age={} length={} weight={}", fishV1.getName(),
|
LOGGER.info("fishV1 name={} age={} length={} weight={}", fishV1.getName(),
|
||||||
fishV1.getAge(), fishV1.getLengthMeters(), fishV1.getWeightTons());
|
fishV1.getAge(), fishV1.getLengthMeters(), fishV1.getWeightTons());
|
||||||
RainbowFishSerializer.writeV1(fishV1, "fish1.out");
|
RainbowFishSerializer.writeV1(fishV1, "fish1.out");
|
||||||
// Read V1
|
// Read V1
|
||||||
RainbowFish deserializedFishV1 = RainbowFishSerializer.readV1("fish1.out");
|
var deserializedRainbowFishV1 = RainbowFishSerializer.readV1("fish1.out");
|
||||||
LOGGER.info("deserializedFishV1 name={} age={} length={} weight={}",
|
LOGGER.info("deserializedFishV1 name={} age={} length={} weight={}",
|
||||||
deserializedFishV1.getName(), deserializedFishV1.getAge(),
|
deserializedRainbowFishV1.getName(), deserializedRainbowFishV1.getAge(),
|
||||||
deserializedFishV1.getLengthMeters(), deserializedFishV1.getWeightTons());
|
deserializedRainbowFishV1.getLengthMeters(), deserializedRainbowFishV1.getWeightTons());
|
||||||
// Write V2
|
// Write V2
|
||||||
RainbowFishV2 fishV2 = new RainbowFishV2("Scar", 5, 12, 15, true, true, true);
|
var fishV2 = new RainbowFishV2("Scar", 5, 12, 15, true, true, true);
|
||||||
LOGGER.info(
|
LOGGER.info(
|
||||||
"fishV2 name={} age={} length={} weight={} sleeping={} hungry={} angry={}",
|
"fishV2 name={} age={} length={} weight={} sleeping={} hungry={} angry={}",
|
||||||
fishV2.getName(), fishV2.getAge(), fishV2.getLengthMeters(), fishV2.getWeightTons(),
|
fishV2.getName(), fishV2.getAge(), fishV2.getLengthMeters(), fishV2.getWeightTons(),
|
||||||
fishV2.getHungry(), fishV2.getAngry(), fishV2.getSleeping());
|
fishV2.getHungry(), fishV2.getAngry(), fishV2.getSleeping());
|
||||||
RainbowFishSerializer.writeV2(fishV2, "fish2.out");
|
RainbowFishSerializer.writeV2(fishV2, "fish2.out");
|
||||||
// Read V2 with V1 method
|
// Read V2 with V1 method
|
||||||
RainbowFish deserializedFishV2 = RainbowFishSerializer.readV1("fish2.out");
|
var deserializedFishV2 = RainbowFishSerializer.readV1("fish2.out");
|
||||||
LOGGER.info("deserializedFishV2 name={} age={} length={} weight={}",
|
LOGGER.info("deserializedFishV2 name={} age={} length={} weight={}",
|
||||||
deserializedFishV2.getName(), deserializedFishV2.getAge(),
|
deserializedFishV2.getName(), deserializedFishV2.getAge(),
|
||||||
deserializedFishV2.getLengthMeters(), deserializedFishV2.getWeightTons());
|
deserializedFishV2.getLengthMeters(), deserializedFishV2.getWeightTons());
|
||||||
|
@ -48,13 +48,15 @@ public final class RainbowFishSerializer {
|
|||||||
* Write V1 RainbowFish to file
|
* Write V1 RainbowFish to file
|
||||||
*/
|
*/
|
||||||
public static void writeV1(RainbowFish rainbowFish, String filename) throws IOException {
|
public static void writeV1(RainbowFish rainbowFish, String filename) throws IOException {
|
||||||
Map<String, String> map = new HashMap<>();
|
var map = Map.of(
|
||||||
map.put("name", rainbowFish.getName());
|
"name", rainbowFish.getName(),
|
||||||
map.put("age", String.format("%d", rainbowFish.getAge()));
|
"age", String.format("%d", rainbowFish.getAge()),
|
||||||
map.put("lengthMeters", String.format("%d", rainbowFish.getLengthMeters()));
|
"lengthMeters", String.format("%d", rainbowFish.getLengthMeters()),
|
||||||
map.put("weightTons", String.format("%d", rainbowFish.getWeightTons()));
|
"weightTons", String.format("%d", rainbowFish.getWeightTons())
|
||||||
try (FileOutputStream fileOut = new FileOutputStream(filename);
|
);
|
||||||
ObjectOutputStream objOut = new ObjectOutputStream(fileOut)) {
|
|
||||||
|
try (var fileOut = new FileOutputStream(filename);
|
||||||
|
var objOut = new ObjectOutputStream(fileOut)) {
|
||||||
objOut.writeObject(map);
|
objOut.writeObject(map);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -63,16 +65,18 @@ public final class RainbowFishSerializer {
|
|||||||
* Write V2 RainbowFish to file
|
* Write V2 RainbowFish to file
|
||||||
*/
|
*/
|
||||||
public static void writeV2(RainbowFishV2 rainbowFish, String filename) throws IOException {
|
public static void writeV2(RainbowFishV2 rainbowFish, String filename) throws IOException {
|
||||||
Map<String, String> map = new HashMap<>();
|
var map = Map.of(
|
||||||
map.put("name", rainbowFish.getName());
|
"name", rainbowFish.getName(),
|
||||||
map.put("age", String.format("%d", rainbowFish.getAge()));
|
"age", String.format("%d", rainbowFish.getAge()),
|
||||||
map.put("lengthMeters", String.format("%d", rainbowFish.getLengthMeters()));
|
"lengthMeters", String.format("%d", rainbowFish.getLengthMeters()),
|
||||||
map.put("weightTons", String.format("%d", rainbowFish.getWeightTons()));
|
"weightTons", String.format("%d", rainbowFish.getWeightTons()),
|
||||||
map.put("angry", Boolean.toString(rainbowFish.getAngry()));
|
"angry", Boolean.toString(rainbowFish.getAngry()),
|
||||||
map.put("hungry", Boolean.toString(rainbowFish.getHungry()));
|
"hungry", Boolean.toString(rainbowFish.getHungry()),
|
||||||
map.put("sleeping", Boolean.toString(rainbowFish.getSleeping()));
|
"sleeping", Boolean.toString(rainbowFish.getSleeping())
|
||||||
try (FileOutputStream fileOut = new FileOutputStream(filename);
|
);
|
||||||
ObjectOutputStream objOut = new ObjectOutputStream(fileOut)) {
|
|
||||||
|
try (var fileOut = new FileOutputStream(filename);
|
||||||
|
var objOut = new ObjectOutputStream(fileOut)) {
|
||||||
objOut.writeObject(map);
|
objOut.writeObject(map);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -83,8 +87,8 @@ public final class RainbowFishSerializer {
|
|||||||
public static RainbowFish readV1(String filename) throws IOException, ClassNotFoundException {
|
public static RainbowFish readV1(String filename) throws IOException, ClassNotFoundException {
|
||||||
Map<String, String> map = null;
|
Map<String, String> map = null;
|
||||||
|
|
||||||
try (FileInputStream fileIn = new FileInputStream(filename);
|
try (var fileIn = new FileInputStream(filename);
|
||||||
ObjectInputStream objIn = new ObjectInputStream(fileIn)) {
|
var objIn = new ObjectInputStream(fileIn)) {
|
||||||
map = (Map<String, String>) objIn.readObject();
|
map = (Map<String, String>) objIn.readObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,8 +41,8 @@ public class App {
|
|||||||
*/
|
*/
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
|
||||||
BallItem ballItem = new BallItem();
|
var ballItem = new BallItem();
|
||||||
BallThread ballThread = new BallThread();
|
var ballThread = new BallThread();
|
||||||
|
|
||||||
ballItem.setTwin(ballThread);
|
ballItem.setTwin(ballThread);
|
||||||
ballThread.setTwin(ballItem);
|
ballThread.setTwin(ballItem);
|
||||||
|
@ -39,7 +39,7 @@ public class App {
|
|||||||
var shyam = new Student(2, "Shyam", "Z bridge, Pune");
|
var shyam = new Student(2, "Shyam", "Z bridge, Pune");
|
||||||
var gopi = new Student(3, "Gopi", "Street 10, Mumbai");
|
var gopi = new Student(3, "Gopi", "Street 10, Mumbai");
|
||||||
|
|
||||||
HashMap<String, List<Student>> context = new HashMap<>();
|
var context = new HashMap<String, List<Student>>();
|
||||||
var studentDatabase = new StudentDatabase();
|
var studentDatabase = new StudentDatabase();
|
||||||
var studentRepository = new StudentRepository(context, studentDatabase);
|
var studentRepository = new StudentRepository(context, studentDatabase);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user