All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.kristofa.brave.internal.Util Maven / Gradle / Ivy

There is a newer version: 4.13.6
Show newest version
package com.github.kristofa.brave.internal;

import java.nio.charset.Charset;

import static java.lang.String.format;

/**
 * Utilities, typically copied in from guava, so as to avoid dependency conflicts.
 */
public final class Util {

  public static final Charset UTF_8 = Charset.forName("UTF-8");

  /**
   * Copy of {@code com.google.common.base.Preconditions#checkNotNull}.
   */
  public static  T checkNotNull(T reference, String errorMessageTemplate, Object... errorMessageArgs) {
    if (reference == null) {
      // If either of these parameters is null, the right thing happens anyway
      throw new NullPointerException(
          format(errorMessageTemplate, errorMessageArgs));
    }
    return reference;
  }

  public static String checkNotBlank(String string, String errorMessageTemplate,
                                     Object... errorMessageArgs) {
    if (checkNotNull(string, errorMessageTemplate, errorMessageArgs).trim().isEmpty()) {
      throw new IllegalArgumentException(format(errorMessageTemplate, errorMessageArgs));
    }
    return string;
  }

  public static boolean equal(Object a, Object b) {
    return a == b || (a != null && a.equals(b));
  }

  private Util() { // no instances
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy