| OLD | NEW |
| (Empty) | |
| 1 /* |
| 2 * Copyright 2011 Google Inc. |
| 3 * |
| 4 * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 * you may not use this file except in compliance with the License. |
| 6 * You may obtain a copy of the License at |
| 7 * |
| 8 * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 * |
| 10 * Unless required by applicable law or agreed to in writing, software |
| 11 * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 * See the License for the specific language governing permissions and |
| 14 * limitations under the License. |
| 15 */ |
| 16 package com.google.ipc.invalidation.util; |
| 17 |
| 18 |
| 19 /** |
| 20 * Precondition checkers modeled after {@link com.google.common.base.Preconditio
ns}. Duplicated here |
| 21 * to avoid the dependency on guava in Java client code. |
| 22 */ |
| 23 public class Preconditions { |
| 24 |
| 25 /** |
| 26 * Throws {@link NullPointerException} if the {@code reference} argument is |
| 27 * {@code null}. Otherwise, returns {@code reference}. |
| 28 */ |
| 29 public static <T> T checkNotNull(T reference) { |
| 30 if (reference == null) { |
| 31 throw new NullPointerException(); |
| 32 } |
| 33 return reference; |
| 34 } |
| 35 |
| 36 /** |
| 37 * Throws {@link NullPointerException} if the {@code reference} argument is |
| 38 * {@code null}. Otherwise, returns {@code reference}. |
| 39 */ |
| 40 public static <T> T checkNotNull(T reference, Object errorMessage) { |
| 41 if (reference == null) { |
| 42 throw new NullPointerException(String.valueOf(errorMessage)); |
| 43 } |
| 44 return reference; |
| 45 } |
| 46 |
| 47 /** Throws {@link IllegalStateException} if the given {@code expression} is {@
code false}. */ |
| 48 public static void checkState(boolean expression) { |
| 49 if (!expression) { |
| 50 throw new IllegalStateException(); |
| 51 } |
| 52 } |
| 53 |
| 54 /** Throws {@link IllegalStateException} if the given {@code expression} is {@
code false}. */ |
| 55 public static void checkState(boolean expression, Object errorMessage) { |
| 56 if (!expression) { |
| 57 throw new IllegalStateException(String.valueOf(errorMessage)); |
| 58 } |
| 59 } |
| 60 |
| 61 /** Throws {@link IllegalArgumentException} if the given {@code expression} is
{@code false}. */ |
| 62 public static void checkArgument(boolean expression) { |
| 63 if (!expression) { |
| 64 throw new IllegalArgumentException(); |
| 65 } |
| 66 } |
| 67 |
| 68 /** Throws {@link IllegalArgumentException} if the given {@code expression} is
{@code false}. */ |
| 69 public static void checkArgument(boolean expression, Object errorMessage) { |
| 70 if (!expression) { |
| 71 throw new IllegalArgumentException(String.valueOf(errorMessage)); |
| 72 } |
| 73 } |
| 74 |
| 75 // Do not instantiate. |
| 76 private Preconditions() { |
| 77 } |
| 78 } |
| OLD | NEW |