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.facebook.buck.cli.LabelSelector.java

static LabelSelector fromString(String raw) {
    Preconditions.checkNotNull(raw);//www . j  a  v  a 2  s  .co m
    Preconditions.checkState(!raw.isEmpty());

    boolean isInclusive = true;
    if (raw.charAt(0) == '!') {
        isInclusive = false;
        raw = raw.substring(1);
    }

    ImmutableSet.Builder<Label> labelBuilder = new ImmutableSet.Builder<>();
    Iterable<String> labelStrings = splitter.split(raw);
    for (String labelString : labelStrings) {
        BuckConfig.validateLabelName(labelString);
        labelBuilder.add(new Label(labelString));
    }

    return new LabelSelector(isInclusive, labelBuilder.build());
}

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

public static TestCaseSummary parse(File xml) throws IOException {
    Document doc = XmlDomParser.parse(xml);
    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");
        boolean isSuccess = Boolean.valueOf(node.getAttribute("success"));
        long time = Long.valueOf(node.getAttribute("time"));

        String message;/*w w  w  .  j a va  2s. c  om*/
        String stacktrace;
        if (isSuccess) {
            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, isSuccess, time, message,
                stacktrace, stdOut, stdErr);
        testResults.add(testResult);
    }

    return new TestCaseSummary(testCaseName, testResults);
}

From source file:com.google.template.soy.jssrc.dsl.Composite.java

static Composite create(ImmutableList<CodeChunk> initialStatements, CodeChunk.WithValue value) {
    Preconditions.checkState(!initialStatements.isEmpty());
    return new AutoValue_Composite(ImmutableSet.<CodeChunk>builder().addAll(initialStatements)
            .addAll(value.initialStatements()).build(), initialStatements, value);
}

From source file:com.google.devtools.build.lib.skyframe.AbstractFileSymlinkExceptionUniquenessValue.java

protected static SkyKey key(SkyFunctionName functionName, ImmutableList<RootedPath> chain) {
    Preconditions.checkState(!chain.isEmpty());
    return new SkyKey(functionName, canonicalize(chain));
}

From source file:com.android.incallui.TelecomAdapter.java

static TelecomAdapter getInstance() {
    Preconditions.checkState(Looper.getMainLooper().getThread() == Thread.currentThread());
    if (sInstance == null) {
        sInstance = new TelecomAdapter();
    }//from   www.j a  va  2s. c o m
    return sInstance;
}

From source file:com.minlia.cloud.framework.common.util.SearchCommonUtil.java

public static List<Triple<String, ClientOperation, String>> parseQueryString(final String queryString) {
    Preconditions.checkNotNull(queryString);
    Preconditions.checkState(queryString.matches("((id~?=[0-9]+)?,?)*((name~?=[0-9a-zA-Z\\-_/*]+),?)*"));

    final List<Triple<String, ClientOperation, String>> tuplesList = Lists.newArrayList();
    final String[] tuples = queryString.split(QueryConstants.SEPARATOR);
    for (final String tuple : tuples) {
        final String[] keyAndValue = tuple.split(QueryConstants.OP);
        Preconditions.checkState(keyAndValue.length == 2);
        tuplesList.add(createConstraintFromUriParam(keyAndValue[0], keyAndValue[1]));
    }//www  . j  a v a2s  . c  o m

    return tuplesList;
}

From source file:org.haiku.haikudepotserver.dataobjects.Country.java

public static Optional<Country> tryGetByCode(ObjectContext context, final String code) {
    Preconditions.checkNotNull(context, "the context must be provided");
    Preconditions.checkState(!Strings.isNullOrEmpty(code));
    return getAll(context).stream().filter(a -> a.getCode().equals(code)).collect(SingleCollector.optional());
}

From source file:com.htc.vzwsipservice.incallui.TelecomAdapter.java

public static TelecomAdapter getInstance() {
    Preconditions.checkState(Looper.getMainLooper().getThread() == Thread.currentThread());
    if (sInstance == null) {
        sInstance = new TelecomAdapter();
    }//from   ww  w.  ja  v a  2 s .  c  om
    return sInstance;
}

From source file:de.javakaffee.sandbox.getfj.ConversionDemo.java

static void assertEquals(Object one, Object another) {
    Preconditions.checkState(one == null ? another == null : another != null);
    Preconditions.checkState(one.equals(another));
}

From source file:com.google.devtools.build.lib.skyframe.FileSymlinkCycleUniquenessValue.java

static SkyKey key(ImmutableList<RootedPath> cycle) {
    Preconditions.checkState(!cycle.isEmpty());
    return new SkyKey(SkyFunctions.FILE_SYMLINK_CYCLE_UNIQUENESS, canonicalize(cycle));
}