Home | History | Annotate | Download | only in base
      1 /**
      2  * Copyright (c) 2000, 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.android.mail.common.base;
     17 
     18 
     19 
     20 /**
     21  * A utility class that contains some very widely used functionality.
     22  * This class is named "X" just to get a short name that can be typed
     23  * everywhere without cluttering up the code.  For example, it
     24  * seems a lot less verbose to say: "X.assertTrue(empty())" instead of
     25  * "Assert.assertTrue(empty())".
     26  *
     27  * <p>Consider using {@link Preconditions} instead though.
     28  *
     29  * <p>If your application is using JDK 1.4, feel free to use the built-in
     30  * assert() methods instead. <b>NOTE:</b> Except remember that JDK assertions
     31  * are not normally enabled unless you pass the -ea flag to the jvm.
     32  */
     33 public final class X {
     34 
     35   /**
     36    * This class should not be instantiated. It provides static methods
     37    * only.
     38    */
     39   private X() {}
     40 
     41   /**
     42    * Raise a runtime exception if the supplied argument is false (note: if you
     43    * are checking a precondition, please use {@link Preconditions} instead).
     44    */
     45   public static void assertTrue(boolean b) {
     46     if (!b)
     47       throw new RuntimeException("Assertion failed");
     48   }
     49 
     50   /**
     51    * Raise a runtime exception if the supplied argument is false and print
     52    * out the error message (note: if you are checking a precondition, please use
     53    * {@link Preconditions} instead).
     54    */
     55   public static void assertTrue(boolean b, String msg) {
     56     if (!b)
     57       throw new RuntimeException("Assertion failed: " + msg);
     58   }
     59 }