Factor out method for validating auto-delete timers.

This commit is contained in:
akwizgran
2020-11-23 16:42:45 +00:00
committed by Torsten Grote
parent 27893f9cdd
commit 61718192ee
5 changed files with 51 additions and 52 deletions

View File

@@ -7,6 +7,10 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import javax.annotation.Nullable;
import static org.briarproject.bramble.api.autodelete.AutoDeleteConstants.MAX_AUTO_DELETE_TIMER_MS;
import static org.briarproject.bramble.api.autodelete.AutoDeleteConstants.MIN_AUTO_DELETE_TIMER_MS;
import static org.briarproject.bramble.api.autodelete.AutoDeleteConstants.NO_AUTO_DELETE_TIMER;
@NotNullByDefault
public class ValidationUtils {
@@ -69,4 +73,11 @@ public class ValidationUtils {
throws FormatException {
if (l != null && (l < min || l > max)) throw new FormatException();
}
public static long validateAutoDeleteTimer(@Nullable Long timer)
throws FormatException {
if (timer == null) return NO_AUTO_DELETE_TIMER;
checkRange(timer, MIN_AUTO_DELETE_TIMER_MS, MAX_AUTO_DELETE_TIMER_MS);
return timer;
}
}