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 String errorMessageTemplate,
        @Nullable Object... errorMessageArgs) 

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:org.geogig.commands.pr.PRCloseOp.java

protected @Override PRStatus _call() {
    PRStatus status = command(PRHealthCheckOp.class).setId(id).call();
    Preconditions.checkState(!status.isMerged(), "Pull request %s is already merged, can't be closed", id);
    if (status.isClosed()) {
        return status;
    }//from  w  ww .  j a v a  2s.c  o m

    PR pr = status.getRequest();
    Context liveContext = context();
    GeogigTransaction tx = pr.getTransaction(liveContext);
    Ref headRef = pr.resolveHeadRef(tx);
    Ref origRef = pr.resolveOriginRef(tx);
    tx.abort();
    setRef(liveContext, headRef);
    setRef(liveContext, origRef);
    return command(PRHealthCheckOp.class).setRequest(pr).call();
}

From source file:com.google.errorprone.bugpatterns.PreconditionsInvalidPlaceholderNegativeCase1.java

public void checkFoo() {
    Preconditions.checkState(foo.intValue() == 0, "foo must be equal to 0 but was %s", foo);
}

From source file:com.google.errorprone.bugpatterns.PreconditionsTooManyArgsPositiveCase1.java

public void checkFoo() {
    //BUG: Suggestion includes "foo must be equal to 0 but was %s"
    Preconditions.checkState(foo == 0, "foo must be equal to 0 but was {0}", foo);
}

From source file:fr.xebia.workshop.continuousdelivery.TeamInfrastructure.java

/**
 * The Jenkins server url (e.g. http://my-ec2-server:8080/) or
 * <code>null</code> if the given ec2 instance is <code>null</code>.
 *
 * @throws IllegalStateException if the given jenkins instance is not initialized and has a
 *                               <code>null</code> 'publicDnsName'.
 *//*from   ww w  .ja v  a2s  . c o  m*/
@Nullable
public static String getJenkinsUrl(@Nullable Instance jenkins) throws IllegalStateException {
    if (jenkins == null) {
        return null;
    }
    Preconditions.checkState(jenkins.getPublicDnsName() != null && !jenkins.getPublicDnsName().isEmpty(),
            "Given jenkins is not yet initialized, it publicDnsName is null: %s", jenkins);
    return "http://" + jenkins.getPublicDnsName() + ":8080/";
}

From source file:com.google.errorprone.bugpatterns.PreconditionsInvalidPlaceholderPositiveCase1.java

public void checkFoo() {
    // BUG: Diagnostic contains: foo must be equal to 0 but was %s
    Preconditions.checkState(foo == 0, "foo must be equal to 0 but was {0}", foo);
}

From source file:org.opendaylight.mdsal.binding.dom.adapter.AdapterBuilder.java

private void checkAllRequiredServices() {
    for (final Class<? extends D> type : getRequiredDelegates()) {
        Preconditions.checkState(delegates.get(type) != null, "Requires service %s is not defined.", type);
    }/* w  w w  . j a  v a  2 s.com*/
}

From source file:de.cosmocode.palava.scope.AbstractUnitOfWorkScope.java

/**
 * Checks that this scope is currently in progress.
 *
 * @since 2.0//from ww  w .j a  v a  2s.c o  m
 * @throws IllegalStateException if this scope is not active
 */
protected final void checkActive() {
    Preconditions.checkState(isActive(), "No %s block in progress", this);
}

From source file:org.opendaylight.controller.config.facade.xml.rpc.ModuleRpcs.java

public void addNameMapping(RuntimeBeanEntry runtimeEntry) {
    String yangName = runtimeEntry.getYangName();
    Preconditions.checkState(!yangToJavaNames.containsKey(yangName),
            "RuntimeBean %s found twice in same namespace", yangName);
    yangToJavaNames.put(yangName, runtimeEntry.getJavaNamePrefix());
}

From source file:com.facebook.buck.rules.AbstractArchiveMemberSourcePath.java

@Value.Check
public void check() {
    Preconditions.checkState(!getMemberPath().isAbsolute(),
            "ArchiveMemberSourcePath must not be absolute but was %s", getMemberPath());
}

From source file:org.b1.pack.cli.FsWriterVolume.java

@Override
public OutputStream getOutputStream() throws IOException {
    System.out.println();/*w  w  w.  java 2  s  .co  m*/
    System.out.println("Creating volume " + file);
    System.out.println();
    Preconditions.checkState(!file.exists(), "File already exists: %s", file);
    Preconditions.checkState(tempFile == null);
    tempFile = FileTools.createTempFile(file);
    return new FileOutputStream(tempFile);
}