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.haiku.haikudepotserver.dataobjects.Architecture.java

public static Optional<Architecture> 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:org.geogit.api.plumbing.CommitFromDateOp.java

@Override
public Optional<RevCommit> call() {
    Preconditions.checkState(date != null);
    long time = date.getTime();
    Iterator<RevCommit> iter = command(LogOp.class).setFirstParentOnly(true).call();
    while (iter.hasNext()) {
        RevCommit commit = iter.next();//w  w w .j a  v a2 s. co m
        if (commit.getCommitter().getTimestamp() < time) {
            return Optional.of(commit);
        }
    }
    return Optional.absent();
}

From source file:com.cloudera.impala.common.FileSystemUtil.java

/**
 * Performs a non-recursive delete of all visible (non-hidden) files in a given
 * directory. Returns the number of files deleted as part of this operation.
 *//* ww  w. j a v  a2 s .  c o  m*/
public static int deleteAllVisibleFiles(Path directory) throws IOException {
    FileSystem fs = directory.getFileSystem(CONF);
    Preconditions.checkState(fs.getFileStatus(directory).isDirectory());
    int numFilesDeleted = 0;
    for (FileStatus fStatus : fs.listStatus(directory)) {
        // Only delete files that are not hidden.
        if (fStatus.isFile() && !isHiddenFile(fStatus.getPath().getName())) {
            LOG.debug("Removing: " + fStatus.getPath());
            fs.delete(fStatus.getPath(), false);
            ++numFilesDeleted;
        }
    }
    return numFilesDeleted;
}

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

protected AlertRecord(byte[] recordBytes) {
    super(recordBytes);
    Preconditions.checkState(getContentType() == ContentType.ALERT);
}

From source file:com.cloudera.oryx.app.kmeans.KMeansUtils.java

/**
 * @param clusters all clusters/*from  w ww  .j  a  va 2  s .  c  om*/
 * @param distanceFn distance function between clusters
 * @param vector point to measure distance to
 * @return cluster whose center is closest to the given point
 */
public static Pair<ClusterInfo, Double> closestCluster(List<ClusterInfo> clusters,
        DistanceFn<double[]> distanceFn, double[] vector) {
    Preconditions.checkArgument(!clusters.isEmpty());
    double closestDist = Double.POSITIVE_INFINITY;
    ClusterInfo minCluster = null;
    for (ClusterInfo cluster : clusters) {
        double distance = distanceFn.applyAsDouble(cluster.getCenter(), vector);
        if (distance < closestDist) {
            closestDist = distance;
            minCluster = cluster;
        }
    }
    Preconditions.checkNotNull(minCluster);
    Preconditions.checkState(!Double.isInfinite(closestDist) && !Double.isNaN(closestDist));
    return new Pair<>(minCluster, closestDist);
}

From source file:model.utilities.stats.collectors.ConsumptionData.java

@Override
public void step(SimState state) {
    Preconditions.checkState(plant != null);
    if (!active)/*from   w  ww.  j a  va 2s  .c  o  m*/
        return;

    //make sure it's the right time
    assert state instanceof MacroII;
    MacroII model = (MacroII) state;
    assert model.getCurrentPhase().equals(ActionOrder.CLEANUP_DATA_GATHERING);
    //set starting day if needed
    if (getStartingDay() == -1)
        setCorrectStartingDate(model);
    assert getStartingDay() >= 0;

    //memorize
    //grab the production vector

    final Set<GoodType> sectorList = model.getGoodTypeMasterList().getListOfAllSectors();
    for (GoodType type : sectorList) //record all consumption
    {
        if (data.get(type) == null) //this can happen if a new good sector has been created
            fillNewSectorObservationsWith0(model, type);

        data.get(type).add((double) plant.getConsumedToday(type));
    }
    //reschedule
    model.scheduleTomorrow(ActionOrder.CLEANUP_DATA_GATHERING, this);

}

From source file:org.opendaylight.controller.config.facade.xml.mapping.IdentityMapping.java

public void addIdSchemaNode(IdentitySchemaNode node) {
    String name = node.getQName().getLocalName();
    Preconditions.checkState(!identityNameToSchemaNode.containsKey(name));
    identityNameToSchemaNode.put(name, node);
}

From source file:net.techcable.pineapple.LazyPreconditions.java

public static void checkState(boolean expression) {
    Preconditions.checkState(expression);
}

From source file:com.yahoo.yqlplus.engine.internal.plan.JoinExpression.java

public String getRightField() {
    Preconditions.checkState(right.getOperator() == ExpressionOperator.READ_FIELD);
    return right.getArgument(1);
}

From source file:com.facebook.buck.parser.cache.impl.ParserCacheStorageFactory.java

private static ParserCacheStorage createRemoteManifestParserStorage(AbstractParserCacheConfig parserCacheConfig,
        ThrowingCloseableMemoizedSupplier<ManifestService, IOException> manifestServiceSupplier) {
    Preconditions.checkState(parserCacheConfig.isRemoteParserCacheEnabled());
    return RemoteManifestServiceCacheStorage.of(manifestServiceSupplier.get(), parserCacheConfig);
}