1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Implemented Add Area.equals

Discussion in 'Client & Site Suggestions' started by tztok, Dec 27, 2016.

  1. tztok

    Joined:
    Nov 7, 2015
    Messages:
    31
    Likes Received:
    5
    Suggestion: add equals method for Area class
    You have toString but no equals?
     
    #1 tztok, Dec 27, 2016
    Last edited: Dec 27, 2016
  2. Party

    Party Client Developer

    Joined:
    Oct 12, 2015
    Messages:
    3,708
    Likes Received:
    1,606
    Emmmm.... area1.equals(area2) ????????????

    Or Objects.equals(area1, area2)
     
    Serene likes this.
  3. Serene

    Serene ( ͡° ͜ʖ ͡°)

    Joined:
    Mar 30, 2015
    Messages:
    2,408
    Likes Received:
    508
    What?

    Methods inherited from class java.lang.Object:
    equals
     
  4. Party

    Party Client Developer

    Joined:
    Oct 12, 2015
    Messages:
    3,708
    Likes Received:
    1,606
    Just to add to that, in case you aren't that familiar with Java:

    All objects in Java inherit from class Object, meaning you can use any of the methods listed below with any object.
    Object (Java Platform SE 7 )
     
  5. Serene

    Serene ( ͡° ͜ʖ ͡°)

    Joined:
    Mar 30, 2015
    Messages:
    2,408
    Likes Received:
    508
    I still get marked as best answer tho
     
  6. Party

    Party Client Developer

    Joined:
    Oct 12, 2015
    Messages:
    3,708
    Likes Received:
    1,606
    No best answer available for posts marked Suggestion I'm afraid 8)
     
  7. tztok

    Joined:
    Nov 7, 2015
    Messages:
    31
    Likes Received:
    5
    it isnt implemented?
     
  8. Serene

    Serene ( ͡° ͜ʖ ͡°)

    Joined:
    Mar 30, 2015
    Messages:
    2,408
    Likes Received:
    508
    What kind of site is this ffs
    --- Double Post Merged, Dec 27, 2016, Original Post Date: Dec 27, 2016 ---
    Yeah test it out.

    private Area randomArea;
    randomArea.equals() should work.
     
  9. Party

    Party Client Developer

    Joined:
    Oct 12, 2015
    Messages:
    3,708
    Likes Received:
    1,606
    What do you mean? Read my post slowly and carefully. :p
     
  10. tztok

    Joined:
    Nov 7, 2015
    Messages:
    31
    Likes Received:
    5
    If you dont overrride it you cant use it like arraylist.contains(area)
    returns false
     
  11. Party

    Party Client Developer

    Joined:
    Oct 12, 2015
    Messages:
    3,708
    Likes Received:
    1,606
    Ehhhhhhhhhhhhh ????????????????
     
  12. tztok

    Joined:
    Nov 7, 2015
    Messages:
    31
    Likes Received:
    5
    try it
     
  13. Party

    Party Client Developer

    Joined:
    Oct 12, 2015
    Messages:
    3,708
    Likes Received:
    1,606
    try it:

    Code (Text):
    1.         Area area1 = new Area.Circular(new Coordinate(0, 0, 0), 2);
    2.         Area area2 = new Area.Circular(new Coordinate(0, 0, 0), 2);
    3.         System.out.println(area1.equals(area2));
    4.        
    5.         area1 = new Area.Circular(new Coordinate(0, 0, 0), 5);
    6.         System.out.println(area1.equals(area2));
     
  14. tztok

    Joined:
    Nov 7, 2015
    Messages:
    31
    Likes Received:
    5
    I meant this:

    Code (Text):
    1.  
    2.     public static final List<Area.Rectangular> nodes = Arrays.asList(
    3.             new Area.Rectangular(new Coordinate(4678, 3439, 0), new Coordinate(1678, 3537, 0))
    4.     );
    5.  
    6.     println(nodes.contains(new Area(new Coordinate(4678, 3439, 0), new Coordinate(1678, 3537, 0))));
    7.  
    --- Double Post Merged, Dec 27, 2016, Original Post Date: Dec 27, 2016 ---
    both print false


    if you dont override it, then it will use this from Object:
    Code (Text):
    1.  
    2. public boolean equals(Object obj) {
    3.     return (this == obj);
    4. }
    5.  
    This wont compare the coordinates.
     
    #14 tztok, Dec 27, 2016
    Last edited: Dec 27, 2016
  15. Party

    Party Client Developer

    Joined:
    Oct 12, 2015
    Messages:
    3,708
    Likes Received:
    1,606
    Probably, neither are valid coordinates (goof example). If you were to do it with Integers/anything else, you would get the point.

    What is it you're trying to accomplish? Whatever you're doing currently, it's probably wrong.

    Code (Text):
    1.  
    2. public static void main(String[] args) {
    3.     Integer i1 = 2;
    4.     Integer i2 = 2;
    5.     List<Integer> ints = Arrays.asList(new Integer(2)); //Unnecessary boxing but for example's sake
    6.     List<Integer> ints2 = Arrays.asList(i2);
    7.  
    8.     System.out.println(i1.equals(i2));
    9.     System.out.println(i1 == i2); //bad, don't do
    10.     System.out.println(Objects.equals(i1, i2));
    11.     System.out.println(ints.contains(i1));
    12.     System.out.println(ints.contains(i2));
    13.     System.out.println(ints2.contains(i1));
    14.     System.out.println(ints.contains(i2));
    15.     System.out.println(ints.contains(2));
    16.     System.out.println(ints2.contains(2));
    17.  
    18. }
    19.  
    Code (Text):
    1.  
    2. true
    3. true
    4. true
    5. true
    6. true
    7. true
    8. true
    9. true
    10. true
    11.  
     
  16. tztok

    Joined:
    Nov 7, 2015
    Messages:
    31
    Likes Received:
    5
    Those are true because class Integer overrides the equals method:

    Code (Text):
    1.  
    2. public boolean equals(Object obj) {
    3.     if (obj instanceof Integer) {
    4.         return value == ((Integer)obj).intValue();
    5.     }
    6.     return false;
    7. }
    8.  
     
  17. alibalhari

    Joined:
    Nov 22, 2016
    Messages:
    1
    Likes Received:
    0
    @Party ur getting rekt by this support
     
  18. Party

    Party Client Developer

    Joined:
    Oct 12, 2015
    Messages:
    3,708
    Likes Received:
    1,606
    wouldn't surprise me - not to be making excuses but I've driven for 12 hours today so my brain is melting away at the edges

    let me sleep and I'll come back and tell you either A. why you're wrong or B. how you could do it
     
  19. Serene

    Serene ( ͡° ͜ʖ ͡°)

    Joined:
    Mar 30, 2015
    Messages:
    2,408
    Likes Received:
    508
    How? There aren't many if any cases where it's necessary to compare a list of coordinates of areas (area vs area) unless making a dynamic list of them, which I don't really see a useful purpose for unless creating a dev tool for mapping areas - and even then you could just compare direct coordinates (which does have a direct equals override). Not a bad suggestion but there are workarounds and for something so small, eh.

    party u better find a way to make best answers on suggestion posts and mark me as one tho, ik you have the power to
     
    #19 Serene, Dec 27, 2016
    Last edited: Dec 27, 2016
    Party likes this.
  20. tztok

    Joined:
    Nov 7, 2015
    Messages:
    31
    Likes Received:
    5
    Ofc there is a work around, but its kinda annoying.
    I was just posting a suggestion to make this easier.
     
    #20 tztok, Dec 27, 2016
    Last edited: Dec 27, 2016

Share This Page

Loading...