Skip to content
Snippets Groups Projects
Select Git revision
  • 6adaf247a1a3a11daba2d904bb2b8b07b6739c52
  • main default protected
  • correction_video
  • going_further
  • ImprovedMouseInteraction
  • final2023
  • template
  • ModifGUI
8 results

Coordinate.java

Blame
  • Forked from YAGOUBI Rim / Game of life Template
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    ShapeReader.java 1.18 KiB
    package serializer;
    
    import shape.Circle;
    import shape.Shape;
    
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileReader;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    
    public class ShapeReader {
    
        private static final Map<String, ShapeSerializer<?>> serializers = new HashMap<>();
    
        static {
            serializers.put("circle", new CircleSerializer());
            serializers.put("rectangle", new RectangleSerializer());
        }
        public static List<Shape> read(File file) throws IOException {
            List<Shape> shapes = new ArrayList<>();
            try(BufferedReader bufferedReader = new BufferedReader(new FileReader(file))) {
            String line ;
            while ((line = bufferedReader.readLine()) != null) {
                String[] parts = line.split(" ",2);
                String code = parts[0];
                String data = parts[1];
                ShapeSerializer<?> serializer = serializers.get(code);
                if (serializer != null) {
                    Shape shape = serializer.unserialize(data);
                    shapes.add(shape);
                }
            }
                return shapes;
            }
        }
    }