Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Planetary data representation
#1
Hi everyone!

I have to say, MekHQ looks awesome already. I especially like the fact that I can easily take the code and change it to my liking.

Which brings me to my point: Planetary and star system data. Right now, they are all crammed into the same class (mekhq.campaign.universe.Planet), which means that systems with multiple inhabited planets (like Sol and Niops) can't be added properly. I'd suggest moving whatever is needed for the star into its own "Star" class instead. A quick refactoring (thanks, Eclipse!) leads to the attached classes as a starting point.

As a side note: Currently, Planet has equals() defined, but not hashCode(). This is an error. The result is that two Planet objects which are equal according to equals() can have different hash codes according to hashCode(), since Object's default implementation does little more than return the in-memory address of the object. See also: http://www.javapractices.com/topic/TopicAction.do?Id=28



Attached Files
.java   Planet.java (Size: 20.94 KB / Downloads: 0)
.java   Star.java (Size: 11.98 KB / Downloads: 0)
Reply
#2
(01-15-2015, 06:21 AM)Akjosch link Wrote: Hi everyone!

I have to say, MekHQ looks awesome already. I especially like the fact that I can easily take the code and change it to my liking.

Which brings me to my point: Planetary and star system data. Right now, they are all crammed into the same class (mekhq.campaign.universe.Planet), which means that systems with multiple inhabited planets (like Sol and Niops) can't be added properly. I'd suggest moving whatever is needed for the star into its own "Star" class instead. A quick refactoring (thanks, Eclipse!) leads to the attached classes as a starting point.

As a side note: Currently, Planet has equals() defined, but not hashCode(). This is an error. The result is that two Planet objects which are equal according to equals() can have different hash codes according to hashCode(), since Object's default implementation does little more than return the in-memory address of the object. See also: http://www.javapractices.com/topic/TopicAction.do?Id=28

Not an error, just bad juju. Regardless, the whole thing is getting refactored later when I have time. Into SolarSystem and Planet. However, this is a much larger undertaking than one would think.
Reply
#3
Well, as soon as you put a Planet as a key in any collection, having equals() but not hashCode() is a disaster waiting to happen. You can do it ... but there are other things to keep in mind then, like "only having private constructors" to control which code is exactly allowed to create an instance.

That's why I like Lombok's @EqualsAndHashCode annotation - all the needed code, properly auto-generated and not cluttering the actual source code.
Reply
#4
Yes, this ability is something I've wanted implemented for a very long time, so hopefully it will be someday.

Just like that editor so I can generate non-canon stats to fluff out the planets without printed data that I've been promised for 3 years now. :Smile
Reply
#5
(01-15-2015, 12:20 PM)Jayof9s link Wrote: Just like that editor so I can generate non-canon stats to fluff out the planets without printed data that I've been promised for 3 years now. :Smile

You mean the one that I've got 85% or so finished and just never seem to get around to working on lately? lol

(01-15-2015, 08:53 AM)Akjosch link Wrote: Well, as soon as you put a Planet as a key in any collection, having equals() but not hashCode() is a disaster waiting to happen. You can do it ... but there are other things to keep in mind then, like "only having private constructors" to control which code is exactly allowed to create an instance.

That's why I like Lombok's @EqualsAndHashCode annotation - all the needed code, properly auto-generated and not cluttering the actual source code.

Lombok looks kinda neat, but personally I prefer to see all the boiler plate code in my files. As for the hashcode thing, open a bug report. I won't remember from the forum.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Planetary governor needs to give up! kipstafoo 2 708 08-12-2016, 06:02 PM
Last Post: BLOODWOLF
  Help With Planetary Data Jayof9s 317 69,830 04-26-2016, 10:21 AM
Last Post: Akjosch
  Planetary Ownership 3145 Madcow9000 3 961 01-17-2015, 10:21 AM
Last Post: Jayof9s
  Loading Planetary Data crash Groggy1 6 1,423 07-10-2013, 11:49 AM
Last Post: Jayof9s
  planetary ownership mchapman1970 2 1,148 10-12-2012, 11:48 PM
Last Post: mchapman1970
  how much data can the program have mchapman1970 10 2,797 05-31-2012, 06:39 PM
Last Post: ralgith
  Planetary recharge times Alain Dumont 5 1,694 03-28-2012, 04:30 PM
Last Post: Alain Dumont
  Question about the location of Planet Data Hammer 4 1,415 12-18-2011, 06:14 PM
Last Post: FogHat
  Planetary Map in MekHQ Snowene 2 1,446 11-28-2011, 11:51 PM
Last Post: Snowene
  Suggestion: Data Files Themicles 2 1,233 07-22-2011, 12:01 AM
Last Post: Themicles

Forum Jump:


Users browsing this thread: 1 Guest(s)