[JAVA] Akanechan who listens to anything

Listen, Akanechan!

[I] I came up with a good idea! [A] What? [I] I will make an enumeration of Akanechan! [A] Ahokusa [me] ... [I] yeah yeah yeah yeah yeah yeah yeah yeah (ry)

Kikake is a conversation with a friend

I just talked about it on the spot, so I don't remember the details.

For the time being, I think I talked about something like "Akanechan's reply that listens to anything is like a boolean type".

The ideal is

if (Seyana) {
    System.out.println("True!!")
}

However, Seyana cannot be used directly as a substitute for boolean type, so I tried as much as I could. It's a play, there is no merit.

I'll make Akanechan!

Akanechan's lines

I don't want to accept Akanechan's lines other than those adopted, so I will make them enumerated. Also, I want to associate a boolean type with each line, so I also decide that. The result is as follows.

--Ahokusa (false) --That (true) --Yes (true) --Encha? (True) --Honma (true) --I don't know (false) --I don't know (false) --That (true) --Soya (true) --Understand (true)

There is a part where I forcibly decided true / false, but it's okay.

Implementation

Create an AkaneChan enum. Insert the above lines into this. At this time, by giving the enumeration type a private constructor, it is possible to give the instance a unique value, so use that to associate the boolean type. Also, since it's a big deal, I'll link the sentences in Japanese and English.

As an example, if "Ahokusa" and "Arena" are implemented, it will be as follows.

public enum AkaneChan {
    Ahokusa(false, "Sounds stupid.", "Ahokusa"),
    Arena(true, "Exactly...", "That"),
    ;

    private boolean agree;
    private String meaning_en;
    private String meaning_jp;

    private AkaneChan(boolean agree, String meaning_en, String meaning_jp) {
    this.agree = agree;
    this.meaning_en = meaning_en;
    this.meaning_jp = meaning_jp;
}
}

later,

--ʻIsAgree () --Method to return agree --getMeaning_en () --method to return meaning_en (English meaning) --getMeaning_jp () `--method to return meaning_jp (Japanese meaning)

If you make it, it will be completed.

I'll use Akanechan!

It's very simple. Ideally, the if statement written in the ~ part is reproduced.

if (AkaneChan.Seyana.isAgree()) {
    System.out.println("True!!");
} else {
    //Will not be called
    System.out.println("False!!");
}

Conclusion

[I] ** I don't need it! Akanechan! !! ** ** [A] I don't know what it is (stick)

Afterword

In addition to the method implemented earlier, the AkaneChan enumeration type with the ListenUpAkaneChan method added and some useless ones are published as a set on Github.

Github - YabPaseri/AKANE-CHAN

I made it in Java8 environment, but I don't use anything unique, so I think it can be used without any problems.

Akanechan in a jar file and the program SampleAkaneChan.java that actually uses Akanechan are also included in / build, so if you don't mind ... why not use it? (Laughs)

Recommended Posts

Akanechan who listens to anything
To you who absolutely need backtrace