content: package <%= appPackage %>.repository.utils;
  
  import android.support.annotation.Nullable;
  
  /**
   * @author xiaobailong24
   * @date 2017/6/16
   * Preconditions
   */
  public final class Preconditions {
      private Preconditions() {
          throw new IllegalStateException("you can't instantiate me!");
      }
  
      public static void checkState(boolean expression) {
          if (!expression) {
              throw new IllegalStateException();
          }
      }
  
      public static void checkState(boolean expression, @Nullable Object errorMessage) {
          if (!expression) {
              throw new IllegalStateException(String.valueOf(errorMessage));
          }
      }
  
      public static void checkState(boolean expression, @Nullable String errorMessageTemplate, @Nullable Object... errorMessageArgs) {
          if (!expression) {
              throw new IllegalStateException(format(errorMessageTemplate, errorMessageArgs));
          }
      }
  
  
      public static <T> T checkNotNull(T reference, @Nullable Object errorMessage) {
          if (reference == null) {
              throw new NullPointerException(String.valueOf(errorMessage));
          } else {
              return reference;
          }
      }
  
      public static <T> T checkNotNull(T reference, @Nullable String errorMessageTemplate, @Nullable Object... errorMessageArgs) {
          if (reference == null) {
              throw new NullPointerException(format(errorMessageTemplate, errorMessageArgs));
          } else {
              return reference;
          }
      }
  
      static String format(String template, @Nullable Object... args) {
          template = String.valueOf(template);
          StringBuilder builder = new StringBuilder(template.length() + 16 * args.length);
          int templateStart = 0;
  
          int i;
          int placeholderStart;
          for (i = 0; i < args.length; templateStart = placeholderStart + 2) {
              placeholderStart = template.indexOf("%s", templateStart);
              if (placeholderStart == -1) {
                  break;
              }
  
              builder.append(template.substring(templateStart, placeholderStart));
              builder.append(args[i++]);
          }
  
          builder.append(template.substring(templateStart));
          if (i < args.length) {
              builder.append(" [");
              builder.append(args[i++]);
  
              while (i < args.length) {
                  builder.append(", ");
                  builder.append(args[i++]);
              }
  
              builder.append(']');
          }
  
          return builder.toString();
      }
  
  }
  