Example usage for com.google.common.base Preconditions checkArgument

List of usage examples for com.google.common.base Preconditions checkArgument

Introduction

In this page you can find the example usage for com.google.common.base Preconditions checkArgument.

Prototype

public static void checkArgument(boolean expression, @Nullable Object errorMessage) 

Source Link

Document

Ensures the truth of an expression involving one or more parameters to the calling method.

Usage

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

public static Optional<UserRating> tryGetByCode(ObjectContext context, String code) {
    Preconditions.checkArgument(null != context, "the context must be supplied");
    Preconditions.checkArgument(!Strings.isNullOrEmpty(code), "the code must be supplied");
    return Optional.ofNullable(ObjectSelect.query(UserRating.class).where(CODE.eq(code)).selectOne(context));
}

From source file:com.palantir.docker.compose.connection.State.java

public static State parseFromDockerComposePs(String psOutput) {
    Preconditions.checkArgument(!Strings.isNullOrEmpty(psOutput), "No container found");
    Matcher matcher = STATE_PATTERN.matcher(psOutput);
    Preconditions.checkState(matcher.find(), "Could not parse status: %s", psOutput);
    String matchedStatus = matcher.group(STATE_INDEX);
    return valueOf(matchedStatus);
}

From source file:io.pravega.controller.store.host.HostStoreFactory.java

public static HostControllerStore createStore(final HostMonitorConfig hostMonitorConfig,
        final StoreClient storeClient) {

    Preconditions.checkNotNull(hostMonitorConfig, "hostMonitorConfig");
    Preconditions.checkNotNull(storeClient, "storeClient");

    if (hostMonitorConfig.isHostMonitorEnabled()) {
        Preconditions.checkArgument(storeClient.getType() == StoreType.Zookeeper,
                "If host monitor is enabled then the store type should be Zookeeper");
        log.info("Creating Zookeeper based host store");
        return new ZKHostStore((CuratorFramework) storeClient.getClient(),
                hostMonitorConfig.getContainerCount());
    } else {//  ww w.j  a  va2s . c  o  m
        // We create an in-memory host store using the configuration passed in hostMonitorConfig.
        log.info("Creating in-memory host store");
        return createInMemoryStore(hostMonitorConfig);
    }
}

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

public static Optional<PkgCategory> getByCode(ObjectContext context, final String code) {
    Preconditions.checkArgument(null != context, "the context must be provided");
    Preconditions.checkArgument(!Strings.isNullOrEmpty(code), "the code must be supplied");
    return getAll(context).stream().filter(pc -> pc.getCode().equals(code)).collect(SingleCollector.optional());
}

From source file:org.terasology.commonworld.geom.Point2d.java

/**
 * @param a the first point/*from  www .ja va  2s .  co m*/
 * @param b the second point
 * @param ipol the interpolation value in the range [0..1]
 * @return the interpolated point
 */
public static Point2md ipol(Point2d a, Point2d b, double ipol) {
    Preconditions.checkArgument(ipol >= 0 && ipol <= 1, "ipol must be in [0..1]");

    double x = a.getX() * (1.0 - ipol) + b.getX() * ipol;
    double y = a.getY() * (1.0 - ipol) + b.getY() * ipol;
    return new Point2md(x, y);
}

From source file:app.philm.in.fragments.MovieCastListFragment.java

public static MovieCastListFragment create(String movieId) {
    Preconditions.checkArgument(!TextUtils.isEmpty(movieId), "movieId cannot be empty");

    Bundle bundle = new Bundle();
    bundle.putString(KEY_QUERY_MOVIE_ID, movieId);

    MovieCastListFragment fragment = new MovieCastListFragment();
    fragment.setArguments(bundle);/*  w w  w.  java  2  s  .  c  om*/

    return fragment;
}

From source file:app.philm.in.fragments.MovieCrewListFragment.java

public static MovieCrewListFragment create(String movieId) {
    Preconditions.checkArgument(!TextUtils.isEmpty(movieId), "movieId cannot be empty");

    Bundle bundle = new Bundle();
    bundle.putString(KEY_QUERY_MOVIE_ID, movieId);

    MovieCrewListFragment fragment = new MovieCrewListFragment();
    fragment.setArguments(bundle);//from   w w  w.j  a v  a 2  s  .c  om

    return fragment;
}

From source file:aritzh.waywia.util.RenderUtil.java

public static Image getImage(String filename) {
    Preconditions.checkArgument(!Strings.isNullOrEmpty(filename), "Image file name must not be null or empty!");
    if (!filename.endsWith(".png"))
        filename += ".png";
    filename = "img/" + filename;
    try {/*from  w  ww. j  a  va 2s  .  co  m*/
        return new Image(TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream(filename)));
    } catch (Exception e) {
        Game.logger.e("Could not load image " + filename, e);
    }
    return null;
}

From source file:io.pravega.common.MathHelpers.java

public static double minMax(double value, double min, double max) {
    Preconditions.checkArgument(min <= max, "min must be less than or equal to max");
    return Math.max(Math.min(value, max), min);
}

From source file:app.philm.in.fragments.PersonCastListFragment.java

public static PersonCastListFragment create(String personId) {
    Preconditions.checkArgument(!TextUtils.isEmpty(personId), "personId cannot be empty");

    Bundle bundle = new Bundle();
    bundle.putString(KEY_QUERY_PERSON_ID, personId);

    PersonCastListFragment fragment = new PersonCastListFragment();
    fragment.setArguments(bundle);//from   w  w  w . j av  a2 s. co m

    return fragment;
}