diff options
author | Timothée Floure | 2016-05-27 13:47:51 +0200 |
---|---|---|
committer | Timothée Floure | 2016-05-27 13:47:51 +0200 |
commit | e7382c3c2a28109b18492e9a62265c51b1be94dd (patch) | |
tree | 68b75b4968f74ddde01d012cccc5cf596a823ec0 /src/ch/epfl/xblast/ArgumentChecker.java | |
parent | 7d9c28e25d5b0965171f4b347852a11fdf01482e (diff) | |
parent | a82a8ba2611378ff6fb1cd226fb3d579d43d6e89 (diff) | |
download | xblast-master.tar.gz |
11 network
See merge request !11
Diffstat (limited to 'src/ch/epfl/xblast/ArgumentChecker.java')
-rw-r--r-- | src/ch/epfl/xblast/ArgumentChecker.java | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/ch/epfl/xblast/ArgumentChecker.java b/src/ch/epfl/xblast/ArgumentChecker.java index 7e77b61..56f8acd 100644 --- a/src/ch/epfl/xblast/ArgumentChecker.java +++ b/src/ch/epfl/xblast/ArgumentChecker.java | |||
@@ -59,4 +59,33 @@ public final class ArgumentChecker { | |||
59 | return s; | 59 | return s; |
60 | } | 60 | } |
61 | 61 | ||
62 | /** | ||
63 | * Returns the element from the array at the requested index, or null if it cannot be retrieved. | ||
64 | * | ||
65 | * @param array the array | ||
66 | * @param index the index | ||
67 | * @param <T> the type of element | ||
68 | * @return the requested element, or null | ||
69 | */ | ||
70 | public static <T> T getOrNull(T[] array, int index) { | ||
71 | if (Objects.isNull(array) || index < 0 || index >= array.length) | ||
72 | return null; | ||
73 | else | ||
74 | return array[index]; | ||
75 | } | ||
76 | |||
77 | /** | ||
78 | * Parses and returns an integer, or return null on error. | ||
79 | * | ||
80 | * @param str the integer to parse | ||
81 | * @return the parsed integer, or null | ||
82 | */ | ||
83 | public static Integer parseIntOrNull(String str) { | ||
84 | try { | ||
85 | return Integer.parseInt(str); | ||
86 | } catch (NumberFormatException | NullPointerException e) { | ||
87 | return null; | ||
88 | } | ||
89 | } | ||
90 | |||
62 | } | 91 | } |