Code Monkey home page Code Monkey logo

ip's People

ip's Issues

Sharing iP code quality feedback [for @yeppog]

We did an automated analysis of your code to detect potential areas to improve the code quality. We are sharing the results below, to help you improve the code further.

IMPORTANT: Note that the script looked for just a few easy-to-detect problems only, and at-most three example are given i.e., there can be other areas/places to improve.

Aspect: Tab Usage

No easy-to-detect issues ๐Ÿ‘

Aspect: Naming boolean variables/methods

No easy-to-detect issues ๐Ÿ‘

Aspect: Brace Style

No easy-to-detect issues ๐Ÿ‘

Aspect: Package Name Style

No easy-to-detect issues ๐Ÿ‘

Aspect: Class Name Style

No easy-to-detect issues ๐Ÿ‘

Aspect: Dead Code

No easy-to-detect issues ๐Ÿ‘

Aspect: Method Length

Example from src/main/java/duke/DukeGui.java lines 33-102:

    public void start(Stage stage) {

        //The container for the content of the chat to scroll.
        scrollPane = new ScrollPane();
        dialogContainer = new VBox();
        scrollPane.setContent(dialogContainer);

        userInput = new TextField();
        sendButton = new Button("Send");

        AnchorPane mainLayout = new AnchorPane();
        mainLayout.getChildren()
                .addAll(scrollPane,
                        userInput,
                        sendButton);

        scene = new Scene(mainLayout);

        //Step 2. Formatting the window to look as expected
        stage.setTitle("Duke");
        stage.setResizable(false);
        stage.setMinHeight(600.0);
        stage.setMinWidth(400.0);

        mainLayout.setPrefSize(400.0,
                600.0);

        scrollPane.setPrefSize(385,
                535);
        scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
        scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.ALWAYS);

        scrollPane.setVvalue(1.0);
        scrollPane.setFitToWidth(true);

        // You will need to import `javafx.scene.layout.Region` for this.
        dialogContainer.setPrefHeight(Region.USE_COMPUTED_SIZE);

        userInput.setPrefWidth(325.0);

        sendButton.setPrefWidth(55.0);

        AnchorPane.setTopAnchor(scrollPane,
                1.0);

        AnchorPane.setBottomAnchor(sendButton,
                1.0);
        AnchorPane.setRightAnchor(sendButton,
                1.0);

        AnchorPane.setLeftAnchor(userInput,
                1.0);
        AnchorPane.setBottomAnchor(userInput,
                1.0);

        //Part 3. Add functionality to handle user input.
        sendButton.setOnMouseClicked((event) -> {
            handleUserInput(stage);
        });

        userInput.setOnAction((event) -> {
            handleUserInput(stage);
        });
        dialogContainer.heightProperty()
                .addListener((observable) -> scrollPane.setVvalue(1.0));

        stage.setScene(scene);
        stage.show();
        // more code to be added here later
    }

Example from src/main/java/duke/util/Parser.java lines 24-60:

    public static Map<String, String> parseCommand(String text) {
        HashMap<String, String> inputMap = new HashMap<>();
        String[] splitted = text.split("\\s");

        String key = splitted[0];
        StringBuilder arguments = new StringBuilder();
        for (int i = 1;
             i < splitted.length;
             i++) {
            if (splitted[i].startsWith("/") && ValidParams.isValid(splitted[i])) {
                if (arguments.length() > 0) {
                    arguments.deleteCharAt(arguments.length() - 1);
                    inputMap.put(key,
                            arguments.toString());
                    arguments.setLength(0);
                } else {
                    inputMap.put(key,
                            null);
                }
                key = splitted[i];
            } else {
                arguments.append(String.format("%s ",
                        splitted[i]));
            }
        }
        if (arguments.length() > 0) {
            arguments.deleteCharAt(arguments.length() - 1);
            inputMap.put(key,
                    arguments.toString());
        } else {
            if (!inputMap.containsKey(key)) {
                inputMap.put(key,
                        null);
            }
        }
        return inputMap;
    }

Example from src/main/java/duke/util/Parser.java lines 124-165:

    public static Optional<LocalDateTime> parseDateTime(String dateTime, DukeConfig config) throws DukeException {
        String dateConfig = config.getDateConfig();
        String[] timeSplit = dateTime.split("\\s");
        String[] dateSplit = timeSplit[0].split("/");

        if (dateSplit.length != 3) {
            throw new DukeException("Invalid date format. The current specified format is " + dateConfig);
        }

        int date;
        int month;
        int year;
        int hour;
        int minute;
        date = parseInt(dateSplit[0]).filter(x -> x < 32).orElseThrow(() -> new DukeException("Invalid day"));
        month = parseInt(dateSplit[1]).filter(x -> x < 13).orElseThrow(() -> new DukeException("Invalid month"));
        year = parseInt(dateSplit[2]).orElseThrow(() -> new DukeException("Invalid year"));

        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
        LocalDate time = LocalDate.parse(String.format("%s/%s/%s", year, month < 10 ? "0" + month : month, date),
                formatter);

        if (time.getDayOfMonth() != date) {
            throw new DukeException("The specified day of the month is not valid");
        }

        if (timeSplit.length == 2) {
            if (timeSplit[1].length() != 4) {
                throw new DukeException("Invalid time");
            }
            hour = parseInt(timeSplit[1].substring(0, 2)).filter(x -> x < 25).orElseThrow(() -> new DukeException(
                    "Invalid hour "
                            + "specified"));
            minute = parseInt(timeSplit[1].substring(2, 4)).filter(x -> x < 60).orElseThrow(() -> new DukeException(
                    "Invalid "
                            + "minute " + "specified"));
            return Optional.of(LocalDateTime.of(year, month, date, hour, minute));
        } else {
            return Optional.of(LocalDateTime.of(year, month, date, 0, 0));
        }

    }

Suggestion: Consider applying SLAP (and other abstraction mechanisms) to shorten methods. You may ignore this suggestion if you think a longer method is justified in a particular case.

Aspect: Header Comments

Example from src/main/java/duke/DukeGui.java lines 112-116:

    /**
     * Iteration 2:
     * Creates two dialog boxes, one echoing user input and the other containing Duke's reply and then appends them to
     * the dialog container. Clears the user input after processing.
     */

Example from src/main/java/duke/DukeGui.java lines 132-135:

    /**
     * You should have your own function to generate a response to user input.
     * Replace this stub with your completed method.
     */

Example from src/main/java/duke/Main.java lines 6-9:

    /**
     * Driver to launch the application
     * @param args System args
     */

Suggestion: Ensure method/class header comments follow the format specified in the coding standard, in particular, the phrasing of the overview statement

Aspect: Recent Git Commit Message (Subject Only)

No easy-to-detect issues ๐Ÿ‘

โ„น๏ธ The bot account @cs2103-bot used to post this issue is un-manned. Do not reply to this post (as those replies will not be read). Instead, contact [email protected] if you want to follow up on this post.

Sharing iP code quality feedback [for @yeppog] - Round 2

We did an automated analysis of your code to detect potential areas to improve the code quality. We are sharing the results below, so that you can avoid similar problems in your tP code (which will be graded more strictly for code quality).

IMPORTANT: Note that the script looked for just a few easy-to-detect problems only, and at-most three example are given i.e., there can be other areas/places to improve.

Aspect: Tab Usage

No easy-to-detect issues ๐Ÿ‘

Aspect: Naming boolean variables/methods

No easy-to-detect issues ๐Ÿ‘

Aspect: Brace Style

No easy-to-detect issues ๐Ÿ‘

Aspect: Package Name Style

No easy-to-detect issues ๐Ÿ‘

Aspect: Class Name Style

No easy-to-detect issues ๐Ÿ‘

Aspect: Dead Code

No easy-to-detect issues ๐Ÿ‘

Aspect: Method Length

Example from src/main/java/duke/DukeGui.java lines 33-102:

    public void start(Stage stage) {

        //The container for the content of the chat to scroll.
        scrollPane = new ScrollPane();
        dialogContainer = new VBox();
        scrollPane.setContent(dialogContainer);

        userInput = new TextField();
        sendButton = new Button("Send");

        AnchorPane mainLayout = new AnchorPane();
        mainLayout.getChildren()
                .addAll(scrollPane,
                        userInput,
                        sendButton);

        scene = new Scene(mainLayout);

        //Step 2. Formatting the window to look as expected
        stage.setTitle("Duke");
        stage.setResizable(false);
        stage.setMinHeight(600.0);
        stage.setMinWidth(400.0);

        mainLayout.setPrefSize(400.0,
                600.0);

        scrollPane.setPrefSize(385,
                535);
        scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
        scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.ALWAYS);

        scrollPane.setVvalue(1.0);
        scrollPane.setFitToWidth(true);

        // You will need to import `javafx.scene.layout.Region` for this.
        dialogContainer.setPrefHeight(Region.USE_COMPUTED_SIZE);

        userInput.setPrefWidth(325.0);

        sendButton.setPrefWidth(55.0);

        AnchorPane.setTopAnchor(scrollPane,
                1.0);

        AnchorPane.setBottomAnchor(sendButton,
                1.0);
        AnchorPane.setRightAnchor(sendButton,
                1.0);

        AnchorPane.setLeftAnchor(userInput,
                1.0);
        AnchorPane.setBottomAnchor(userInput,
                1.0);

        //Part 3. Add functionality to handle user input.
        sendButton.setOnMouseClicked((event) -> {
            handleUserInput(stage);
        });

        userInput.setOnAction((event) -> {
            handleUserInput(stage);
        });
        dialogContainer.heightProperty()
                .addListener((observable) -> scrollPane.setVvalue(1.0));

        stage.setScene(scene);
        stage.show();
        // more code to be added here later
    }

Example from src/main/java/duke/util/Parser.java lines 24-60:

    public static Map<String, String> parseCommand(String text) {
        HashMap<String, String> inputMap = new HashMap<>();
        String[] splitted = text.split("\\s");

        String key = splitted[0];
        StringBuilder arguments = new StringBuilder();
        for (int i = 1;
             i < splitted.length;
             i++) {
            if (splitted[i].startsWith("/") && ValidParams.isValid(splitted[i])) {
                if (arguments.length() > 0) {
                    arguments.deleteCharAt(arguments.length() - 1);
                    inputMap.put(key,
                            arguments.toString());
                    arguments.setLength(0);
                } else {
                    inputMap.put(key,
                            null);
                }
                key = splitted[i];
            } else {
                arguments.append(String.format("%s ",
                        splitted[i]));
            }
        }
        if (arguments.length() > 0) {
            arguments.deleteCharAt(arguments.length() - 1);
            inputMap.put(key,
                    arguments.toString());
        } else {
            if (!inputMap.containsKey(key)) {
                inputMap.put(key,
                        null);
            }
        }
        return inputMap;
    }

Example from src/main/java/duke/util/Parser.java lines 124-165:

    public static Optional<LocalDateTime> parseDateTime(String dateTime, DukeConfig config) throws DukeException {
        String dateConfig = config.getDateConfig();
        String[] timeSplit = dateTime.split("\\s");
        String[] dateSplit = timeSplit[0].split("/");

        if (dateSplit.length != 3) {
            throw new DukeException("Invalid date format. The current specified format is " + dateConfig);
        }

        int date;
        int month;
        int year;
        int hour;
        int minute;
        date = parseInt(dateSplit[0]).filter(x -> x < 32).orElseThrow(() -> new DukeException("Invalid day"));
        month = parseInt(dateSplit[1]).filter(x -> x < 13).orElseThrow(() -> new DukeException("Invalid month"));
        year = parseInt(dateSplit[2]).orElseThrow(() -> new DukeException("Invalid year"));

        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
        LocalDate time = LocalDate.parse(String.format("%s/%s/%s", year, month < 10 ? "0" + month : month, date),
                formatter);

        if (time.getDayOfMonth() != date) {
            throw new DukeException("The specified day of the month is not valid");
        }

        if (timeSplit.length == 2) {
            if (timeSplit[1].length() != 4) {
                throw new DukeException("Invalid time");
            }
            hour = parseInt(timeSplit[1].substring(0, 2)).filter(x -> x < 25).orElseThrow(() -> new DukeException(
                    "Invalid hour "
                            + "specified"));
            minute = parseInt(timeSplit[1].substring(2, 4)).filter(x -> x < 60).orElseThrow(() -> new DukeException(
                    "Invalid "
                            + "minute " + "specified"));
            return Optional.of(LocalDateTime.of(year, month, date, hour, minute));
        } else {
            return Optional.of(LocalDateTime.of(year, month, date, 0, 0));
        }

    }

Suggestion: Consider applying SLAP (and other abstraction mechanisms) to shorten methods. You may ignore this suggestion if you think a longer method is justified in a particular case.

Aspect: Class size

No easy-to-detect issues ๐Ÿ‘

Aspect: Header Comments

Example from src/main/java/duke/DukeGui.java lines 112-116:

    /**
     * Iteration 2:
     * Creates two dialog boxes, one echoing user input and the other containing Duke's reply and then appends them to
     * the dialog container. Clears the user input after processing.
     */

Example from src/main/java/duke/DukeGui.java lines 132-135:

    /**
     * You should have your own function to generate a response to user input.
     * Replace this stub with your completed method.
     */

Example from src/main/java/duke/Main.java lines 6-9:

    /**
     * Driver to launch the application
     * @param args System args
     */

Suggestion: Ensure method/class header comments follow the format specified in the coding standard, in particular, the phrasing of the overview statement

Aspect: Recent Git Commit Message (Subject Only)

No easy-to-detect issues ๐Ÿ‘

โ— You are not required to (but you are welcome to) fix the above problems in your iP, unless you have been separately asked to resubmit the iP due to code quality issues.

โ„น๏ธ The bot account @nus-se-bot used to post this issue is un-manned. Do not reply to this post (as those replies will not be read). Instead, contact [email protected] if you want to follow up on this post.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.