public class Alterable
extends java.lang.Object
Example:
final Alterable life = new Alterable(100); life.decrease(25); // life = 75 life.fill(); // life = 100 life.isFull(); // returns true life.getNeeded(150); // returns 50 life.setMax(150); life.fill(); // life = 150 life.increase(25); // life = 150 life.set(0); // life = 0 life.isEmpty(); // returns true
Attribute
Constructor and Description |
---|
Alterable(int max)
Constructor.
|
Alterable(int max,
boolean overMax)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
int |
decrease(int decrease)
Decrease current value.
|
void |
fill()
Fill until max value (set current value to max).
|
int |
getCurrent()
Get current value.
|
int |
getMax()
Get maximum reachable value.
|
int |
getNeeded(int value)
Get the needed value from an input to a specified value.
|
int |
getPercent()
Get percent value (depending of current/max).
|
int |
increase(int increase)
Increase current value.
|
boolean |
isEmpty()
Check if current value is equal to zero (current = 0).
|
boolean |
isEnough(int value)
Check if current value less the specified value is still positive.
|
boolean |
isFull()
Check if current value equal max or not (current == max).
|
void |
reset()
Reset value to minimum.
|
void |
set(int value)
Set current value.
|
void |
setMax(int max)
Set maximum reachable value.
|
public Alterable(int max)
max
- The maximum reachable value.public Alterable(int max, boolean overMax)
max
- The maximum reachable value.overMax
- true
to allow over value.public int increase(int increase)
increase
- The increase step.public int decrease(int decrease)
decrease
- The decrease step.public void fill()
public void reset()
public void set(int value)
value
- The current value.public void setMax(int max)
max
- The maximum reachable value.public int getMax()
public int getCurrent()
public int getPercent()
public int getNeeded(int value)
Example: if current = 50; getNeeded(60) will return 10 (60 - 50).
value
- The quantity desired.public boolean isFull()
true
if current equal max, false
else.public boolean isEmpty()
true
if 0, false
else.public boolean isEnough(int value)
isEnough(40)
will return true
;
isEnough(60)
will return false
.value
- The check value.true
if subtract is positive, false
else.