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

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

Introduction

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

Prototype

public static void checkState(boolean expression, @Nullable Object errorMessage) 

Source Link

Document

Ensures the truth of an expression involving the state of the calling instance, but not involving any parameters to the calling method.

Usage

From source file:com.android.camera.async.RefCountBase.java

public RefCountBase(T object, int initialReferenceCount) {
    Preconditions.checkState(initialReferenceCount > 0, "initialReferenceCount is not greater than 0.");
    mLock = new Object();
    mObject = object;/*from  www. j a  v  a2 s  .co m*/
    mRefCount = initialReferenceCount;
    mObjectClosed = false;
}

From source file:com.nesscomputing.mojo.numbers.macros.DemoMacro.java

@Override
public String getValue(@Nonnull final MacroDefinition macroDefinition,
        @Nonnull final ValueProvider valueProvider, @Nonnull final AbstractNumbersMojo mojo) {
    Preconditions.checkState(mojo != null, "inserted mojo is null!");

    final String type = macroDefinition.getProperties().getProperty("type", "static");
    if ("static".equals(type)) {
        return "static-value";
    } else if ("property".equals(type)) {
        return valueProvider.getValue();
    } else {//from  w  ww. j a v a2  s  . c o  m
        return macroDefinition.getProperties().getProperty("value");
    }
}

From source file:codecrafter47.bungeetablistplus.api.bukkit.BungeeTabListPlusBukkitAPI.java

/**
 * Unregisters all variables registered by the give plugin
 *
 * @param plugin the plugin/*from   ww  w.ja v  a2 s.  c o m*/
 */
public static void unregisterVariables(Plugin plugin) {
    Preconditions.checkState(instance != null, "instance is null, is the plugin enabled?");
    instance.unregisterVariables0(plugin);
}

From source file:org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.ObjectNameAttributeReadingStrategy.java

@Override
AttributeConfigElement readElementHook(List<XmlElement> configNodes) throws DocumentedException {

    XmlElement firstChild = configNodes.get(0);
    Preconditions.checkState(configNodes.size() == 1,
            "This element should be present only once " + firstChild + " but was " + configNodes.size());

    Preconditions.checkNotNull(firstChild, "Element %s should be present", firstChild);
    return AttributeConfigElement.create(getNullableDefault(), resolve(firstChild));
}

From source file:io.macgyver.core.web.BrowserControl.java

public static List<Instruction> getInstructionList() {

    MacGyverWebContext ctx = MacGyverWebContext.get();
    Preconditions.checkState(ctx != null, "MacGyverWebContext not bound to current thread");
    HttpServletRequest request = ctx.getServletRequest();
    Preconditions.checkState(request != null,
            "HttpServletRequest not bound to current thread via MacGyverWebContext");

    List<Instruction> list = (List<Instruction>) request.getAttribute(OPLIST_KEY);
    if (list == null) {
        list = Lists.newArrayList();/*from   w  ww. ja v a2  s .  c  om*/
        request.setAttribute(OPLIST_KEY, list);
    }

    return list;
}

From source file:com.google.gerrit.sshd.SingleCommandPluginModule.java

@Override
protected final void configure() {
    Preconditions.checkState(command != null, "@PluginName must be provided");
    configure(bind(Commands.key(command)));
}

From source file:com.blurengine.blur.framework.WorldModule.java

public WorldModule(ModuleManager moduleManager) {
    super(moduleManager);
    Preconditions.checkState(super.getSession() instanceof WorldBlurSession,
            "session is not WorldBlurSession.");
}

From source file:com.google.cloud.tools.eclipse.appengine.facets.NonSystemJobSuspender.java

/** Once called, it is imperative to call {@link resume()} later. */
public static void suspendFutureJobs() {
    synchronized (suspendedJobs) {
        Preconditions.checkState(!suspended.getAndSet(true), "Already suspended.");
        Job.getJobManager().addJobChangeListener(jobScheduleListener);
    }/*  w  ww  .j a va  2  s.  c o  m*/
}

From source file:org.locationtech.geogig.plumbing.TransactionBegin.java

/**
 * Creates a new transaction and returns it.
 * //  w w  w. j  a v a2  s .  c  o m
 * @return the {@link GeogigTransaction} that was created by the operation
 */
@Override
protected GeogigTransaction _call() {
    Preconditions.checkState(!(context instanceof GeogigTransaction),
            "Cannot start a new transaction within a transaction!");

    GeogigTransaction t = new GeogigTransaction(context, UUID.randomUUID());

    // Lock the repository
    try {
        refDatabase().lock();
    } catch (TimeoutException e) {
        Throwables.propagate(e);
    }
    try {
        // Copy original refs
        t.create();
    } finally {
        // Unlock the repository
        refDatabase().unlock();
    }
    // Return the transaction
    return t;
}

From source file:org.geogit.api.plumbing.TransactionBegin.java

/**
 * Creates a new transaction and returns it.
 * /*  w w w .j a va2 s.com*/
 * @return the {@link GeogitTransaction} that was created by the operation
 */
@Override
public GeogitTransaction call() {
    Preconditions.checkState(!(commandLocator instanceof GeogitTransaction),
            "Cannot start a new transaction within a transaction!");

    GeogitTransaction t = new GeogitTransaction(commandLocator, repository, UUID.randomUUID());

    // Lock the repository
    try {
        getRefDatabase().lock();
    } catch (TimeoutException e) {
        Throwables.propagate(e);
    }
    try {
        // Copy original refs
        t.create();
    } finally {
        // Unlock the repository
        getRefDatabase().unlock();
    }
    // Return the transaction
    return t;
}