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.gmail.tracebachi.DeltaExecutor.DeltaExecutor.java

public static DeltaExecutor instance() {
    return Preconditions.checkNotNull(instance, "DeltaExecutor has not been initialized yet.");
}

From source file:org.apache.flume.serialization.EventDeserializerFactory.java

public static EventDeserializer getInstance(String deserializerType, Context context,
        ResettableInputStream in) {//  w  w  w .  j av  a  2 s . c o  m

    Preconditions.checkNotNull(deserializerType, "serializer type must not be null");

    // try to find builder class in enum of known output serializers
    EventDeserializerType type;
    try {
        type = EventDeserializerType.valueOf(deserializerType.toUpperCase());
    } catch (IllegalArgumentException e) {
        logger.debug("Not in enum, loading builder class: {}", deserializerType);
        type = EventDeserializerType.OTHER;
    }
    Class<? extends EventDeserializer.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(deserializerType);
            if (c != null && EventDeserializer.Builder.class.isAssignableFrom(c)) {
                builderClass = (Class<? extends EventDeserializer.Builder>) c;
            } else {
                String errMessage = "Unable to instantiate Builder from " + deserializerType
                        + ": does not appear to implement " + EventDeserializer.Builder.class.getName();
                throw new FlumeException(errMessage);
            }
        } catch (ClassNotFoundException ex) {
            logger.error("Class not found: " + deserializerType, ex);
            throw new FlumeException(ex);
        }
    }

    // build the builder
    EventDeserializer.Builder builder;
    try {
        builder = builderClass.newInstance();
    } catch (InstantiationException ex) {
        String errMessage = "Cannot instantiate builder: " + deserializerType;
        logger.error(errMessage, ex);
        throw new FlumeException(errMessage, ex);
    } catch (IllegalAccessException ex) {
        String errMessage = "Cannot instantiate builder: " + deserializerType;
        logger.error(errMessage, ex);
        throw new FlumeException(errMessage, ex);
    }

    return builder.build(context, in);
}

From source file:com.atoito.please.core.util.Environment.java

public static void initializeWithHome(File home) {
    // M.info("=========  initializeWithHome '%s'", home.getAbsolutePath());
    if (current != null) {
        throw new PleaseException("environment already initialized");
    }/* ww w  .  ja va2s  .c o  m*/
    File cleanHome = Preconditions.checkNotNull(home, "home directory cannot be null");
    Preconditions.checkArgument(cleanHome.exists(), "home '%s' not found", cleanHome.getAbsolutePath());
    Preconditions.checkArgument(cleanHome.isDirectory(), "home '%s' is not a directory",
            cleanHome.getAbsolutePath());
    current = new Environment(cleanHome);
}

From source file:fr.xebia.cloud.cloudinit.FreemarkerUtils.java

/**
 * /*  w w  w .j a v a  2 s.  c  o  m*/
 * @param rootMap
 *            root node of the freemarker datamodel.
 * @param templatePath
 *            classpath of the template
 * @return generated file
 */
@SuppressWarnings("unchecked")
@Nonnull
public static String generate(@Nullable Map<String, Object> rootMap, @Nonnull String templatePath) {
    Preconditions.checkNotNull(templatePath, "'templatePath' can NOT be null");
    rootMap = (Map<String, Object>) Objects.firstNonNull(rootMap, Collections.emptyMap());

    try {
        Configuration cfg = new Configuration();
        cfg.setClassForTemplateLoading(FreemarkerUtils.class, "/");

        Template template = cfg.getTemplate(templatePath);
        Writer out = new StringWriter();
        template.process(rootMap, out);
        return out.toString();
    } catch (IOException e) {
        throw Throwables.propagate(e);
    } catch (TemplateException e) {
        throw Throwables.propagate(e);
    }
}

From source file:works.chatterbox.hooks.ircchannels.tasks.SaveChannelsTask.java

public SaveChannelsTask(@NotNull final IRCChannels ircChannels) {
    Preconditions.checkNotNull(ircChannels, "ircChannels was null");
    this.ircChannels = ircChannels;
}

From source file:com.outerspacecat.util.Appendables.java

public static Writer tee(final Appendable a1, final Appendable a2) {
    Preconditions.checkNotNull(a1, "a1 required");
    Preconditions.checkNotNull(a2, "a2 required");

    return new Writer() {
        private boolean closed;

        @Override/*from   www .ja  v a2s . co  m*/
        public void write(final char[] cbuf, final int off, final int len) throws IOException {
            a1.append(CharBuffer.wrap(cbuf, off, len));
            a2.append(CharBuffer.wrap(cbuf, off, len));
        }

        @Override
        public void flush() throws IOException {
            if (a1 instanceof Flushable)
                ((Flushable) a1).flush();
            if (a2 instanceof Flushable)
                ((Flushable) a2).flush();
        }

        @Override
        public void close() throws IOException {
            if (closed)
                return;

            if (a1 instanceof Closeable)
                ((Closeable) a1).close();
            if (a2 instanceof Closeable)
                ((Closeable) a2).close();

            closed = true;
        }
    };
}

From source file:org.sonar.db.qualityprofile.ActiveRuleKey.java

/**
 * Create a key. Parameters are NOT null.
 *///ww w.  j  a v a 2s . c  o  m
public static ActiveRuleKey of(String qualityProfileKey, RuleKey ruleKey) {
    Preconditions.checkNotNull(qualityProfileKey, "QProfile is missing");
    Preconditions.checkNotNull(ruleKey, "RuleKey is missing");
    return new ActiveRuleKey(qualityProfileKey, ruleKey);
}

From source file:com.google.security.zynamics.binnavi.Gui.GraphWindows.Implementations.CGraphProximityBrowser.java

/**
 * Toggles the state of proximity browsing in the graph.
 *
 * @param parent Parent window used to display dialogs.
 * @param graph The graph where proximity browsing is switched on or off.
 *//*from   w w  w  .j  ava 2  s  .c  o m*/
public static void toggleProximityBrowsing(final JFrame parent, final ZyGraph graph) {
    Preconditions.checkNotNull(parent, "IE01750: Parent argument can not be null");

    Preconditions.checkNotNull(graph, "IE01751: Graph argument can not be null");

    if (graph.getSettings().getProximitySettings().getProximityBrowsing()) {
        CProgressDialog.showEndless(parent, "Switching off proximity browsing", new ProximityWaiter(graph));
    } else {
        CProgressDialog.showEndless(parent, "Switching on proximity browsing", new ProximityWaiter(graph));
    }
}

From source file:org.waveprotocol.box.server.authentication.AccountStoreHolder.java

synchronized public static void init(AccountStore store, String defaultDomain) {
    Preconditions.checkNotNull(store, "Account store cannot be null");
    Preconditions.checkNotNull(defaultDomain, "Default domain cannot be null");
    Preconditions.checkState(AccountStoreHolder.store == null, "Account store already set");
    AccountStoreHolder.store = store;//from  w  w  w. j ava  2s .  c o m
    AccountStoreHolder.defaultDomain = defaultDomain.toLowerCase();
}

From source file:org.opendaylight.controller.remote.rpc.messages.ErrorResponse.java

public ErrorResponse(final Exception e) {
    Preconditions.checkNotNull(e, "Exception should be present for error message");
    this.exception = e;
}