public class PreconditionExcerpts extends Object
Preconditions methods.| Modifier and Type | Method and Description |
|---|---|
static Excerpt |
checkArgument(Object condition,
String message,
Object... args)
Returns an excerpt equivalent to Guava's
Preconditions.checkArgument(boolean, String, Object...). |
static Excerpt |
checkNotNull(Object reference)
Returns an excerpt equivalent to Guava's
Preconditions.checkNotNull(Object). |
static Excerpt |
checkNotNullInline(Object reference)
Returns an excerpt equivalent to an inline call to Guava's
Preconditions.checkNotNull(Object). |
static Excerpt |
checkNotNullPreamble(Object reference)
Returns an excerpt of the preamble required to emulate an inline call to Guava's
Preconditions.checkNotNull(Object) method. |
static Excerpt |
checkState(Object condition,
String message,
Object... args)
Returns an excerpt equivalent to Guava's
Preconditions.checkState(boolean, String, Object...). |
public static Excerpt checkNotNullPreamble(Object reference)
Preconditions.checkNotNull(Object) method.
If Guava or Java 7's Objects are available, no preamble will be generated. Otherwise, the check will be done out-of-line with an if block in this excerpt.
If you use this, you must also use checkNotNullInline(java.lang.Object) to allow the check to
be performed inline when possible:
code.add(checkNotNullPreamble("value"))
.addLine("this.property = %s;", checkNotNullInline("value"));reference - an excerpt containing the reference to pass to the checkNotNull methodpublic static Excerpt checkNotNullInline(Object reference)
Preconditions.checkNotNull(Object).
If you use this, you must also use checkNotNullPreamble(java.lang.Object) to allow the
check to be performed out-of-line if necessary:
code.add(checkNotNullPreamble("value"))
.addLine("this.property = %s;", checkNotNullInline("value"));reference - an excerpt containing the reference to pass to the checkNotNull methodpublic static Excerpt checkNotNull(Object reference)
Preconditions.checkNotNull(Object).
code.add(checkNotNull("key"))
.add(checkNotNull("value"))
.addLine("map.put(key, value);");reference - an excerpt containing the reference to pass to the checkNotNull methodpublic static Excerpt checkArgument(Object condition, String message, Object... args)
Preconditions.checkArgument(boolean, String, Object...).
code.add(checkArgument("age >= 0", "age must be non-negative (got %s)", "age"));condition - an excerpt containing the expression to pass to the checkArgument methodmessage - the error message template to pass to the checkArgument methodargs - excerpts containing the error message arguments to pass to the checkArgument methodpublic static Excerpt checkState(Object condition, String message, Object... args)
Preconditions.checkState(boolean, String, Object...).
code.add(checkState("start < end",
"start must be before end (got %s and %s)", "start", "end"));condition - an excerpt containing the expression to pass to the checkState methodmessage - the error message template to pass to the checkState methodargs - excerpts containing the error message arguments to pass to the checkState methodCopyright © 2016 Google, Inc.. All rights reserved.