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.Prominence.java

public static Optional<Prominence> getByOrdering(ObjectContext context, Integer ordering) {
    Preconditions.checkArgument(null != context, "the context must be supplied");
    Preconditions.checkState(null != ordering && ordering >= 0, "bad ordering");
    return getAll(context).stream().filter((p) -> p.getOrdering().equals(ordering)).findFirst();
}

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

public static List<Permission> getAll(ObjectContext context) {
    Preconditions.checkArgument(null != context, "the context must be provided");
    return ObjectSelect.query(Permission.class).orderBy(NAME.asc()).sharedCache().select(context);
}

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

public static List<Country> getAll(ObjectContext context) {
    Preconditions.checkArgument(null != context, "the context must be provided");
    return ObjectSelect.query(Country.class).orderBy(Country.NAME.asc())
            .cacheStrategy(QueryCacheStrategy.SHARED_CACHE).select(context);
}

From source file:garmintools.util.StringUtil.java

public static String pad(String text, int length) {
    Preconditions.checkArgument(text.length() <= length,
            String.format("Text [%s] exceeds max length %d", text, length));
    for (int i = text.length(); i < length; ++i) {
        text += " ";
    }//w  w  w.  j av a2s . c  o m
    return text;
}

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

public static List<PkgCategory> getAll(ObjectContext context) {
    Preconditions.checkArgument(null != context, "the context must be provided");
    return ObjectSelect.query(PkgCategory.class).sharedCache().orderBy(NAME.asc()).select(context);
}

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

public static Optional<PermissionUserPkg> getByPermissionUserAndPkg(ObjectContext context,
        Permission permission, User user, Pkg pkg) {
    Preconditions.checkArgument(null != context, "the context must be provided");
    Preconditions.checkArgument(null != permission, "the context must be provided");
    Preconditions.checkArgument(null != user, "the user must be provided");

    return Optional.ofNullable(ObjectSelect.query(PermissionUserPkg.class).where(PERMISSION.eq(permission))
            .and(USER.eq(user)).and(PKG.eq(pkg)).selectOne(context));
}

From source file:org.opendaylight.controller.config.yangjmxgenerator.plugin.util.YangModelSearchUtils.java

public static Map<String, Module> mapModulesByNames(Collection<Module> modules) {
    Map<String, Module> result = new HashMap<>();
    for (Module m : modules) {
        String moduleName = m.getName();
        Preconditions.checkArgument(result.containsKey(moduleName) == false,
                "Two modules have same name " + moduleName);
        result.put(moduleName, m);//from  w  w w  . jav a 2  s.  c om
    }
    return result;
}

From source file:com.cloudera.nav.plugin.model.HdfsIdGenerator.java

public static String generateHdfsEntityId(String sourceId, String fileSystemPath) {
    Preconditions.checkArgument(!StringUtils.isEmpty(sourceId) && !StringUtils.isEmpty(fileSystemPath),
            "SourceId and fileSystemPath " + "must be supplied to generate HDFS entity identity");
    return MD5IdGenerator.generateIdentity(sourceId, fileSystemPath);
}

From source file:com.turn.splicer.tsdbutils.TsQuerySerializer.java

public static TsQuery deserializeFromJson(String jsonContent) {
    Preconditions.checkNotNull(jsonContent);
    Preconditions.checkArgument(!jsonContent.isEmpty(), "Incoming data was null or empty");

    return JSON.parseToObject(jsonContent, TsQuery.class);
}

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

private static List<PkgVersionLocalization> getForPkgVersion(ObjectContext context, PkgVersion pkgVersion) {
    Preconditions.checkArgument(null != context, "the context must be supplied");
    Preconditions.checkArgument(null != pkgVersion, "the pkg version must be supplied");
    return ObjectSelect.query(PkgVersionLocalization.class).where(PKG_VERSION.eq(pkgVersion)).sharedCache()
            .cacheGroup(HaikuDepot.CacheGroup.PKG_VERSION_LOCALIZATION.name()).select(context);
}