mirror of
https://github.com/correl/mage.git
synced 2025-01-13 11:01:58 +00:00
Moved overflow check method to CardUtil
This commit is contained in:
parent
2174f4d303
commit
c4334ef043
1 changed files with 0 additions and 22 deletions
|
@ -3000,26 +3000,4 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
fireEvent(new GameEvent(GameEvent.EventType.BECOMES_MONARCH, monarchId, source == null ? null : source.getSourceId(), monarchId));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addWithOverflowCheck(int base, int increment) {
|
||||
long result = ((long) base) + increment;
|
||||
if (result > Integer.MAX_VALUE) {
|
||||
return Integer.MAX_VALUE;
|
||||
} else if (result < Integer.MIN_VALUE) {
|
||||
return Integer.MIN_VALUE;
|
||||
}
|
||||
return base + increment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int subtractWithOverflowCheck(int base, int decrement) {
|
||||
long result = ((long) base) - decrement;
|
||||
if (result > Integer.MAX_VALUE) {
|
||||
return Integer.MAX_VALUE;
|
||||
} else if (result < Integer.MIN_VALUE) {
|
||||
return Integer.MIN_VALUE;
|
||||
}
|
||||
return base - decrement;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue