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.opendaylight.protocol.bmp.spi.registry.AbstractBmpExtensionProviderActivator.java

@Override
public final synchronized void stop() {
    Preconditions.checkState(this.registrations != null);

    for (final AutoCloseable r : this.registrations) {
        try {/*www.  j  a  va 2 s  .c o  m*/
            r.close();
        } catch (final Exception e) {
            LOG.warn("Failed to close registration", e);
        }
    }

    this.registrations = null;
}

From source file:com.twitter.common.stats.PrintableHistogram.java

/**
 * Creates a histogram with the given bucket boundaries.  The boundaries
 * 0 and infinity are implicitly added.//from www  .j av  a2s . co m
 *
 * @param buckets Boundaries for histogram buckets.
 */
public PrintableHistogram(double... buckets) {
    Preconditions.checkState(buckets[0] != 0);

    bucketBoundaries = new double[buckets.length + 2];
    bucketBoundaries[0] = 0;
    bucketCounts = new int[buckets.length + 2];
    for (int i = 0; i < buckets.length; i++) {
        if (i > 0) {
            Preconditions.checkState(buckets[i] > buckets[i - 1], "Bucket %f must be greater than %f.",
                    buckets[i], buckets[i - 1]);
        }
        bucketCounts[i] = 0;
        bucketBoundaries[i + 1] = buckets[i];
    }

    bucketBoundaries[bucketBoundaries.length - 1] = Integer.MAX_VALUE;
}

From source file:org.obm.imap.archive.logging.LoggerAppenders.java

public static LoggerAppenders from(ArchiveTreatmentRunId runId, Logger logger) {
    String baseAppenderName = runId.serialize();

    Appender<ILoggingEvent> fileAppender = logger.getAppender(baseAppenderName);
    Preconditions.checkState(fileAppender != null);
    ChunkedOutputAppender chunkedOutputAppender = (ChunkedOutputAppender) logger
            .getAppender(LoggerFactory.CHUNK_APPENDER_PREFIX + baseAppenderName);
    Preconditions.checkState(chunkedOutputAppender != null);

    return new LoggerAppenders(logger, fileAppender, chunkedOutputAppender);
}

From source file:com.facebook.buck.util.cache.impl.DefaultJarContentHasher.java

public DefaultJarContentHasher(ProjectFilesystem filesystem, Path jarRelativePath) {
    Preconditions.checkState(!jarRelativePath.isAbsolute());
    this.filesystem = filesystem;
    this.jarRelativePath = jarRelativePath;
}

From source file:org.waveprotocol.wave.client.wavepanel.view.fake.FakeAnchor.java

void setContainer(FakeBlipView container) {
    Preconditions.checkState(blip == null && meta == null);
    this.blip = container;
}

From source file:org.apache.tajo.catalog.json.TableDescAdapter.java

@Override
public TableDesc deserialize(JsonElement json, Type type, JsonDeserializationContext ctx)
        throws JsonParseException {
    JsonObject jsonObject = json.getAsJsonObject();
    String typeName = jsonObject.get("type").getAsJsonPrimitive().getAsString();
    Preconditions.checkState(typeName.equals("TableDesc"));
    return ctx.deserialize(jsonObject.get("body"), TableDescImpl.class);
}

From source file:org.apache.ratis.server.impl.PeerConfiguration.java

PeerConfiguration(Iterable<RaftPeer> peers) {
    Preconditions.checkNotNull(peers);/*from  w  w  w  . j  av a 2 s  .  c o m*/
    Map<String, RaftPeer> map = new HashMap<>();
    for (RaftPeer p : peers) {
        map.put(p.getId(), p);
    }
    this.peers = Collections.unmodifiableMap(map);
    Preconditions.checkState(!this.peers.isEmpty());
}

From source file:com.linkedin.pinot.core.plan.DocIdSetPlanNode.java

public DocIdSetPlanNode(@Nonnull IndexSegment indexSegment, @Nonnull BrokerRequest brokerRequest,
        int maxDocPerCall) {
    Preconditions.checkState(maxDocPerCall <= MAX_DOC_PER_CALL);
    _indexSegment = indexSegment;/*from   w w w .  j a  v a  2s . c om*/
    _filterPlanNode = new FilterPlanNode(_indexSegment, brokerRequest);
    _maxDocPerCall = maxDocPerCall;
}

From source file:garmintools.sections.IcaoRegionSection.java

public IndexForeignKey lookupByRegion(Proto.IcaoRegion region) {
    int index = data.indexOf(region);
    Preconditions.checkState(index != -1);
    return new IndexForeignKey(index);
}

From source file:org.sosy_lab.java_smt.solvers.z3.Z3AbstractProver.java

@Override
public Z3Model getModel() {
    Preconditions.checkState(!closed);
    return Z3Model.create(z3context, getZ3Model(), creator);
}