8686 * <p>
8787 * Using functional blocks to handle operations, that are intended to operate properly, simplify the code and makes it more
8888 * readable. It's also good way to deal with untested, uncovered {@code catch} blocks. It's easy and gives developers nice way of
89- * dealing with countless operations that supose to work as intended.
89+ * dealing with countless operations that suppose to work as intended.
9090 *
9191 * <p>
9292 * Example:
@@ -113,29 +113,31 @@ protected EidPreconditions() {
113113 /**
114114 * Ensures the truth of an expression involving one or more parameters to the calling method.
115115 *
116- * @param expression ({@link Nonnull }) a boolean expression
116+ * @param expression ({@link Nullable }) a boolean expression
117117 * @param eid ({@link Nonnull}) the exception ID to use if the check fails; will be converted to
118118 * {@link pl.wavesoftware.eid.exceptions.Eid}
119119 * @throws EidIllegalArgumentException if {@code expression} is false
120+ * @throws EidNullPointerException if {@code expression} is null
120121 */
121- public static void checkArgument (@ Nonnull boolean expression , @ Nonnull String eid ) {
122+ public static void checkArgument (@ Nullable Boolean expression , @ Nonnull String eid ) {
122123 String checkedEid = checkNotNull (eid );
123- if (!expression ) {
124+ if (!checkNotNull ( expression , checkedEid ) ) {
124125 throw new EidIllegalArgumentException (new Eid (checkedEid ));
125126 }
126127 }
127128
128129 /**
129130 * Ensures the truth of an expression involving one or more parameters to the calling method.
130131 *
131- * @param expression ({@link Nonnull }) a boolean expression
132+ * @param expression ({@link Nullable }) a boolean expression
132133 * @param eid ({@link Nonnull}) the exception ID to use if the check fails; will be converted to
133134 * {@link pl.wavesoftware.eid.exceptions.Eid}
134135 * @throws EidIllegalArgumentException if {@code expression} is false
136+ * @throws EidNullPointerException if {@code expression} is null
135137 */
136- public static void checkArgument (@ Nonnull boolean expression , @ Nonnull Eid eid ) {
138+ public static void checkArgument (@ Nullable Boolean expression , @ Nonnull Eid eid ) {
137139 Eid checkedEid = checkNotNull (eid );
138- if (!expression ) {
140+ if (!checkNotNull ( expression , checkedEid ) ) {
139141 throw new EidIllegalArgumentException (checkedEid );
140142 }
141143 }
@@ -144,14 +146,15 @@ public static void checkArgument(@Nonnull boolean expression, @Nonnull Eid eid)
144146 * Ensures the truth of an expression involving the state of the calling instance, but not involving any parameters to the
145147 * calling method.
146148 *
147- * @param expression a boolean expression
148- * @param eid the exception message to use if the check fails; will be converted to a string using
149+ * @param expression ({@link Nullable}) a boolean expression
150+ * @param eid ({@link Nonnull}) the exception message to use if the check fails; will be converted to a string using
149151 * {@link String#valueOf(Object)}
150152 * @throws EidIllegalStateException if {@code expression} is false
153+ * @throws EidNullPointerException if {@code expression} is null
151154 */
152- public static void checkState (@ Nonnull boolean expression , @ Nonnull String eid ) {
155+ public static void checkState (@ Nullable Boolean expression , @ Nonnull String eid ) {
153156 String checkedEid = checkNotNull (eid );
154- if (!expression ) {
157+ if (!checkNotNull ( expression , checkedEid ) ) {
155158 throw new EidIllegalStateException (new Eid (checkedEid ));
156159 }
157160 }
@@ -160,14 +163,14 @@ public static void checkState(@Nonnull boolean expression, @Nonnull String eid)
160163 * Ensures the truth of an expression involving the state of the calling instance, but not involving any parameters to the
161164 * calling method.
162165 *
163- * @param expression a boolean expression
164- * @param eid the exception message to use if the check fails; will be converted to a string using
166+ * @param expression ({@link Nullable}) a boolean expression
167+ * @param eid ({@link Nonnull}) the exception message to use if the check fails; will be converted to a string using
165168 * {@link String#valueOf(Object)}
166169 * @throws EidIllegalStateException if {@code expression} is false
167170 */
168- public static void checkState (@ Nonnull boolean expression , @ Nonnull Eid eid ) {
171+ public static void checkState (@ Nullable Boolean expression , @ Nonnull Eid eid ) {
169172 Eid checkedEid = checkNotNull (eid );
170- if (!expression ) {
173+ if (!checkNotNull ( expression , checkedEid ) ) {
171174 throw new EidIllegalStateException (checkedEid );
172175 }
173176 }
@@ -221,7 +224,6 @@ public static <T> T checkNotNull(@Nullable T reference, @Nonnull Eid eid) {
221224 * @throws EidIndexOutOfBoundsException if {@code index} is negative or is not less than {@code size}
222225 * @throws EidIllegalArgumentException if {@code size} is negative
223226 */
224- @ Nonnull
225227 public static int checkElementIndex (int index , int size , @ Nonnull String eid ) {
226228 String checkedEid = checkNotNull (eid );
227229 if (size < 0 ) {
@@ -245,7 +247,6 @@ public static int checkElementIndex(int index, int size, @Nonnull String eid) {
245247 * @throws EidIndexOutOfBoundsException if {@code index} is negative or is not less than {@code size}
246248 * @throws EidIllegalArgumentException if {@code size} is negative
247249 */
248- @ Nonnull
249250 public static int checkElementIndex (int index , int size , @ Nonnull Eid eid ) {
250251 Eid checkedEid = checkNotNull (eid );
251252 if (size < 0 ) {
@@ -350,8 +351,12 @@ public interface RiskyCode<R> {
350351 R execute () throws Exception ;
351352 }
352353
354+ private static boolean isNull (@ Nullable Object reference ) {
355+ return reference == null ;
356+ }
357+
353358 private static <T > T checkNotNull (@ Nullable T reference ) {
354- if (reference == null ) {
359+ if (isNull ( reference ) ) {
355360 throw new IllegalArgumentException ("Pass not-null Eid to EidPreconditions first!" );
356361 }
357362 return reference ;
0 commit comments