<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--NewPage-->
<HTML>
<HEAD>
<!-- Generated by javadoc (build 1.6.0-google-internal) on Mon Jan 04 20:47:56 PST 2010 -->
<TITLE>
Preconditions (Guava Libraries 2010.01.04)
</TITLE>
<META NAME="date" CONTENT="2010-01-04">
<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../stylesheet.css" TITLE="Style">
<SCRIPT type="text/javascript">
function windowTitle()
{
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="Preconditions (Guava Libraries 2010.01.04)";
}
}
</SCRIPT>
<NOSCRIPT>
</NOSCRIPT>
</HEAD>
<BODY BGCOLOR="white" onload="windowTitle();">
<HR>
<!-- ========= START OF TOP NAVBAR ======= -->
<A NAME="navbar_top"><!-- --></A>
<A HREF="#skip-navbar_top" title="Skip navigation links"></A>
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
<TR>
<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
<A NAME="navbar_top_firstrow"><!-- --></A>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
<TR ALIGN="center" VALIGN="top">
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD>
<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/Preconditions.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD>
</TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
</EM>
</TD>
</TR>
<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../../com/google/common/base/Objects.ToStringHelper.html" title="class in com.google.common.base"><B>PREV CLASS</B></A>
<A HREF="../../../../com/google/common/base/Predicate.html" title="interface in com.google.common.base"><B>NEXT CLASS</B></A></FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../../index.html?com/google/common/base/Preconditions.html" target="_top"><B>FRAMES</B></A>
<A HREF="Preconditions.html" target="_top"><B>NO FRAMES</B></A>
<SCRIPT type="text/javascript">
<!--
if(window==top) {
document.writeln('<A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>');
}
//-->
</SCRIPT>
<NOSCRIPT>
<A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>
</NOSCRIPT>
</FONT></TD>
</TR>
<TR>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
SUMMARY: NESTED | FIELD | CONSTR | <A HREF="#method_summary">METHOD</A></FONT></TD>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
DETAIL: FIELD | CONSTR | <A HREF="#method_detail">METHOD</A></FONT></TD>
</TR>
</TABLE>
<A NAME="skip-navbar_top"></A>
<!-- ========= END OF TOP NAVBAR ========= -->
<HR>
<!-- ======== START OF CLASS DATA ======== -->
<H2>
<FONT SIZE="-1">
com.google.common.base</FONT>
<BR>
Class Preconditions</H2>
<PRE>
<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">java.lang.Object</A>
<IMG SRC="../../../../resources/inherit.gif" ALT="extended by "><B>com.google.common.base.Preconditions</B>
</PRE>
<HR>
<DL>
<DT><PRE>public final class <B>Preconditions</B><DT>extends <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</A></DL>
</PRE>
<P>
Simple static methods to be called at the start of your own methods to verify
correct arguments and state. This allows constructs such as
<pre>
if (count <= 0) {
throw new IllegalArgumentException("must be positive: " + count);
}</pre>
to be replaced with the more compact
<pre>
checkArgument(count > 0, "must be positive: %s", count);</pre>
Note that the sense of the expression is inverted; with <code>Preconditions</code>
you declare what you expect to be <i>true</i>, just as you do with an
<a href="http://java.sun.com/j2se/1.5.0/docs/guide/language/assert.html">
<code>assert</code></a> or a JUnit <code>assertTrue</code> call.
<p><b>Warning:</b> only the <code>"%s"</code> specifier is recognized as a
placeholder in these messages, not the full range of <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/String.html?is-external=true#format(java.lang.String, java.lang.Object...)" title="class or interface in java.lang"><CODE>String.format(String, Object[])</CODE></A> specifiers.
<p>Take care not to confuse precondition checking with other similar types
of checks! Precondition exceptions -- including those provided here, but also
<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/IndexOutOfBoundsException.html?is-external=true" title="class or interface in java.lang"><CODE>IndexOutOfBoundsException</CODE></A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/util/NoSuchElementException.html?is-external=true" title="class or interface in java.util"><CODE>NoSuchElementException</CODE></A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/UnsupportedOperationException.html?is-external=true" title="class or interface in java.lang"><CODE>UnsupportedOperationException</CODE></A> and others -- are used to signal that the
<i>calling method</i> has made an error. This tells the caller that it should
not have invoked the method when it did, with the arguments it did, or
perhaps ever. Postcondition or other invariant failures should not throw
these types of exceptions.
<P>
<P>
<DL>
<DT><B>Since:</B></DT>
<DD>2010.01.04 <b>stable</b> (imported from Google Collections Library)</DD>
<DT><B>Author:</B></DT>
<DD>Kevin Bourrillion</DD>
</DL>
<HR>
<P>
<!-- ========== METHOD SUMMARY =========== -->
<A NAME="method_summary"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
<B>Method Summary</B></FONT></TH>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../com/google/common/base/Preconditions.html#checkArgument(boolean)">checkArgument</A></B>(boolean expression)</CODE>
<BR>
Ensures the truth of an expression involving one or more parameters to the
calling method.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../com/google/common/base/Preconditions.html#checkArgument(boolean, java.lang.Object)">checkArgument</A></B>(boolean expression,
<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</A> errorMessage)</CODE>
<BR>
Ensures the truth of an expression involving one or more parameters to the
calling method.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../com/google/common/base/Preconditions.html#checkArgument(boolean, java.lang.String, java.lang.Object...)">checkArgument</A></B>(boolean expression,
<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A> errorMessageTemplate,
<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</A>... errorMessageArgs)</CODE>
<BR>
Ensures the truth of an expression involving one or more parameters to the
calling method.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static int</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../com/google/common/base/Preconditions.html#checkElementIndex(int, int)">checkElementIndex</A></B>(int index,
int size)</CODE>
<BR>
Ensures that <code>index</code> specifies a valid <i>element</i> in an array,
list or string of size <code>size</code>.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static int</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../com/google/common/base/Preconditions.html#checkElementIndex(int, int, java.lang.String)">checkElementIndex</A></B>(int index,
int size,
<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A> desc)</CODE>
<BR>
Ensures that <code>index</code> specifies a valid <i>element</i> in an array,
list or string of size <code>size</code>.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" SUMMARY="">
<TR ALIGN="right" VALIGN="">
<TD NOWRAP><FONT SIZE="-1">
<CODE><T> T</CODE></FONT></TD>
</TR>
</TABLE>
</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../com/google/common/base/Preconditions.html#checkNotNull(T)">checkNotNull</A></B>(T reference)</CODE>
<BR>
Ensures that an object reference passed as a parameter to the calling
method is not null.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" SUMMARY="">
<TR ALIGN="right" VALIGN="">
<TD NOWRAP><FONT SIZE="-1">
<CODE><T> T</CODE></FONT></TD>
</TR>
</TABLE>
</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../com/google/common/base/Preconditions.html#checkNotNull(T, java.lang.Object)">checkNotNull</A></B>(T reference,
<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</A> errorMessage)</CODE>
<BR>
Ensures that an object reference passed as a parameter to the calling
method is not null.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" SUMMARY="">
<TR ALIGN="right" VALIGN="">
<TD NOWRAP><FONT SIZE="-1">
<CODE><T> T</CODE></FONT></TD>
</TR>
</TABLE>
</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../com/google/common/base/Preconditions.html#checkNotNull(T, java.lang.String, java.lang.Object...)">checkNotNull</A></B>(T reference,
<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A> errorMessageTemplate,
<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</A>... errorMessageArgs)</CODE>
<BR>
Ensures that an object reference passed as a parameter to the calling
method is not null.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static int</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../com/google/common/base/Preconditions.html#checkPositionIndex(int, int)">checkPositionIndex</A></B>(int index,
int size)</CODE>
<BR>
Ensures that <code>index</code> specifies a valid <i>position</i> in an array,
list or string of size <code>size</code>.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static int</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../com/google/common/base/Preconditions.html#checkPositionIndex(int, int, java.lang.String)">checkPositionIndex</A></B>(int index,
int size,
<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A> desc)</CODE>
<BR>
Ensures that <code>index</code> specifies a valid <i>position</i> in an array,
list or string of size <code>size</code>.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../com/google/common/base/Preconditions.html#checkPositionIndexes(int, int, int)">checkPositionIndexes</A></B>(int start,
int end,
int size)</CODE>
<BR>
Ensures that <code>start</code> and <code>end</code> specify a valid <i>positions</i>
in an array, list or string of size <code>size</code>, and are in order.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../com/google/common/base/Preconditions.html#checkState(boolean)">checkState</A></B>(boolean expression)</CODE>
<BR>
Ensures the truth of an expression involving the state of the calling
instance, but not involving any parameters to the calling method.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../com/google/common/base/Preconditions.html#checkState(boolean, java.lang.Object)">checkState</A></B>(boolean expression,
<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</A> errorMessage)</CODE>
<BR>
Ensures the truth of an expression involving the state of the calling
instance, but not involving any parameters to the calling method.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../com/google/common/base/Preconditions.html#checkState(boolean, java.lang.String, java.lang.Object...)">checkState</A></B>(boolean expression,
<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A> errorMessageTemplate,
<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</A>... errorMessageArgs)</CODE>
<BR>
Ensures the truth of an expression involving the state of the calling
instance, but not involving any parameters to the calling method.</TD>
</TR>
</TABLE>
<A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
<TH ALIGN="left"><B>Methods inherited from class java.lang.<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</A></B></TH>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#clone()" title="class or interface in java.lang">clone</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#equals(java.lang.Object)" title="class or interface in java.lang">equals</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#finalize()" title="class or interface in java.lang">finalize</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#getClass()" title="class or interface in java.lang">getClass</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#hashCode()" title="class or interface in java.lang">hashCode</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#notify()" title="class or interface in java.lang">notify</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#notifyAll()" title="class or interface in java.lang">notifyAll</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#toString()" title="class or interface in java.lang">toString</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#wait()" title="class or interface in java.lang">wait</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#wait(long)" title="class or interface in java.lang">wait</A>, <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true#wait(long, int)" title="class or interface in java.lang">wait</A></CODE></TD>
</TR>
</TABLE>
<P>
<!-- ============ METHOD DETAIL ========== -->
<A NAME="method_detail"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
<B>Method Detail</B></FONT></TH>
</TR>
</TABLE>
<A NAME="checkArgument(boolean)"><!-- --></A><H3>
checkArgument</H3>
<PRE>
public static void <B>checkArgument</B>(boolean expression)</PRE>
<DL>
<DD>Ensures the truth of an expression involving one or more parameters to the
calling method.
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>expression</CODE> - a boolean expression
<DT><B>Throws:</B>
<DD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/IllegalArgumentException.html?is-external=true" title="class or interface in java.lang">IllegalArgumentException</A></CODE> - if <code>expression</code> is false</DL>
</DD>
</DL>
<HR>
<A NAME="checkArgument(boolean, java.lang.Object)"><!-- --></A><H3>
checkArgument</H3>
<PRE>
public static void <B>checkArgument</B>(boolean expression,
<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</A> errorMessage)</PRE>
<DL>
<DD>Ensures the truth of an expression involving one or more parameters to the
calling method.
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>expression</CODE> - a boolean expression<DD><CODE>errorMessage</CODE> - the exception message to use if the check fails; will
be converted to a string using <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/String.html?is-external=true#valueOf(java.lang.Object)" title="class or interface in java.lang"><CODE>String.valueOf(Object)</CODE></A>
<DT><B>Throws:</B>
<DD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/IllegalArgumentException.html?is-external=true" title="class or interface in java.lang">IllegalArgumentException</A></CODE> - if <code>expression</code> is false</DL>
</DD>
</DL>
<HR>
<A NAME="checkArgument(boolean, java.lang.String, java.lang.Object...)"><!-- --></A><H3>
checkArgument</H3>
<PRE>
public static void <B>checkArgument</B>(boolean expression,
<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A> errorMessageTemplate,
<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</A>... errorMessageArgs)</PRE>
<DL>
<DD>Ensures the truth of an expression involving one or more parameters to the
calling method.
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>expression</CODE> - a boolean expression<DD><CODE>errorMessageTemplate</CODE> - a template for the exception message should the
check fail. The message is formed by replacing each <code>%s</code>
placeholder in the template with an argument. These are matched by
position - the first <code>%s</code> gets <code>errorMessageArgs[0]</code>, etc.
Unmatched arguments will be appended to the formatted message in square
braces. Unmatched placeholders will be left as-is.<DD><CODE>errorMessageArgs</CODE> - the arguments to be substituted into the message
template. Arguments are converted to strings using
<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/String.html?is-external=true#valueOf(java.lang.Object)" title="class or interface in java.lang"><CODE>String.valueOf(Object)</CODE></A>.
<DT><B>Throws:</B>
<DD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/IllegalArgumentException.html?is-external=true" title="class or interface in java.lang">IllegalArgumentException</A></CODE> - if <code>expression</code> is false
<DD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/NullPointerException.html?is-external=true" title="class or interface in java.lang">NullPointerException</A></CODE> - if the check fails and either <code>errorMessageTemplate</code> or <code>errorMessageArgs</code> is null (don't let
this happen)</DL>
</DD>
</DL>
<HR>
<A NAME="checkState(boolean)"><!-- --></A><H3>
checkState</H3>
<PRE>
public static void <B>checkState</B>(boolean expression)</PRE>
<DL>
<DD>Ensures the truth of an expression involving the state of the calling
instance, but not involving any parameters to the calling method.
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>expression</CODE> - a boolean expression
<DT><B>Throws:</B>
<DD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/IllegalStateException.html?is-external=true" title="class or interface in java.lang">IllegalStateException</A></CODE> - if <code>expression</code> is false</DL>
</DD>
</DL>
<HR>
<A NAME="checkState(boolean, java.lang.Object)"><!-- --></A><H3>
checkState</H3>
<PRE>
public static void <B>checkState</B>(boolean expression,
<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</A> errorMessage)</PRE>
<DL>
<DD>Ensures the truth of an expression involving the state of the calling
instance, but not involving any parameters to the calling method.
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>expression</CODE> - a boolean expression<DD><CODE>errorMessage</CODE> - the exception message to use if the check fails; will
be converted to a string using <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/String.html?is-external=true#valueOf(java.lang.Object)" title="class or interface in java.lang"><CODE>String.valueOf(Object)</CODE></A>
<DT><B>Throws:</B>
<DD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/IllegalStateException.html?is-external=true" title="class or interface in java.lang">IllegalStateException</A></CODE> - if <code>expression</code> is false</DL>
</DD>
</DL>
<HR>
<A NAME="checkState(boolean, java.lang.String, java.lang.Object...)"><!-- --></A><H3>
checkState</H3>
<PRE>
public static void <B>checkState</B>(boolean expression,
<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A> errorMessageTemplate,
<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</A>... errorMessageArgs)</PRE>
<DL>
<DD>Ensures the truth of an expression involving the state of the calling
instance, but not involving any parameters to the calling method.
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>expression</CODE> - a boolean expression<DD><CODE>errorMessageTemplate</CODE> - a template for the exception message should the
check fail. The message is formed by replacing each <code>%s</code>
placeholder in the template with an argument. These are matched by
position - the first <code>%s</code> gets <code>errorMessageArgs[0]</code>, etc.
Unmatched arguments will be appended to the formatted message in square
braces. Unmatched placeholders will be left as-is.<DD><CODE>errorMessageArgs</CODE> - the arguments to be substituted into the message
template. Arguments are converted to strings using
<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/String.html?is-external=true#valueOf(java.lang.Object)" title="class or interface in java.lang"><CODE>String.valueOf(Object)</CODE></A>.
<DT><B>Throws:</B>
<DD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/IllegalStateException.html?is-external=true" title="class or interface in java.lang">IllegalStateException</A></CODE> - if <code>expression</code> is false
<DD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/NullPointerException.html?is-external=true" title="class or interface in java.lang">NullPointerException</A></CODE> - if the check fails and either <code>errorMessageTemplate</code> or <code>errorMessageArgs</code> is null (don't let
this happen)</DL>
</DD>
</DL>
<HR>
<A NAME="checkNotNull(java.lang.Object)"><!-- --></A><A NAME="checkNotNull(T)"><!-- --></A><H3>
checkNotNull</H3>
<PRE>
public static <T> T <B>checkNotNull</B>(T reference)</PRE>
<DL>
<DD>Ensures that an object reference passed as a parameter to the calling
method is not null.
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>reference</CODE> - an object reference
<DT><B>Returns:</B><DD>the non-null reference that was validated
<DT><B>Throws:</B>
<DD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/NullPointerException.html?is-external=true" title="class or interface in java.lang">NullPointerException</A></CODE> - if <code>reference</code> is null</DL>
</DD>
</DL>
<HR>
<A NAME="checkNotNull(java.lang.Object,java.lang.Object)"><!-- --></A><A NAME="checkNotNull(T, java.lang.Object)"><!-- --></A><H3>
checkNotNull</H3>
<PRE>
public static <T> T <B>checkNotNull</B>(T reference,
<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</A> errorMessage)</PRE>
<DL>
<DD>Ensures that an object reference passed as a parameter to the calling
method is not null.
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>reference</CODE> - an object reference<DD><CODE>errorMessage</CODE> - the exception message to use if the check fails; will
be converted to a string using <A HREF="http://java.sun.com/javase/6/docs/api/java/lang/String.html?is-external=true#valueOf(java.lang.Object)" title="class or interface in java.lang"><CODE>String.valueOf(Object)</CODE></A>
<DT><B>Returns:</B><DD>the non-null reference that was validated
<DT><B>Throws:</B>
<DD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/NullPointerException.html?is-external=true" title="class or interface in java.lang">NullPointerException</A></CODE> - if <code>reference</code> is null</DL>
</DD>
</DL>
<HR>
<A NAME="checkNotNull(java.lang.Object,java.lang.String,java.lang.Object[])"><!-- --></A><A NAME="checkNotNull(T, java.lang.String, java.lang.Object...)"><!-- --></A><H3>
checkNotNull</H3>
<PRE>
public static <T> T <B>checkNotNull</B>(T reference,
<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A> errorMessageTemplate,
<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</A>... errorMessageArgs)</PRE>
<DL>
<DD>Ensures that an object reference passed as a parameter to the calling
method is not null.
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>reference</CODE> - an object reference<DD><CODE>errorMessageTemplate</CODE> - a template for the exception message should the
check fail. The message is formed by replacing each <code>%s</code>
placeholder in the template with an argument. These are matched by
position - the first <code>%s</code> gets <code>errorMessageArgs[0]</code>, etc.
Unmatched arguments will be appended to the formatted message in square
braces. Unmatched placeholders will be left as-is.<DD><CODE>errorMessageArgs</CODE> - the arguments to be substituted into the message
template. Arguments are converted to strings using
<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/String.html?is-external=true#valueOf(java.lang.Object)" title="class or interface in java.lang"><CODE>String.valueOf(Object)</CODE></A>.
<DT><B>Returns:</B><DD>the non-null reference that was validated
<DT><B>Throws:</B>
<DD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/NullPointerException.html?is-external=true" title="class or interface in java.lang">NullPointerException</A></CODE> - if <code>reference</code> is null</DL>
</DD>
</DL>
<HR>
<A NAME="checkElementIndex(int, int)"><!-- --></A><H3>
checkElementIndex</H3>
<PRE>
public static int <B>checkElementIndex</B>(int index,
int size)</PRE>
<DL>
<DD>Ensures that <code>index</code> specifies a valid <i>element</i> in an array,
list or string of size <code>size</code>. An element index may range from zero,
inclusive, to <code>size</code>, exclusive.
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>index</CODE> - a user-supplied index identifying an element of an array, list
or string<DD><CODE>size</CODE> - the size of that array, list or string
<DT><B>Returns:</B><DD>the value of <code>index</code>
<DT><B>Throws:</B>
<DD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/IndexOutOfBoundsException.html?is-external=true" title="class or interface in java.lang">IndexOutOfBoundsException</A></CODE> - if <code>index</code> is negative or is not
less than <code>size</code>
<DD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/IllegalArgumentException.html?is-external=true" title="class or interface in java.lang">IllegalArgumentException</A></CODE> - if <code>size</code> is negative</DL>
</DD>
</DL>
<HR>
<A NAME="checkElementIndex(int, int, java.lang.String)"><!-- --></A><H3>
checkElementIndex</H3>
<PRE>
public static int <B>checkElementIndex</B>(int index,
int size,
<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A> desc)</PRE>
<DL>
<DD>Ensures that <code>index</code> specifies a valid <i>element</i> in an array,
list or string of size <code>size</code>. An element index may range from zero,
inclusive, to <code>size</code>, exclusive.
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>index</CODE> - a user-supplied index identifying an element of an array, list
or string<DD><CODE>size</CODE> - the size of that array, list or string<DD><CODE>desc</CODE> - the text to use to describe this index in an error message
<DT><B>Returns:</B><DD>the value of <code>index</code>
<DT><B>Throws:</B>
<DD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/IndexOutOfBoundsException.html?is-external=true" title="class or interface in java.lang">IndexOutOfBoundsException</A></CODE> - if <code>index</code> is negative or is not
less than <code>size</code>
<DD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/IllegalArgumentException.html?is-external=true" title="class or interface in java.lang">IllegalArgumentException</A></CODE> - if <code>size</code> is negative</DL>
</DD>
</DL>
<HR>
<A NAME="checkPositionIndex(int, int)"><!-- --></A><H3>
checkPositionIndex</H3>
<PRE>
public static int <B>checkPositionIndex</B>(int index,
int size)</PRE>
<DL>
<DD>Ensures that <code>index</code> specifies a valid <i>position</i> in an array,
list or string of size <code>size</code>. A position index may range from zero
to <code>size</code>, inclusive.
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>index</CODE> - a user-supplied index identifying a position in an array, list
or string<DD><CODE>size</CODE> - the size of that array, list or string
<DT><B>Returns:</B><DD>the value of <code>index</code>
<DT><B>Throws:</B>
<DD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/IndexOutOfBoundsException.html?is-external=true" title="class or interface in java.lang">IndexOutOfBoundsException</A></CODE> - if <code>index</code> is negative or is
greater than <code>size</code>
<DD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/IllegalArgumentException.html?is-external=true" title="class or interface in java.lang">IllegalArgumentException</A></CODE> - if <code>size</code> is negative</DL>
</DD>
</DL>
<HR>
<A NAME="checkPositionIndex(int, int, java.lang.String)"><!-- --></A><H3>
checkPositionIndex</H3>
<PRE>
public static int <B>checkPositionIndex</B>(int index,
int size,
<A HREF="http://java.sun.com/javase/6/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A> desc)</PRE>
<DL>
<DD>Ensures that <code>index</code> specifies a valid <i>position</i> in an array,
list or string of size <code>size</code>. A position index may range from zero
to <code>size</code>, inclusive.
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>index</CODE> - a user-supplied index identifying a position in an array, list
or string<DD><CODE>size</CODE> - the size of that array, list or string<DD><CODE>desc</CODE> - the text to use to describe this index in an error message
<DT><B>Returns:</B><DD>the value of <code>index</code>
<DT><B>Throws:</B>
<DD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/IndexOutOfBoundsException.html?is-external=true" title="class or interface in java.lang">IndexOutOfBoundsException</A></CODE> - if <code>index</code> is negative or is
greater than <code>size</code>
<DD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/IllegalArgumentException.html?is-external=true" title="class or interface in java.lang">IllegalArgumentException</A></CODE> - if <code>size</code> is negative</DL>
</DD>
</DL>
<HR>
<A NAME="checkPositionIndexes(int, int, int)"><!-- --></A><H3>
checkPositionIndexes</H3>
<PRE>
public static void <B>checkPositionIndexes</B>(int start,
int end,
int size)</PRE>
<DL>
<DD>Ensures that <code>start</code> and <code>end</code> specify a valid <i>positions</i>
in an array, list or string of size <code>size</code>, and are in order. A
position index may range from zero to <code>size</code>, inclusive.
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>start</CODE> - a user-supplied index identifying a starting position in an
array, list or string<DD><CODE>end</CODE> - a user-supplied index identifying a ending position in an array,
list or string<DD><CODE>size</CODE> - the size of that array, list or string
<DT><B>Throws:</B>
<DD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/IndexOutOfBoundsException.html?is-external=true" title="class or interface in java.lang">IndexOutOfBoundsException</A></CODE> - if either index is negative or is
greater than <code>size</code>, or if <code>end</code> is less than <code>start</code>
<DD><CODE><A HREF="http://java.sun.com/javase/6/docs/api/java/lang/IllegalArgumentException.html?is-external=true" title="class or interface in java.lang">IllegalArgumentException</A></CODE> - if <code>size</code> is negative</DL>
</DD>
</DL>
<!-- ========= END OF CLASS DATA ========= -->
<HR>
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<A NAME="navbar_bottom"><!-- --></A>
<A HREF="#skip-navbar_bottom" title="Skip navigation links"></A>
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
<TR>
<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
<A NAME="navbar_bottom_firstrow"><!-- --></A>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
<TR ALIGN="center" VALIGN="top">
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD>
<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/Preconditions.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD>
</TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
</EM>
</TD>
</TR>
<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../../com/google/common/base/Objects.ToStringHelper.html" title="class in com.google.common.base"><B>PREV CLASS</B></A>
<A HREF="../../../../com/google/common/base/Predicate.html" title="interface in com.google.common.base"><B>NEXT CLASS</B></A></FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../../index.html?com/google/common/base/Preconditions.html" target="_top"><B>FRAMES</B></A>
<A HREF="Preconditions.html" target="_top"><B>NO FRAMES</B></A>
<SCRIPT type="text/javascript">
<!--
if(window==top) {
document.writeln('<A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>');
}
//-->
</SCRIPT>
<NOSCRIPT>
<A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>
</NOSCRIPT>
</FONT></TD>
</TR>
<TR>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
SUMMARY: NESTED | FIELD | CONSTR | <A HREF="#method_summary">METHOD</A></FONT></TD>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
DETAIL: FIELD | CONSTR | <A HREF="#method_detail">METHOD</A></FONT></TD>
</TR>
</TABLE>
<A NAME="skip-navbar_bottom"></A>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
<HR>
</BODY>
</HTML>