DEV Community

Ahmad
Ahmad

Posted on

Second Hacktoberfest Contribution

The Issue

The issue author wanted someone to simplify anonymous types into lambda throughout the project.

Working on the issue

It had been a while since I'd written in Java or even used lambda, so I had to brush up on this first. I looked at old labs and notes from a JAC444 (Java) class I took last semester and quickly got the hang of it again.

After forking, cloning, and making an issue branch to work on, I followed the project's setup guide. The guide wanted contributors to use IntelliJ, which I had never used before. So I installed it and got the project running. Then I went searching for anonymous types.

I was actually able to chop down a lot of decently sized pieces of code. Like this nested anonymous type in ScheduleSaver.java:

new Thread() {
    public void run() {
        boolean success = false;
        if (schedule.getFile() != null) {
            success = schedule.writeToFile();
            if (!success) {
                Platform.runLater(new Runnable() {

                    @Override
                    public void run() {
                        Dialog.showError(LabelGrabber.INSTANCE.getLabel("cant.save.schedule.title"), LabelGrabber.INSTANCE.getLabel("cant.save.schedule.text"));
                    }
                });
            }
            if (callback != null) {
                callback.saved(success);
            }
            statusPanel.done();
        }
    }.start();

    if (callback != null) {
        callback.saved(success);
    }
    statusPanel.done();
}).start();
Enter fullscreen mode Exit fullscreen mode
After
new Thread(() -> {
    boolean success = false;
    if (schedule.getFile() != null) {
        success = schedule.writeToFile();
        if (!success) {
            Platform.runLater(() -> Dialog.showError(LabelGrabber.INSTANCE.getLabel("cant.save.schedule.title"), LabelGrabber.INSTANCE.getLabel("cant.save.schedule.text")));
        }
    }
    if (callback != null) {
        callback.saved(success);
    }
    statusPanel.done();
}).start();
Enter fullscreen mode Exit fullscreen mode

With every change, I tested and confirmed that everything was working as normal.

After replacing as much as I could find, I realized that some of the files I altered now had unused imports, because I had removed the need for them through lambda. So I had to go back and make sure I hadn't left any others hanging.

Merging

After finishing and double checking my work, I made a pull request. My pull request was approved and merged without issue!

Discussion (0)