Example usage for com.google.common.base Preconditions checkNotNull

List of usage examples for com.google.common.base Preconditions checkNotNull

Introduction

In this page you can find the example usage for com.google.common.base Preconditions checkNotNull.

Prototype

public static <T> T checkNotNull(T reference, @Nullable Object errorMessage) 

Source Link

Document

Ensures that an object reference passed as a parameter to the calling method is not null.

Usage

From source file:com.zaradai.kunzite.optimizer.data.DataResult.java

public static DataResult newResult(UUID requestId, Row row) {
    Preconditions.checkNotNull(requestId, "Invalid request id");
    Preconditions.checkNotNull(row, "Invalid Row");

    return new DataResult(requestId, row);
}

From source file:net.awired.clients.sonar.QualityMeasures.java

public static SonarQualityMeasure asQualityMeasure(Measure measure, String measureKey) {
    Preconditions.checkNotNull(measure, "measure is mandatory");
    Preconditions.checkArgument(!measureKey.isEmpty(), "measureKey is mandatory");
    Preconditions.checkNotNull(measure.getValue(), "measure must have a value");
    Double value = measure.getValue();
    SonarQualityMeasure qualityMeasure = new SonarQualityMeasure();
    qualityMeasure.setKey(measureKey);/*from w  w  w. j  av  a  2  s. com*/
    qualityMeasure.setValue(value);
    qualityMeasure.setFormattedValue(measure.getFormattedValue());
    return qualityMeasure;
}

From source file:net.minecraftforge.server.permission.context.ContextKey.java

public static <E> ContextKey<E> create(String id, Class<E> c) {
    Preconditions.checkNotNull(id, "ContextKey's ID can't be null!");
    Preconditions.checkNotNull(c, "ContextKey's Type can't be null!");

    if (id.isEmpty()) {
        throw new IllegalArgumentException("ContextKey's ID can't be blank!");
    }/*  w  w  w . ja v a  2  s  .c o  m*/

    return new ContextKey<E>(id, c);
}

From source file:com.google.security.zynamics.zylib.general.StackTrace.java

/**
 * Converts a stack trace to a string./*from w ww  .ja  v a 2  s .c  o m*/
 * 
 * @param stackTrace The stack trace in question.
 * 
 * @return The converted stack trace.
 */
public static String toString(final StackTraceElement[] stackTrace) {
    Preconditions.checkNotNull(stackTrace, "Invalid stack trace");

    final StringBuilder sb = new StringBuilder();

    for (final StackTraceElement stackTraceElement : stackTrace) {
        sb.append(stackTraceElement.toString());
        sb.append(System.getProperty("line.separator"));
    }

    return sb.toString();
}

From source file:io.soabase.core.features.client.ClientUtils.java

public static String hostToServiceName(String host) {
    host = Preconditions.checkNotNull(host, "Request URI's host cannot be null");
    if (host.startsWith(HOST_SUBSTITUTION_TOKEN) && (host.length() > HOST_SUBSTITUTION_TOKEN.length())) {
        return host.substring(HOST_SUBSTITUTION_TOKEN.length());
    }//from w  w w .  j  a va  2  s  . com
    return null;
}

From source file:org.eclipse.lsp4j.util.Positions.java

/**
 * {@code true} if {@code left} is strictly before than {@code right}. Otherwise,
 * {@code false}.//from www.ja va2s  .  c o m
 * <p>
 * If you want to allow equality, use {@link Position#equals}.
 */
public static boolean isBefore(Position left, Position right) {
    Preconditions.checkNotNull(left, "left");
    Preconditions.checkNotNull(right, "right");
    if (left.getLine() < right.getLine()) {
        return true;
    }
    if (left.getLine() > right.getLine()) {
        return false;
    }
    return left.getCharacter() < right.getCharacter();
}

From source file:io.kazuki.v0.internal.helper.StringHelper.java

public static String toCamelCase(String value) {
    Preconditions.checkNotNull(value, "value");

    String canonical = value.replace('.', '-').toLowerCase();

    return CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, canonical);
}

From source file:io.github.bktlib.lazy.LazyInitVar.java

public static <T> LazyInitVar<T> of(@Nonnull Supplier<T> supp) {
    Preconditions.checkNotNull(supp, "supp");

    return new LazyInitVar<T>() {
        @Override/*from   ww  w  . j  a va 2  s.  c  om*/
        protected T init() {
            return supp.get();
        }
    };
}

From source file:uk.ac.cam.cl.dtg.picky.util.BuildProperties.java

public static Properties readBuildProperties() {

    try (InputStream inputStream = BuildProperties.class.getClassLoader()
            .getResourceAsStream("build.properties")) {
        Preconditions.checkNotNull(inputStream, "build.properties not found");

        Properties properties = new Properties();
        properties.load(inputStream);//w w w .  j ava  2s .  co m

        return properties;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.opendaylight.sloth.akka.SlothActorSystem.java

public static synchronized ActorSystem createActorSystem(final BundleContext bundleContext) {
    if (actorSystem == null) {
        Preconditions.checkNotNull(bundleContext, "can not create actor system with empty bundle context");
        BundleDelegatingClassLoader classLoader = new BundleDelegatingClassLoader(bundleContext.getBundle(),
                Thread.currentThread().getContextClassLoader());
        actorSystem = ActorSystem.create("SlothActorSystem", null, classLoader);
        LOG.info("successfully create actor system with osgi classloader");
    }//from   w w  w .j a v a  2s.  c  o m
    return actorSystem;
}