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:ezbake.thrift.authentication.EzX509.java

public void assertValidPeer(String msg, Object... msgArgs) {
    Preconditions.checkState(peerDn.isPresent(), msg, msgArgs);
}

From source file:com.facebook.swift.generator.TypeRegistry.java

public void add(final SwiftJavaType type) {
    Preconditions.checkState(!registry.containsKey(type.getKey()), "The type %s was already registered!", type);
    registry.put(type.getKey(), type);//from ww  w . j ava2s.  c  o  m
}

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

@Override
public void setContent(FileContent content) throws IOException {
    Preconditions.checkState(!targetFile.exists(), "File already exists: %s", targetFile);
    System.out.println("Extracting " + targetFile);
    File tempFile = FileTools.createTempFile(targetFile);
    FileOutputStream stream = new FileOutputStream(tempFile);
    try {//w w  w  . j  a  va 2  s. co m
        content.writeTo(stream, 0, null);
    } finally {
        stream.close();
    }
    Files.move(tempFile, targetFile);
}

From source file:com.facebook.swift.thrift.generator.TypeRegistry.java

public void add(final SwiftJavaType type) {
    Preconditions.checkState(!registry.containsKey(type.getKey()), "The type %s was already registered!", type);
    //        System.out.println("added "+type.toString());
    registry.put(type.getKey(), type);/*from  www . j  av  a2  s.  c om*/
}

From source file:harp.script.node.NodeContextBuilder.java

void addNode(NodeSpec nodeSpec) {
    Preconditions.checkNotNull(nodeSpec.getName(), "A NodeSpec must have a non-null name.");
    Preconditions.checkState(!nodeNames.contains(nodeSpec.getName()),
            "A NodeSpec named %s has already been declared.", nodeSpec.getName());
    nodeNames.add(nodeSpec.getName());//from w  ww  .java2s.  c  o  m
    nodes.add(nodeSpec);
}

From source file:org.janusgraph.graphdb.types.ParameterIndexField.java

public SchemaStatus getStatus() {
    SchemaStatus status = ParameterType.STATUS.findParameter(parameters, null);
    Preconditions.checkState(status != null, "Field [%s] did not have a status", this);
    return status;
}

From source file:org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.fromxml.CompositeAttributeReadingStrategy.java

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

    Preconditions.checkState(configNodes.size() == 1, "This element should be present only once %s",
            configNodes);/*  ww w .j  a  v  a  2 s  . c om*/

    XmlElement complexElement = configNodes.get(0);

    Map<String, Object> innerMap = Maps.newHashMap();

    List<XmlElement> recognisedChildren = Lists.newArrayList();
    for (Entry<String, AttributeReadingStrategy> innerAttrEntry : innerStrategies.entrySet()) {
        List<XmlElement> childItem = complexElement.getChildElementsWithSameNamespace(innerAttrEntry.getKey());
        recognisedChildren.addAll(childItem);

        AttributeConfigElement resolvedInner = innerAttrEntry.getValue().readElement(childItem);

        Object value = resolvedInner.getValue();
        if (value == null) {
            value = resolvedInner.getDefaultValue();
        }

        innerMap.put(innerAttrEntry.getKey(), value);
    }

    complexElement.checkUnrecognisedElements(recognisedChildren);

    return AttributeConfigElement.create(getNullableDefault(), innerMap);
}

From source file:com.lyndir.omicron.api.Module.java

protected Module(final ImmutableResourceCost resourceCost) {
    this.resourceCost = resourceCost;
    Preconditions.checkState(getType().getModuleType().isInstance(this), "Invalid module type for module: %s",
            this);
}

From source file:harp.script.root.RootContextBuilder.java

void addEnvironment(Environment environment) {
    Preconditions.checkNotNull(environment.getName(), "An Environment must have a non-null name.");
    Preconditions.checkState(!environmentNames.contains(environment.getName()),
            "An Environment named %s has already been declared.", environment.getName());
    environmentNames.add(environment.getName());
    environments.add(environment);/*from   w  ww  . j a v  a 2s . c o m*/
}

From source file:com.yahoo.yqlplus.engine.internal.compiler.LocalFrame.java

LocalValue allocate(String name, TypeWidget type) {
    Preconditions.checkState(!vars.containsKey(name), "variable name '%s' cannot already exist", name);
    int size = type.getJVMType().getSize();
    Preconditions.checkArgument(size > 0, "Do not allocate variables for void ('%s')", name);
    LocalValue result = new LocalValue(name, type, top);
    vars.put(name, result);/*from   w w w. j  a v  a 2s.com*/
    top += size;
    return result;
}