1 package net.pterodactylus.sone.utils;
3 import javax.annotation.Nonnull;
4 import javax.annotation.Nullable;
6 import com.google.common.primitives.Ints;
7 import com.google.common.primitives.Longs;
10 * Parses numbers from strings.
12 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
14 public class NumberParsers {
17 public static Integer parseInt(@Nullable String text,
18 @Nullable Integer defaultValue) {
22 Integer value = Ints.tryParse(text);
23 return (value == null) ? defaultValue : value;
27 public static Long parseLong(@Nullable String text,
28 @Nullable Long defaultValue) {
32 Long value = Longs.tryParse(text);
33 return (value == null) ? defaultValue : value;