Chromium Code Reviews| Index: remoting/android/java/src/org/chromium/chromoting/Preconditions.java |
| diff --git a/remoting/android/java/src/org/chromium/chromoting/Preconditions.java b/remoting/android/java/src/org/chromium/chromoting/Preconditions.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b91fdf29c4df721c0b18dd8b3bdbad655a4b8e0a |
| --- /dev/null |
| +++ b/remoting/android/java/src/org/chromium/chromoting/Preconditions.java |
| @@ -0,0 +1,33 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.chromoting; |
| + |
| +/** |
| + * A set of helper functions to write assertions. These functions are always being executed, and |
| + * will not ignored in release build. |
| + */ |
| + |
| +public final class Preconditions { |
| + // This class contains only static functions, so it should not be instantiated. |
| + private Preconditions() {} |
| + |
| + // Checks whether input |v| is true, and returns its value. Throws |
|
Lambros
2016/05/27 00:38:52
s/v/value
Why bother returning the value if it's
Hzj_jie
2016/05/27 02:55:20
I think it's more helpful in the following scenari
|
| + // {@link IllegalStateException} if |v| is false. |
| + public static final boolean isTrue(boolean v) { |
| + if (!v) { |
| + throw new IllegalStateException(); |
| + } |
| + return v; |
| + } |
| + |
| + // Checks whether input |ref| is not a null reference, and return its value. Throws |
| + // {@link NullPointerException} if |ref| is null. |
| + public static final <T> T notNull(T ref) { |
| + if (ref == null) { |
| + throw new NullPointerException(); |
| + } |
| + return ref; |
| + } |
| +} |