MCPcopy Index your code
hub / github.com/BruceEckel/OnJava8-Examples / main

Method main

serialization/AStoreCADState.java:83–106  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

81
82public class AStoreCADState {
83 public static void main(String[] args) {
84 List<Class<? extends Shape>> shapeTypes =
85 Arrays.asList(
86 Circle.class, Square.class, Line.class);
87 List<Shape> shapes = IntStream.range(0, 10)
88 .mapToObj(i -> Shape.randomFactory())
89 .collect(Collectors.toList());
90 // Set all the static colors to GREEN:
91 shapes.forEach(s -> s.setColor(Color.GREEN));
92 // Save the state vector:
93 try(
94 ObjectOutputStream out =
95 new ObjectOutputStream(
96 new FileOutputStream("CADState.dat"))
97 ) {
98 out.writeObject(shapeTypes);
99 Line.serializeStaticState(out);
100 out.writeObject(shapes);
101 } catch(IOException e) {
102 throw new RuntimeException(e);
103 }
104 // Display the shapes:
105 System.out.println(shapes);
106 }
107}
108/* Output:
109[class CircleColor[GREEN] xPos[58] yPos[55] dim[93]

Callers

nothing calls this directly

Calls 5

randomFactoryMethod · 0.95
serializeStaticStateMethod · 0.95
rangeMethod · 0.80
writeObjectMethod · 0.80
setColorMethod · 0.45

Tested by

no test coverage detected