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.jcustenborder.kafka.connect.utils.StructHelper.java

public static SchemaAndValue asSchemaAndValue(Struct struct) {
    Preconditions.checkNotNull(struct, "struct cannot be null.");
    return new SchemaAndValue(struct.schema(), struct);
}

From source file:eu.thebluemountain.customers.dctm.brownbag.badcontentslister.config.JDBCConfig.java

/**
 * The method that creates a new JDBC configuration
 *
 * @param url carries the URL to connect to
 * @param user is the user to connect as
 * @param password is the password to connect with if any
 * @param schema is the default schema to use if any
 * @return the matching configuration/*from w  ww .  j  a v a  2s.  co  m*/
 */
public static JDBCConfig create(String url, String user, Optional<String> password, String schema) {
    return new JDBCConfig(Preconditions.checkNotNull(url, "null url supplied"),
            Preconditions.checkNotNull(user, "null user supplied"),
            Preconditions.checkNotNull(password, "null password supplied"),
            Preconditions.checkNotNull(schema, "null schema supplied"));
}

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

public static DataRequest newRequest(UUID requester, InputRow request, Class<? extends Evaluator> evaluator) {
    Preconditions.checkNotNull(requester, "Invalid requester");
    Preconditions.checkNotNull(request, "Invalid request");
    Preconditions.checkNotNull(evaluator, "Invalid evaluator");

    return new DataRequest(requester, request, evaluator);
}

From source file:com.google.security.zynamics.binnavi.ZyGraph.Updaters.CNodeUpdaterInitializer.java

/**
 * Adds node updaters to all nodes of a graph.
 *
 * @param model The model that describes the graph to be initialized.
 *//*from ww  w  .  ja va2 s. c o m*/
public static void addUpdaters(final CGraphModel model) {
    Preconditions.checkNotNull(model, "IE02240: Model argument can not be null");

    model.getGraph().iterate(new INodeCallback<NaviNode>() {
        @Override
        public IterationMode next(final NaviNode node) {
            addUpdaters(model, node);

            return IterationMode.CONTINUE;
        }
    });
}

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

public static InputRow getNext(InputRow from) {
    Preconditions.checkNotNull(from, "InputRow cannot be null");

    InputRow res = (InputRow) from.clone();
    increment(res, 0);//from   ww w.  jav a2  s  .  c o m

    return res;
}

From source file:org.onsteroids.eve.api.XmlUtility.java

public static Node getNodeByName(String name, Node parent) {
    Preconditions.checkNotNull(name, "Name");
    Preconditions.checkNotNull(parent, "Parent");
    NodeList list = parent.getChildNodes();
    for (int n = 0; n < list.getLength(); n++) {
        Node node = list.item(n);
        if (name.equals(node.getNodeName())) {
            return node;
        }// w ww.j  a v  a  2s. c  o  m
    }
    throw new IllegalArgumentException("Node " + name + " not found");
}

From source file:org.apache.eagle.metadata.utils.ConfigTemplateHelper.java

public static Configuration unmarshallFromXmlStream(InputStream inputStream) throws JAXBException {
    Preconditions.checkNotNull(inputStream, "Input stream is null");
    try {/*from   www.jav  a2s .  c  o  m*/
        JAXBContext jc = JAXBContext.newInstance(Configuration.class);
        Unmarshaller unmarshaller = jc.createUnmarshaller();
        return (Configuration) unmarshaller.unmarshal(inputStream);
    } catch (Exception ex) {
        LOG.error("Failed to unmarshall ConfigTemplate from stream", ex);
        throw ex;
    }
}

From source file:net.sf.derquinsej.Methods.java

/**
 * Returns the methods of a class as an iterable.
 * @param klass Class to process.//from   w ww.  j a v  a2 s.c  o m
 * @return The methods of the class.
 * @throws NullPointerException if the argument is null.
 */
public static List<Method> getMethods(Class<?> klass) {
    Preconditions.checkNotNull(klass, "A class must be provided");
    return Arrays.asList(klass.getMethods());
}

From source file:org.apache.flume.sink.customhdfs.SequenceFileSerializerFactory.java

@SuppressWarnings("unchecked")
static SequenceFileSerializer getSerializer(String formatType, Context context) {

    Preconditions.checkNotNull(formatType, "serialize type must not be null");

    // try to find builder class in enum of known formatters
    SequenceFileSerializerType type;//from  w  ww .  j  a va2 s.c o m
    try {
        type = SequenceFileSerializerType.valueOf(formatType);
    } catch (IllegalArgumentException e) {
        logger.debug("Not in enum, loading builder class: {}", formatType);
        type = SequenceFileSerializerType.Other;
    }
    Class<? extends SequenceFileSerializer.Builder> builderClass = type.getBuilderClass();

    // handle the case where they have specified their own builder in the config
    if (builderClass == null) {
        try {
            Class c = Class.forName(formatType);
            if (c != null && SequenceFileSerializer.Builder.class.isAssignableFrom(c)) {
                builderClass = (Class<? extends SequenceFileSerializer.Builder>) c;
            } else {
                logger.error("Unable to instantiate Builder from {}", formatType);
                return null;
            }
        } catch (ClassNotFoundException ex) {
            logger.error("Class not found: " + formatType, ex);
            return null;
        } catch (ClassCastException ex) {
            logger.error("Class does not extend " + SequenceFileSerializer.Builder.class.getCanonicalName()
                    + ": " + formatType, ex);
            return null;
        }
    }

    // build the builder
    SequenceFileSerializer.Builder builder;
    try {
        builder = builderClass.newInstance();
    } catch (InstantiationException ex) {
        logger.error("Cannot instantiate builder: " + formatType, ex);
        return null;
    } catch (IllegalAccessException ex) {
        logger.error("Cannot instantiate builder: " + formatType, ex);
        return null;
    }

    return builder.build(context);
}

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

public static Row fromSchema(RowSchema schema) {
    Preconditions.checkNotNull(schema, "Invalid schema specified");

    return new Row(InputRow.fromSchema(schema.getInputRowSchema()),
            OutputRow.fromSchema(schema.getOutputRowSchema()));
}