1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 2 <!--NewPage--> 3 <HTML> 4 <HEAD> 5 <!-- Generated by javadoc (build 1.6.0-google-internal) on Mon Jan 04 20:47:56 PST 2010 --> 6 <TITLE> 7 Preconditions (Guava Libraries 2010.01.04) 8 </TITLE> 9 10 <META NAME="date" CONTENT="2010-01-04"> 11 12 <LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../stylesheet.css" TITLE="Style"> 13 14 <SCRIPT type="text/javascript"> 15 function windowTitle() 16 { 17 if (location.href.indexOf('is-external=true') == -1) { 18 parent.document.title="Preconditions (Guava Libraries 2010.01.04)"; 19 } 20 } 21 </SCRIPT> 22 <NOSCRIPT> 23 </NOSCRIPT> 24 25 </HEAD> 26 27 <BODY BGCOLOR="white" onload="windowTitle();"> 28 <HR> 29 30 31 <!-- ========= START OF TOP NAVBAR ======= --> 32 <A NAME="navbar_top"><!-- --></A> 33 <A HREF="#skip-navbar_top" title="Skip navigation links"></A> 34 <TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY=""> 35 <TR> 36 <TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> 37 <A NAME="navbar_top_firstrow"><!-- --></A> 38 <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY=""> 39 <TR ALIGN="center" VALIGN="top"> 40 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD> 41 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD> 42 <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD> 43 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/Preconditions.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD> 44 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD> 45 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD> 46 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD> 47 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD> 48 </TR> 49 </TABLE> 50 </TD> 51 <TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM> 52 </EM> 53 </TD> 54 </TR> 55 56 <TR> 57 <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> 58 <A HREF="../../../../com/google/common/base/Objects.ToStringHelper.html" title="class in com.google.common.base"><B>PREV CLASS</B></A> 59 <A HREF="../../../../com/google/common/base/Predicate.html" title="interface in com.google.common.base"><B>NEXT CLASS</B></A></FONT></TD> 60 <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> 61 <A HREF="../../../../index.html?com/google/common/base/Preconditions.html" target="_top"><B>FRAMES</B></A> 62 <A HREF="Preconditions.html" target="_top"><B>NO FRAMES</B></A> 63 <SCRIPT type="text/javascript"> 64 <!-- 65 if(window==top) { 66 document.writeln('<A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>'); 67 } 68 //--> 69 </SCRIPT> 70 <NOSCRIPT> 71 <A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A> 72 </NOSCRIPT> 73 74 75 </FONT></TD> 76 </TR> 77 <TR> 78 <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> 79 SUMMARY: NESTED | FIELD | CONSTR | <A HREF="#method_summary">METHOD</A></FONT></TD> 80 <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> 81 DETAIL: FIELD | CONSTR | <A HREF="#method_detail">METHOD</A></FONT></TD> 82 </TR> 83 </TABLE> 84 <A NAME="skip-navbar_top"></A> 85 <!-- ========= END OF TOP NAVBAR ========= --> 86 87 <HR> 88 <!-- ======== START OF CLASS DATA ======== --> 89 <H2> 90 <FONT SIZE="-1"> 91 com.google.common.base</FONT> 92 <BR> 93 Class Preconditions</H2> 94 <PRE> 95 <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> 96 <IMG SRC="../../../../resources/inherit.gif" ALT="extended by "><B>com.google.common.base.Preconditions</B> 97 </PRE> 98 <HR> 99 <DL> 100 <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> 101 </PRE> 102 103 <P> 104 Simple static methods to be called at the start of your own methods to verify 105 correct arguments and state. This allows constructs such as 106 <pre> 107 if (count <= 0) { 108 throw new IllegalArgumentException("must be positive: " + count); 109 }</pre> 110 111 to be replaced with the more compact 112 <pre> 113 checkArgument(count > 0, "must be positive: %s", count);</pre> 114 115 Note that the sense of the expression is inverted; with <code>Preconditions</code> 116 you declare what you expect to be <i>true</i>, just as you do with an 117 <a href="http://java.sun.com/j2se/1.5.0/docs/guide/language/assert.html"> 118 <code>assert</code></a> or a JUnit <code>assertTrue</code> call. 119 120 <p><b>Warning:</b> only the <code>"%s"</code> specifier is recognized as a 121 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. 122 123 <p>Take care not to confuse precondition checking with other similar types 124 of checks! Precondition exceptions -- including those provided here, but also 125 <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 126 <i>calling method</i> has made an error. This tells the caller that it should 127 not have invoked the method when it did, with the arguments it did, or 128 perhaps ever. Postcondition or other invariant failures should not throw 129 these types of exceptions. 130 <P> 131 132 <P> 133 <DL> 134 <DT><B>Since:</B></DT> 135 <DD>2010.01.04 <b>stable</b> (imported from Google Collections Library)</DD> 136 <DT><B>Author:</B></DT> 137 <DD>Kevin Bourrillion</DD> 138 </DL> 139 <HR> 140 141 <P> 142 143 <!-- ========== METHOD SUMMARY =========== --> 144 145 <A NAME="method_summary"><!-- --></A> 146 <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""> 147 <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"> 148 <TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2"> 149 <B>Method Summary</B></FONT></TH> 150 </TR> 151 <TR BGCOLOR="white" CLASS="TableRowColor"> 152 <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 153 <CODE>static void</CODE></FONT></TD> 154 <TD><CODE><B><A HREF="../../../../com/google/common/base/Preconditions.html#checkArgument(boolean)">checkArgument</A></B>(boolean expression)</CODE> 155 156 <BR> 157 Ensures the truth of an expression involving one or more parameters to the 158 calling method.</TD> 159 </TR> 160 <TR BGCOLOR="white" CLASS="TableRowColor"> 161 <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 162 <CODE>static void</CODE></FONT></TD> 163 <TD><CODE><B><A HREF="../../../../com/google/common/base/Preconditions.html#checkArgument(boolean, java.lang.Object)">checkArgument</A></B>(boolean expression, 164 <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> 165 166 <BR> 167 Ensures the truth of an expression involving one or more parameters to the 168 calling method.</TD> 169 </TR> 170 <TR BGCOLOR="white" CLASS="TableRowColor"> 171 <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 172 <CODE>static void</CODE></FONT></TD> 173 <TD><CODE><B><A HREF="../../../../com/google/common/base/Preconditions.html#checkArgument(boolean, java.lang.String, java.lang.Object...)">checkArgument</A></B>(boolean expression, 174 <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, 175 <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> 176 177 <BR> 178 Ensures the truth of an expression involving one or more parameters to the 179 calling method.</TD> 180 </TR> 181 <TR BGCOLOR="white" CLASS="TableRowColor"> 182 <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 183 <CODE>static int</CODE></FONT></TD> 184 <TD><CODE><B><A HREF="../../../../com/google/common/base/Preconditions.html#checkElementIndex(int, int)">checkElementIndex</A></B>(int index, 185 int size)</CODE> 186 187 <BR> 188 Ensures that <code>index</code> specifies a valid <i>element</i> in an array, 189 list or string of size <code>size</code>.</TD> 190 </TR> 191 <TR BGCOLOR="white" CLASS="TableRowColor"> 192 <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 193 <CODE>static int</CODE></FONT></TD> 194 <TD><CODE><B><A HREF="../../../../com/google/common/base/Preconditions.html#checkElementIndex(int, int, java.lang.String)">checkElementIndex</A></B>(int index, 195 int size, 196 <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> 197 198 <BR> 199 Ensures that <code>index</code> specifies a valid <i>element</i> in an array, 200 list or string of size <code>size</code>.</TD> 201 </TR> 202 <TR BGCOLOR="white" CLASS="TableRowColor"> 203 <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 204 <CODE>static 205 <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" SUMMARY=""> 206 <TR ALIGN="right" VALIGN=""> 207 <TD NOWRAP><FONT SIZE="-1"> 208 <CODE><T> T</CODE></FONT></TD> 209 </TR> 210 </TABLE> 211 </CODE></FONT></TD> 212 <TD><CODE><B><A HREF="../../../../com/google/common/base/Preconditions.html#checkNotNull(T)">checkNotNull</A></B>(T reference)</CODE> 213 214 <BR> 215 Ensures that an object reference passed as a parameter to the calling 216 method is not null.</TD> 217 </TR> 218 <TR BGCOLOR="white" CLASS="TableRowColor"> 219 <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 220 <CODE>static 221 <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" SUMMARY=""> 222 <TR ALIGN="right" VALIGN=""> 223 <TD NOWRAP><FONT SIZE="-1"> 224 <CODE><T> T</CODE></FONT></TD> 225 </TR> 226 </TABLE> 227 </CODE></FONT></TD> 228 <TD><CODE><B><A HREF="../../../../com/google/common/base/Preconditions.html#checkNotNull(T, java.lang.Object)">checkNotNull</A></B>(T reference, 229 <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> 230 231 <BR> 232 Ensures that an object reference passed as a parameter to the calling 233 method is not null.</TD> 234 </TR> 235 <TR BGCOLOR="white" CLASS="TableRowColor"> 236 <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 237 <CODE>static 238 <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" SUMMARY=""> 239 <TR ALIGN="right" VALIGN=""> 240 <TD NOWRAP><FONT SIZE="-1"> 241 <CODE><T> T</CODE></FONT></TD> 242 </TR> 243 </TABLE> 244 </CODE></FONT></TD> 245 <TD><CODE><B><A HREF="../../../../com/google/common/base/Preconditions.html#checkNotNull(T, java.lang.String, java.lang.Object...)">checkNotNull</A></B>(T reference, 246 <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, 247 <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> 248 249 <BR> 250 Ensures that an object reference passed as a parameter to the calling 251 method is not null.</TD> 252 </TR> 253 <TR BGCOLOR="white" CLASS="TableRowColor"> 254 <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 255 <CODE>static int</CODE></FONT></TD> 256 <TD><CODE><B><A HREF="../../../../com/google/common/base/Preconditions.html#checkPositionIndex(int, int)">checkPositionIndex</A></B>(int index, 257 int size)</CODE> 258 259 <BR> 260 Ensures that <code>index</code> specifies a valid <i>position</i> in an array, 261 list or string of size <code>size</code>.</TD> 262 </TR> 263 <TR BGCOLOR="white" CLASS="TableRowColor"> 264 <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 265 <CODE>static int</CODE></FONT></TD> 266 <TD><CODE><B><A HREF="../../../../com/google/common/base/Preconditions.html#checkPositionIndex(int, int, java.lang.String)">checkPositionIndex</A></B>(int index, 267 int size, 268 <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> 269 270 <BR> 271 Ensures that <code>index</code> specifies a valid <i>position</i> in an array, 272 list or string of size <code>size</code>.</TD> 273 </TR> 274 <TR BGCOLOR="white" CLASS="TableRowColor"> 275 <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 276 <CODE>static void</CODE></FONT></TD> 277 <TD><CODE><B><A HREF="../../../../com/google/common/base/Preconditions.html#checkPositionIndexes(int, int, int)">checkPositionIndexes</A></B>(int start, 278 int end, 279 int size)</CODE> 280 281 <BR> 282 Ensures that <code>start</code> and <code>end</code> specify a valid <i>positions</i> 283 in an array, list or string of size <code>size</code>, and are in order.</TD> 284 </TR> 285 <TR BGCOLOR="white" CLASS="TableRowColor"> 286 <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 287 <CODE>static void</CODE></FONT></TD> 288 <TD><CODE><B><A HREF="../../../../com/google/common/base/Preconditions.html#checkState(boolean)">checkState</A></B>(boolean expression)</CODE> 289 290 <BR> 291 Ensures the truth of an expression involving the state of the calling 292 instance, but not involving any parameters to the calling method.</TD> 293 </TR> 294 <TR BGCOLOR="white" CLASS="TableRowColor"> 295 <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 296 <CODE>static void</CODE></FONT></TD> 297 <TD><CODE><B><A HREF="../../../../com/google/common/base/Preconditions.html#checkState(boolean, java.lang.Object)">checkState</A></B>(boolean expression, 298 <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> 299 300 <BR> 301 Ensures the truth of an expression involving the state of the calling 302 instance, but not involving any parameters to the calling method.</TD> 303 </TR> 304 <TR BGCOLOR="white" CLASS="TableRowColor"> 305 <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> 306 <CODE>static void</CODE></FONT></TD> 307 <TD><CODE><B><A HREF="../../../../com/google/common/base/Preconditions.html#checkState(boolean, java.lang.String, java.lang.Object...)">checkState</A></B>(boolean expression, 308 <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, 309 <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> 310 311 <BR> 312 Ensures the truth of an expression involving the state of the calling 313 instance, but not involving any parameters to the calling method.</TD> 314 </TR> 315 </TABLE> 316 <A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A> 317 <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""> 318 <TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor"> 319 <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> 320 </TR> 321 <TR BGCOLOR="white" CLASS="TableRowColor"> 322 <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> 323 </TR> 324 </TABLE> 325 326 <P> 327 328 <!-- ============ METHOD DETAIL ========== --> 329 330 <A NAME="method_detail"><!-- --></A> 331 <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""> 332 <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"> 333 <TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2"> 334 <B>Method Detail</B></FONT></TH> 335 </TR> 336 </TABLE> 337 338 <A NAME="checkArgument(boolean)"><!-- --></A><H3> 339 checkArgument</H3> 340 <PRE> 341 public static void <B>checkArgument</B>(boolean expression)</PRE> 342 <DL> 343 <DD>Ensures the truth of an expression involving one or more parameters to the 344 calling method. 345 <P> 346 <DD><DL> 347 <DT><B>Parameters:</B><DD><CODE>expression</CODE> - a boolean expression 348 <DT><B>Throws:</B> 349 <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> 350 </DD> 351 </DL> 352 <HR> 353 354 <A NAME="checkArgument(boolean, java.lang.Object)"><!-- --></A><H3> 355 checkArgument</H3> 356 <PRE> 357 public static void <B>checkArgument</B>(boolean expression, 358 <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> 359 <DL> 360 <DD>Ensures the truth of an expression involving one or more parameters to the 361 calling method. 362 <P> 363 <DD><DL> 364 <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 365 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> 366 <DT><B>Throws:</B> 367 <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> 368 </DD> 369 </DL> 370 <HR> 371 372 <A NAME="checkArgument(boolean, java.lang.String, java.lang.Object...)"><!-- --></A><H3> 373 checkArgument</H3> 374 <PRE> 375 public static void <B>checkArgument</B>(boolean expression, 376 <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, 377 <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> 378 <DL> 379 <DD>Ensures the truth of an expression involving one or more parameters to the 380 calling method. 381 <P> 382 <DD><DL> 383 <DT><B>Parameters:</B><DD><CODE>expression</CODE> - a boolean expression<DD><CODE>errorMessageTemplate</CODE> - a template for the exception message should the 384 check fail. The message is formed by replacing each <code>%s</code> 385 placeholder in the template with an argument. These are matched by 386 position - the first <code>%s</code> gets <code>errorMessageArgs[0]</code>, etc. 387 Unmatched arguments will be appended to the formatted message in square 388 braces. Unmatched placeholders will be left as-is.<DD><CODE>errorMessageArgs</CODE> - the arguments to be substituted into the message 389 template. Arguments are converted to strings using 390 <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>. 391 <DT><B>Throws:</B> 392 <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 393 <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 394 this happen)</DL> 395 </DD> 396 </DL> 397 <HR> 398 399 <A NAME="checkState(boolean)"><!-- --></A><H3> 400 checkState</H3> 401 <PRE> 402 public static void <B>checkState</B>(boolean expression)</PRE> 403 <DL> 404 <DD>Ensures the truth of an expression involving the state of the calling 405 instance, but not involving any parameters to the calling method. 406 <P> 407 <DD><DL> 408 <DT><B>Parameters:</B><DD><CODE>expression</CODE> - a boolean expression 409 <DT><B>Throws:</B> 410 <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> 411 </DD> 412 </DL> 413 <HR> 414 415 <A NAME="checkState(boolean, java.lang.Object)"><!-- --></A><H3> 416 checkState</H3> 417 <PRE> 418 public static void <B>checkState</B>(boolean expression, 419 <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> 420 <DL> 421 <DD>Ensures the truth of an expression involving the state of the calling 422 instance, but not involving any parameters to the calling method. 423 <P> 424 <DD><DL> 425 <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 426 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> 427 <DT><B>Throws:</B> 428 <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> 429 </DD> 430 </DL> 431 <HR> 432 433 <A NAME="checkState(boolean, java.lang.String, java.lang.Object...)"><!-- --></A><H3> 434 checkState</H3> 435 <PRE> 436 public static void <B>checkState</B>(boolean expression, 437 <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, 438 <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> 439 <DL> 440 <DD>Ensures the truth of an expression involving the state of the calling 441 instance, but not involving any parameters to the calling method. 442 <P> 443 <DD><DL> 444 <DT><B>Parameters:</B><DD><CODE>expression</CODE> - a boolean expression<DD><CODE>errorMessageTemplate</CODE> - a template for the exception message should the 445 check fail. The message is formed by replacing each <code>%s</code> 446 placeholder in the template with an argument. These are matched by 447 position - the first <code>%s</code> gets <code>errorMessageArgs[0]</code>, etc. 448 Unmatched arguments will be appended to the formatted message in square 449 braces. Unmatched placeholders will be left as-is.<DD><CODE>errorMessageArgs</CODE> - the arguments to be substituted into the message 450 template. Arguments are converted to strings using 451 <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>. 452 <DT><B>Throws:</B> 453 <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 454 <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 455 this happen)</DL> 456 </DD> 457 </DL> 458 <HR> 459 460 <A NAME="checkNotNull(java.lang.Object)"><!-- --></A><A NAME="checkNotNull(T)"><!-- --></A><H3> 461 checkNotNull</H3> 462 <PRE> 463 public static <T> T <B>checkNotNull</B>(T reference)</PRE> 464 <DL> 465 <DD>Ensures that an object reference passed as a parameter to the calling 466 method is not null. 467 <P> 468 <DD><DL> 469 <DT><B>Parameters:</B><DD><CODE>reference</CODE> - an object reference 470 <DT><B>Returns:</B><DD>the non-null reference that was validated 471 <DT><B>Throws:</B> 472 <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> 473 </DD> 474 </DL> 475 <HR> 476 477 <A NAME="checkNotNull(java.lang.Object,java.lang.Object)"><!-- --></A><A NAME="checkNotNull(T, java.lang.Object)"><!-- --></A><H3> 478 checkNotNull</H3> 479 <PRE> 480 public static <T> T <B>checkNotNull</B>(T reference, 481 <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> 482 <DL> 483 <DD>Ensures that an object reference passed as a parameter to the calling 484 method is not null. 485 <P> 486 <DD><DL> 487 <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 488 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> 489 <DT><B>Returns:</B><DD>the non-null reference that was validated 490 <DT><B>Throws:</B> 491 <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> 492 </DD> 493 </DL> 494 <HR> 495 496 <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> 497 checkNotNull</H3> 498 <PRE> 499 public static <T> T <B>checkNotNull</B>(T reference, 500 <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, 501 <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> 502 <DL> 503 <DD>Ensures that an object reference passed as a parameter to the calling 504 method is not null. 505 <P> 506 <DD><DL> 507 <DT><B>Parameters:</B><DD><CODE>reference</CODE> - an object reference<DD><CODE>errorMessageTemplate</CODE> - a template for the exception message should the 508 check fail. The message is formed by replacing each <code>%s</code> 509 placeholder in the template with an argument. These are matched by 510 position - the first <code>%s</code> gets <code>errorMessageArgs[0]</code>, etc. 511 Unmatched arguments will be appended to the formatted message in square 512 braces. Unmatched placeholders will be left as-is.<DD><CODE>errorMessageArgs</CODE> - the arguments to be substituted into the message 513 template. Arguments are converted to strings using 514 <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>. 515 <DT><B>Returns:</B><DD>the non-null reference that was validated 516 <DT><B>Throws:</B> 517 <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> 518 </DD> 519 </DL> 520 <HR> 521 522 <A NAME="checkElementIndex(int, int)"><!-- --></A><H3> 523 checkElementIndex</H3> 524 <PRE> 525 public static int <B>checkElementIndex</B>(int index, 526 int size)</PRE> 527 <DL> 528 <DD>Ensures that <code>index</code> specifies a valid <i>element</i> in an array, 529 list or string of size <code>size</code>. An element index may range from zero, 530 inclusive, to <code>size</code>, exclusive. 531 <P> 532 <DD><DL> 533 <DT><B>Parameters:</B><DD><CODE>index</CODE> - a user-supplied index identifying an element of an array, list 534 or string<DD><CODE>size</CODE> - the size of that array, list or string 535 <DT><B>Returns:</B><DD>the value of <code>index</code> 536 <DT><B>Throws:</B> 537 <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 538 less than <code>size</code> 539 <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> 540 </DD> 541 </DL> 542 <HR> 543 544 <A NAME="checkElementIndex(int, int, java.lang.String)"><!-- --></A><H3> 545 checkElementIndex</H3> 546 <PRE> 547 public static int <B>checkElementIndex</B>(int index, 548 int size, 549 <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> 550 <DL> 551 <DD>Ensures that <code>index</code> specifies a valid <i>element</i> in an array, 552 list or string of size <code>size</code>. An element index may range from zero, 553 inclusive, to <code>size</code>, exclusive. 554 <P> 555 <DD><DL> 556 <DT><B>Parameters:</B><DD><CODE>index</CODE> - a user-supplied index identifying an element of an array, list 557 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 558 <DT><B>Returns:</B><DD>the value of <code>index</code> 559 <DT><B>Throws:</B> 560 <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 561 less than <code>size</code> 562 <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> 563 </DD> 564 </DL> 565 <HR> 566 567 <A NAME="checkPositionIndex(int, int)"><!-- --></A><H3> 568 checkPositionIndex</H3> 569 <PRE> 570 public static int <B>checkPositionIndex</B>(int index, 571 int size)</PRE> 572 <DL> 573 <DD>Ensures that <code>index</code> specifies a valid <i>position</i> in an array, 574 list or string of size <code>size</code>. A position index may range from zero 575 to <code>size</code>, inclusive. 576 <P> 577 <DD><DL> 578 <DT><B>Parameters:</B><DD><CODE>index</CODE> - a user-supplied index identifying a position in an array, list 579 or string<DD><CODE>size</CODE> - the size of that array, list or string 580 <DT><B>Returns:</B><DD>the value of <code>index</code> 581 <DT><B>Throws:</B> 582 <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 583 greater than <code>size</code> 584 <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> 585 </DD> 586 </DL> 587 <HR> 588 589 <A NAME="checkPositionIndex(int, int, java.lang.String)"><!-- --></A><H3> 590 checkPositionIndex</H3> 591 <PRE> 592 public static int <B>checkPositionIndex</B>(int index, 593 int size, 594 <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> 595 <DL> 596 <DD>Ensures that <code>index</code> specifies a valid <i>position</i> in an array, 597 list or string of size <code>size</code>. A position index may range from zero 598 to <code>size</code>, inclusive. 599 <P> 600 <DD><DL> 601 <DT><B>Parameters:</B><DD><CODE>index</CODE> - a user-supplied index identifying a position in an array, list 602 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 603 <DT><B>Returns:</B><DD>the value of <code>index</code> 604 <DT><B>Throws:</B> 605 <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 606 greater than <code>size</code> 607 <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> 608 </DD> 609 </DL> 610 <HR> 611 612 <A NAME="checkPositionIndexes(int, int, int)"><!-- --></A><H3> 613 checkPositionIndexes</H3> 614 <PRE> 615 public static void <B>checkPositionIndexes</B>(int start, 616 int end, 617 int size)</PRE> 618 <DL> 619 <DD>Ensures that <code>start</code> and <code>end</code> specify a valid <i>positions</i> 620 in an array, list or string of size <code>size</code>, and are in order. A 621 position index may range from zero to <code>size</code>, inclusive. 622 <P> 623 <DD><DL> 624 <DT><B>Parameters:</B><DD><CODE>start</CODE> - a user-supplied index identifying a starting position in an 625 array, list or string<DD><CODE>end</CODE> - a user-supplied index identifying a ending position in an array, 626 list or string<DD><CODE>size</CODE> - the size of that array, list or string 627 <DT><B>Throws:</B> 628 <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 629 greater than <code>size</code>, or if <code>end</code> is less than <code>start</code> 630 <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> 631 </DD> 632 </DL> 633 <!-- ========= END OF CLASS DATA ========= --> 634 <HR> 635 636 637 <!-- ======= START OF BOTTOM NAVBAR ====== --> 638 <A NAME="navbar_bottom"><!-- --></A> 639 <A HREF="#skip-navbar_bottom" title="Skip navigation links"></A> 640 <TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY=""> 641 <TR> 642 <TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> 643 <A NAME="navbar_bottom_firstrow"><!-- --></A> 644 <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY=""> 645 <TR ALIGN="center" VALIGN="top"> 646 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD> 647 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD> 648 <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD> 649 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/Preconditions.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD> 650 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD> 651 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD> 652 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD> 653 <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD> 654 </TR> 655 </TABLE> 656 </TD> 657 <TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM> 658 </EM> 659 </TD> 660 </TR> 661 662 <TR> 663 <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> 664 <A HREF="../../../../com/google/common/base/Objects.ToStringHelper.html" title="class in com.google.common.base"><B>PREV CLASS</B></A> 665 <A HREF="../../../../com/google/common/base/Predicate.html" title="interface in com.google.common.base"><B>NEXT CLASS</B></A></FONT></TD> 666 <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> 667 <A HREF="../../../../index.html?com/google/common/base/Preconditions.html" target="_top"><B>FRAMES</B></A> 668 <A HREF="Preconditions.html" target="_top"><B>NO FRAMES</B></A> 669 <SCRIPT type="text/javascript"> 670 <!-- 671 if(window==top) { 672 document.writeln('<A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>'); 673 } 674 //--> 675 </SCRIPT> 676 <NOSCRIPT> 677 <A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A> 678 </NOSCRIPT> 679 680 681 </FONT></TD> 682 </TR> 683 <TR> 684 <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> 685 SUMMARY: NESTED | FIELD | CONSTR | <A HREF="#method_summary">METHOD</A></FONT></TD> 686 <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> 687 DETAIL: FIELD | CONSTR | <A HREF="#method_detail">METHOD</A></FONT></TD> 688 </TR> 689 </TABLE> 690 <A NAME="skip-navbar_bottom"></A> 691 <!-- ======== END OF BOTTOM NAVBAR ======= --> 692 693 <HR> 694 695 </BODY> 696 </HTML> 697