Moved overflow check method to CardUtil

This commit is contained in:
Zzooouhh 2017-12-23 23:58:31 +01:00 committed by GitHub
parent 2174f4d303
commit c4334ef043
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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;
}
}