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) 

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.torodb.core.cursors.EmptyCursor.java

@Override
public boolean hasNext() {
    Preconditions.checkState(!closed);
    return false;
}

From source file:com.palantir.atlasdb.keyvalue.partition.status.BackfillableEndpointWithStatus.java

public void setBackfilled() {
    Preconditions.checkState(!backfilled);
    backfilled = true;
}

From source file:dagger.internal.codegen.DaggerStatistics.java

void processingStarted() {
    Preconditions.checkState(!totalRuntimeStopwatch.isRunning());
    totalRuntimeStopwatch.start();
}

From source file:pl.setblack.airomem.core.builders.PersistenceFactory.java

/**
 * Init previously stored system./*w  ww  .j  a va2  s .  c  om*/
 *
 * @param <T> Mutable interface of system
 * @param <R> Immutable view of system
 * @param name name of automatically created folder (to store jounal and
 * snapshots)
 * @return PersistenceControllerImpl for later use
 */
public <T extends Storable<R>, R> PersistenceController<T, R> load(String name) {
    Preconditions.checkState(exists(name));

    PrevaylerBuilder<T, R> builder = PrevaylerBuilder.newBuilder().withFolder(name);
    return builder.build();
}

From source file:com.heartbleed.tls.records.HeartbeatResponseMessage.java

public boolean responseContainsByteSequence(byte[] sequence) {
    Preconditions.checkState(recordBytes[5] == 0x02);
    ByteBuffer buffer = ByteBuffer.wrap(recordBytes);
    buffer.position(6);/*from   w w  w.j  ava  2 s.co m*/
    short payloadLength = buffer.getShort();

    for (int i = 0; i < payloadLength - sequence.length; i++) {
        int j;
        for (j = 0; j < sequence.length; j++) {
            if (recordBytes[8 + i + j] != sequence[j]) {
                break;
            }
        }
        if (j == sequence.length) {
            return true;
        }
    }
    return false;
}

From source file:org.opendaylight.protocol.bgp.rib.spi.AbstractRIBExtensionProviderActivator.java

@Override
public final synchronized void startRIBExtensionProvider(final RIBExtensionProviderContext context) {
    Preconditions.checkState(this.registrations == null);

    this.registrations = Preconditions.checkNotNull(startRIBExtensionProviderImpl(context));
}

From source file:com.facebook.buck.test.XmlTestResultParser.java

private static TestCaseSummary doParse(String xml) throws IOException {
    Document doc = XmlDomParser.parse(new InputSource(new StringReader(xml)), /* namespaceAware */ true);
    Element root = doc.getDocumentElement();
    Preconditions.checkState("testcase".equals(root.getTagName()));
    String testCaseName = root.getAttribute("name");

    NodeList testElements = doc.getElementsByTagName("test");
    List<TestResultSummary> testResults = Lists.newArrayListWithCapacity(testElements.getLength());
    for (int i = 0; i < testElements.getLength(); i++) {
        Element node = (Element) testElements.item(i);
        String testName = node.getAttribute("name");
        long time = Long.parseLong(node.getAttribute("time"));
        String typeString = node.getAttribute("type");
        ResultType type = ResultType.valueOf(typeString);

        String message;/* w w  w  .  ja va2  s. c  o  m*/
        String stacktrace;
        if (type == ResultType.SUCCESS) {
            message = null;
            stacktrace = null;
        } else {
            message = node.getAttribute("message");
            stacktrace = node.getAttribute("stacktrace");
        }

        NodeList stdoutElements = node.getElementsByTagName("stdout");
        String stdOut;
        if (stdoutElements.getLength() == 1) {
            stdOut = stdoutElements.item(0).getTextContent();
        } else {
            stdOut = null;
        }

        NodeList stderrElements = node.getElementsByTagName("stderr");
        String stdErr;
        if (stderrElements.getLength() == 1) {
            stdErr = stderrElements.item(0).getTextContent();
        } else {
            stdErr = null;
        }

        TestResultSummary testResult = new TestResultSummary(testCaseName, testName, type, time, message,
                stacktrace, stdOut, stdErr);
        testResults.add(testResult);
    }

    return new TestCaseSummary(testCaseName, testResults);
}

From source file:com.google.javascript.jscomp.fuzzing.Scope.java

String randomLabelForContinue(Random random) {
    Preconditions.checkState(!loopLabels.isEmpty());
    return loopLabels.get(random.nextInt(loopLabels.size()));
}

From source file:org.haiku.pkg.output.AttributeWriter.java

private void write(int indent, AttributeContext context, Attribute attribute) throws IOException {
    Preconditions.checkNotNull(context);
    Preconditions.checkNotNull(attribute);
    Preconditions.checkState(indent >= 0);

    for (int i = 0; i < indent; i++) {
        write(' ');
    }/*from  www  .  j  av a2  s .c  o  m*/

    write(attribute.getAttributeId().getName());
    write(" : ");
    write(attribute.getAttributeType().name());
    write(" : ");

    try {
        switch (attribute.getAttributeType()) {

        case RAW:
            byte[] data = (byte[]) attribute.getValue(context);
            write(String.format("%d bytes", data.length));
            break;

        case INT:
            write(attribute.getValue(context).toString());
            break;

        case STRING:
            write(attribute.getValue(context).toString());
            break;

        default:
            write("???");
            break;

        }
    } catch (HpkException e) {
        throw new IOException("unable to process an attribute '" + attribute.toString() + "'", e);
    }

    write("\n");

    if (attribute.hasChildAttributes()) {
        for (Attribute childAttribute : attribute.getChildAttributes()) {
            write(indent + 2, context, childAttribute);
        }
    }
}

From source file:org.opendaylight.netconf.sal.rest.doc.impl.ApiDocGenerator.java

public ResourceList getResourceListing(UriInfo uriInfo) {
    Preconditions.checkState(schemaService != null);
    SchemaContext schemaContext = schemaService.getGlobalContext();
    Preconditions.checkState(schemaContext != null);
    return super.getResourceListing(uriInfo, schemaContext, "");
}