libgdx - Java Map with multiple primitive keys -



libgdx - Java Map with multiple primitive keys -

i'm looking have map in java/libgdx can take multiple primitive values key. concrete case have multiple position (x,y,z) need object attached.

at moment using (object)map list key, isn't there improve way?

the short reply question no, because primitive types can't java map keys. longer reply question easily, create position class -

static class position { int x; int y; int z; position(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } public boolean equals(object b) { if (b instanceof position) { position other = (position) b; homecoming this.x == other.x && this.y == other.y && this.z == other.z; } homecoming false; } public int hashcode() { homecoming (integer.valueof(x).hashcode() ^ integer.valueof(y) .hashcode()) & integer.valueof(z).hashcode(); } }

then

map<position, object> map;

java libgdx

Comments

Popular posts from this blog

ruby on rails - Devise Logout Error in RoR -

model view controller - MVC Rails Planning -

php - Working with pretty urls on apache and fastcgi after hhvm installation -