@ Override public ByteAmount increaseBy ( int percentage ) { checkArgument ( percentage >= 0 , String . format ( "Increasing by negative percent (%d) not supported" , percentage ) ) ; double factor = 1.0 + ( ( double ) percentage / 100 ) ; long max = Math . round ( Long . MAX_VALUE / factor ) ; checkArgument ( value <= max , String . format ( "Increasing %s by %d percent would exceed Long.MAX_LONG" , this , percentage ) ) ; return ByteAmount . fromBytes ( Math . round ( value . doubleValue ( ) * factor ) ) ; }
Increases by a percentage rounding any remainder . Be aware that because of rounding increases will be approximate to the nearest byte .