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.github.jeluard.guayaba.lang.reflect.Fields.java

/**
 * @param <T>//from   ww  w .jav  a 2 s .c o  m
 * @param field
 * @param object
 * @return value of specified {@link Field}
 */
public static <T> T get(final Field field, final Object object) {
    Preconditions.checkNotNull(field, "null field");
    Preconditions.checkNotNull(object, "null object");

    if (!field.isAccessible()) {
        field.setAccessible(true);
    }

    try {
        return (T) field.get(object);
    } catch (IllegalAccessException e) {
        //Cannot happen as we force accessibility.
        throw new IllegalStateException(e);
    }
}

From source file:net.awired.visuwall.teamcityclient.DateAdapter.java

public static Date parseDate(String dateToParse) {
    Preconditions.checkNotNull(dateToParse, "dateToParse is mandatory");
    try {//from  w  w w.  jav  a  2  s  .c  o m
        return TEAMCITY_DATE_FORMAT.parse(dateToParse);
    } catch (ParseException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.zaradai.kunzite.optimizer.model.OutputRow.java

public static OutputRow fromSchema(OutputRowSchema schema) {
    Preconditions.checkNotNull(schema, "Must be created with valid schema");

    return new OutputRow(schema);
}

From source file:org.anarres.graphviz.builder.GraphVizUtils.java

/**
 * This supports a one-liner: GraphVizUtils.toGraphVizGraph(object).writeTo(new File(...)).
 *
 * @param object The object to graph./*from w w w  . j a v a 2s . c o m*/
 * @return A newly constructed GraphVizGraph.
 */
@Nonnull
public static GraphVizGraph toGraphVizGraph(@Nonnull GraphVizable object) {
    Preconditions.checkNotNull(object, "GraphVizable object was null.");
    GraphVizGraph graph = new GraphVizGraph();
    object.toGraphViz(graph);
    return graph;
}

From source file:org.opendaylight.lispflowmapping.lisp.util.LispSimpleAddressStringifier.java

public static String getString(Destination dst, SimpleAddress addr) {
    Preconditions.checkNotNull(addr, "address should not be null");

    if (addr.getIpAddress() != null) {
        if (addr.getIpAddress().getIpv4Address() != null) {
            return addr.getIpAddress().getIpv4Address().getValue();
        } else if (addr.getIpAddress().getIpv6Address() != null) {
            return addr.getIpAddress().getIpv6Address().getValue();
        }//  ww w .j  a v  a2s . c o m
    } else if (addr.getIpPrefix() != null) {
        if (addr.getIpPrefix().getIpv4Prefix() != null) {
            return addr.getIpPrefix().getIpv4Prefix().getValue();
        } else if (addr.getIpPrefix().getIpv6Prefix() != null) {
            return addr.getIpPrefix().getIpv6Prefix().getValue();
        }
    } else if (addr.getMacAddress() != null) {
        return addr.getMacAddress().getValue();
    } else if (addr.getDistinguishedNameType() != null) {
        return (addr.getDistinguishedNameType().getValue());
    } else if (addr.getAsNumber() != null) {
        return "AS" + addr.getAsNumber().getValue();
    }

    return null;
}

From source file:com.facebook.presto.sql.planner.DeterminismEvaluator.java

public static boolean isDeterministic(Expression expression) {
    Preconditions.checkNotNull(expression, "expression is null");

    AtomicBoolean deterministic = new AtomicBoolean(true);
    new Visitor().process(expression, deterministic);
    return deterministic.get();
}

From source file:com.nesscomputing.migratory.maven.ConfigureLog4j.java

public static void start(final AbstractMojo mojo) {
    LogManager.resetConfiguration();

    final URL configFile = ConfigureLog4j.class.getResource("/log4j-maven.xml");
    Preconditions.checkNotNull(configFile, "no log4j-maven.xml file found!");

    DOMConfigurator.configure(configFile);
    MavenLogAppender.startPluginLog(mojo);

}

From source file:com.github.jeluard.guayaba.base.Optionals.java

/**
 * @param <T>//from  w ww .j ava  2s .co m
 * @param optional
 * @return an {@link Optional} returning encapsulated {@link Optional}
 */
public static <T> Optional<T> flatten(final Optional<Optional<T>> optional) {
    Preconditions.checkNotNull(optional, "null optional");

    if (!optional.isPresent()) {
        return Optional.absent();
    }

    return optional.get();
}

From source file:com.zaradai.kunzite.optimizer.model.InputRow.java

public static InputRow fromSchema(InputRowSchema schema) {
    Preconditions.checkNotNull(schema, "Input row needs valid schema to build");

    return new InputRow(schema);
}

From source file:org.impressivecode.depress.common.TransformationUtils.java

public static String filePath2JavaClass(final String fileName) {
    Preconditions.checkNotNull(fileName, "FileName has to be set");
    return fileName.replaceAll("\\\\", ".").replaceAll("/", ".").replace(".java", "");
}