🔀 Merge branch 'release/v82'
[Sone.git] / src / main / java / net / pterodactylus / sone / utils / NumberParsers.java
1 package net.pterodactylus.sone.utils;
2
3 import javax.annotation.Nullable;
4
5 import com.google.common.primitives.Ints;
6 import com.google.common.primitives.Longs;
7
8 /**
9  * Parses numbers from strings.
10  */
11 public class NumberParsers {
12
13         @Nullable
14         public static Integer parseInt(@Nullable String text,
15                         @Nullable Integer defaultValue) {
16                 if (text == null) {
17                         return defaultValue;
18                 }
19                 Integer value = Ints.tryParse(text);
20                 return (value == null) ? defaultValue : value;
21         }
22
23         @Nullable
24         public static Long parseLong(@Nullable String text,
25                         @Nullable Long defaultValue) {
26                 if (text == null) {
27                         return defaultValue;
28                 }
29                 Long value = Longs.tryParse(text);
30                 return (value == null) ? defaultValue : value;
31         }
32
33 }