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:org.semtinel.core.shell.Parser.java

public ParseResult parse(String request) {
    shell.setStatus(ShellStatus.PARSING);
    String[] tokens = tokenize(request);

    Preconditions.checkNotNull(tokens, "error while parsing request!");
    Preconditions.checkState(tokens.length > 0);

    Map<String, String> options = Collections.emptyMap();

    if (hasOptions(tokens)) {
        options = extractOptionsFromParams(Arrays.copyOfRange(tokens, 1, tokens.length));
    }// w ww .  j  a va 2s .c  o m

    return new ParseResult(tokens[0], options);
}

From source file:org.opendaylight.controller.sal.connect.netconf.UncancellableFuture.java

@Override
public synchronized boolean set(@Nullable V value) {
    Preconditions.checkState(uncancellable == true);
    return super.set(value);
}

From source file:org.opendaylight.yangtools.binding.data.codec.impl.CaseNodeCodecContext.java

@Override
public D deserialize(final NormalizedNode<?, ?> normalizedNode) {
    Preconditions.checkState(normalizedNode instanceof ChoiceNode);
    return createBindingProxy((ChoiceNode) normalizedNode);
}

From source file:org.sonar.java.resolve.Convert.java

public static String innerClassName(String enclosingClassName, String shortName) {
    Preconditions.checkArgument(!enclosingClassName.isEmpty(),
            "Enclosing class name should not be empty : " + shortName);
    int indexEnclosing = shortName.indexOf(enclosingClassName);
    if (indexEnclosing == -1) {
        // short name does not contain enclosing class name, might happen when a library is obfuscated
        return shortName;
    }/*w w w .  j a  v  a2  s .c  o  m*/
    Preconditions
            .checkState(shortName.substring(indexEnclosing + enclosingClassName.length()).charAt(0) == '$');
    return shortName.substring(indexEnclosing + enclosingClassName.length() + 1);
}

From source file:com.alibaba.supersonic.base.infrastructure.TupleSchema.java

public static TupleSchema singleton(final String name, final DataType type, final Nullability nullability) {
    TupleSchema result = new TupleSchema();
    Attribute attribute = new Attribute(name, type, nullability);
    Preconditions.checkState(result.addAttribute(attribute));
    return result;
}

From source file:org.xacml4j.spring.pdp.RequestContextHandlerFactoryBean.java

@Override
protected RequestContextHandler createInstance() throws Exception {
    Preconditions.checkState(ref != null);
    return ref;
}

From source file:com.facebook.buck.jvm.java.abi.AnnotationDefaultValueMirror.java

@Override
public void visitEnum(String name, String desc, String value) {
    Preconditions.checkState(defaultValue == null);

    defaultValue = AnnotationValueMirror.forEnum(desc, value);
}

From source file:io.selendroid.MultiTouchAction.java

public void perform(WebDriver driver) {
    Preconditions.checkState(driver instanceof HasMultiTouchScreen);
    ((HasMultiTouchScreen) driver).getMultiTouchScreen().executeAction(this);
}

From source file:com.cloudera.impala.analysis.AlterViewStmt.java

@Override
public void analyze(Analyzer analyzer) throws AnalysisException {
    // Enforce Hive column labels for view compatibility.
    analyzer.setUseHiveColLabels(true);//from  w  w w.j ava 2 s.co  m
    viewDefStmt_.analyze(analyzer);

    Preconditions.checkState(tableName_ != null && !tableName_.isEmpty());
    dbName_ = analyzer.getTargetDbName(tableName_);
    owner_ = analyzer.getUser().getName();

    Table table = analyzer.getTable(tableName_, Privilege.ALTER);
    Preconditions.checkNotNull(table);
    if (!(table instanceof View)) {
        throw new AnalysisException(
                String.format("ALTER VIEW not allowed on a table: %s.%s", dbName_, getTbl()));
    }

    createColumnAndViewDefs(analyzer);
}

From source file:garmintools.adapters.garmin.LandingFacilityIdentifierIndexGarminAdapter.java

@Override
public Map<Byte, Integer> read(DataLengthSection dataLengthSection, TableOfContentsEntry entry,
        ByteBuffer byteBuffer) {/*  w ww  . ja  v  a  2  s .  c om*/
    Preconditions.checkState(entry.itemQuantity == NUM_ENTRIES);
    ImmutableMap.Builder<Byte, Integer> mapBuilder = ImmutableMap.builder();
    Preconditions.checkState(entry.itemLength == 3);
    for (int i = 0; i < entry.itemQuantity; ++i) {
        int offset = byteBuffer.getShort() & 0xffff;
        offset |= (byteBuffer.get() << 16);
        byte landingFacilityIdentifierPrefixByte = (byte) (i + 4);
        if (landingFacilityIdentifierPrefixByte <= NUM_ENTRIES && offset != NOT_PRESENT_INDEX_MARKER) {
            mapBuilder.put(landingFacilityIdentifierPrefixByte, offset);
        }
    }
    return mapBuilder.build();
}