Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to develop a TS3 Bot in Java with this API: https://github.com/TheHolyWaffle/TeamSpeak-3-Java-API

I have a list with all Server Groups that a Client have:

List<ServerGroup> playerGroups = TS3Bot.api.getServerGroupsByClientId(player.clientdbID);

And now I check if the List contains a Group:

if(!playerGroups.contains(TS3Bot.botGroups.get(1))){...}

And the result is false. I am 100% sure that this List contains the ServerGroup.

Already checked it out with Sysouts.

Here is the Link to the ServerGroup Class: https://github.com/TheHolyWaffle/TeamSpeak-3-Java-API/blob/master/src/main/java/com/github/theholywaffle/teamspeak3/api/wrapper/ServerGroup.java

and this is just the ServerGroup Object.toString().

{iconid=0, savedb=1, sortid=0, name=Test 2, n_member_removep=100, sgid=98, type=1, n_member_addp=100, namemode=0, n_modifyp=100}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
145 views
Welcome To Ask or Share your Answers For Others

1 Answer

Do not forget to respect the Object#equals(Object o) contract

Indicates whether some other object is "equal to" this one. The equals method implements an equivalence relation on non-null object references:

It is reflexive: for any non-null reference value x, x.equals(x) should return true.

It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.

It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.

It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.

For any non-null reference value x, x.equals(null) should return false. The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference values x and y, this method returns true if and only if x and y refer to the same object (x == y has the value true).

Note that it is generally necessary to override the hashCode method whenever this method is overridden, so as to maintain the general contract for the hashCode method, which states that equal objects must have equal hash codes.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...