Merge pull request #8651 from Isira-Seneviratne/Use_limiting_methods

Use range-limiting methods.
This commit is contained in:
Stypox 2022-07-20 15:06:45 +02:00 committed by GitHub
commit cacce6d2d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 49 additions and 75 deletions

View file

@ -13,6 +13,7 @@ import android.util.DisplayMetrics;
import androidx.annotation.NonNull;
import androidx.annotation.PluralsRes;
import androidx.annotation.StringRes;
import androidx.core.math.MathUtils;
import androidx.preference.PreferenceManager;
import org.ocpsoft.prettytime.PrettyTime;
@ -247,8 +248,7 @@ public final class Localization {
// is not the responsibility of this method handle long numbers
// (it probably will fall in the "other" category,
// or some language have some specific rule... then we have to change it)
final int safeCount = count > Integer.MAX_VALUE ? Integer.MAX_VALUE
: count < Integer.MIN_VALUE ? Integer.MIN_VALUE : (int) count;
final int safeCount = (int) MathUtils.clamp(count, Integer.MIN_VALUE, Integer.MAX_VALUE);
return context.getResources().getQuantityString(pluralId, safeCount, formattedCount);
}