Im assuming "getPoints()" is an instance for the "MutableInteger" class, or, is that a separate class?
Edit: Nvm Im dumb lol
|
I made this thread to mostly to get feedback but I said why not and I released it as a snippet. I created this because I didn't want my Player class filled up with methods so I made universal methods for points.
Code:package com.elvarg.util; public class MutableInteger { private int value; public MutableInteger(int value) { this.value = value; } public void set(int value) { this.value = value; } public int get() { return value; } public void increment(int value) { this.value += value; } public void decrement(int value) { this.value -= value; } }Code:public MutableInteger SLAYER_POINTS = new MutableInteger(0);Code:player.getPoints().SLAYER_POINTS.get(); player.getPoints().SLAYER_POINTS.set(100); player.getPoints().SLAYER_POINTS.decrement(30);
Im assuming "getPoints()" is an instance for the "MutableInteger" class, or, is that a separate class?
Edit: Nvm Im dumb lol
Nothin special about this as the MutableInteger class does not specialize anything, what I mean is that you could utilize some methods to be more realistic with the system,
so somethin like:
void decrement(int amount) {
this.amount -= amount;
if (amount < 0) amount = 0;
}
Etc etc etc..
Even better idea, just use a mapping of keys to values where the keys are point types and the values are the associated amounts. Simple as that.
Code:Points points = player.getPoints(); Integer individualPoints = points.getOr(SomeEnumOfKeys.SLAYER_POINTS, 0); points.setInteger(SomeEnumOfKeys.SLAYER_POINTS, 1);
Thanks for your contribution!
Also, just wondering. But why not just have some kind of map holding attributes, including points and everything else?
I think it would be much cleaner instead of filling up the player class with crap
why did u name it SLAYER_POINTS when the name is literally MutableInteger.
Dont think thats the issue.. more like why would he name it like that when its not final
Technically it would make sense to make it uppercased if it was final and MutableInteger, even though the #value of the MutableInteger is mutable but the actual class is final so..
No. The java.lang.Number class already has everything you need to represent a mutable or immutable number.
No it wouldn't. An object or member cannot have a constant naming if the object is not effectively final and immutable.
i.e
The latter is correct because it provides no functions that mutate the underlying collection of strings. The former is incorrect because it provides function that mutate the underlying collection, such as set.Code:static final List<String> IMMUTABLE_STRING_VALUES = Arrays.asList("this", "is", "bad"); static final List<String> IMMUTABLE_STRING_VALUES = ImmutableList.of("this", "is", "correct");
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |