List of usage examples for com.google.common.base Preconditions checkArgument
public static void checkArgument(boolean expression, @Nullable Object errorMessage)
From source file:com.github.fommil.ff.Direction.java
/** * @param angle {@code [-PI, PI]} with 0 being NORTH. * @return/*from www . jav a2s . c o m*/ */ public static Direction valueOf(double angle) { if (Double.isNaN(angle)) return null; Preconditions.checkArgument(angle <= Math.PI && angle >= -Math.PI, angle); angle = angle - Math.PI / 8; // tolerance if (angle <= -Math.PI) { return SOUTH; } else if (angle <= -3 * Math.PI / 4) { return SOUTH_WEST; } else if (angle <= -Math.PI / 2) { return WEST; } else if (angle <= -Math.PI / 4) { return NORTH_WEST; } else if (angle <= 0) { return NORTH; } else if (angle <= Math.PI / 4) { return NORTH_EAST; } else if (angle <= Math.PI / 2) { return EAST; } else if (angle <= 3 * Math.PI / 4) { return SOUTH_EAST; } else { return SOUTH; } }
From source file:com.github.hilcode.versionator.misc.Either.java
public static final <T, L, R> Either<L, R> asRight(final Either<T, R> either) { Preconditions.checkArgument(either.isRight(), "Invalid cast, this Either represents a Left."); @SuppressWarnings("unchecked") final Either<L, R> either_ = (Either<L, R>) either; return either_; }
From source file:de.jackwhite20.cobra.client.CobraClientFactory.java
public static CobraClient create(String baseUrl) { Preconditions.checkArgument(baseUrl != null, "baseUrl cannot be null"); Preconditions.checkArgument(!baseUrl.isEmpty(), "baseUrl cannot be empty"); return new CobraClientImpl(baseUrl); }
From source file:com.cloudera.nav.sdk.model.HiveIdGenerator.java
public static String generateColumnId(String sourceId, String databaseName, String tableName, String columnName) {// ww w . j a v a 2 s. co m Preconditions.checkArgument( !StringUtils.isEmpty(sourceId) && !StringUtils.isEmpty(databaseName) && !StringUtils.isEmpty(tableName) && !StringUtils.isEmpty(columnName), "SourceId, database name, table name, and column name must be " + "supplied to generate Hive column identity"); return MD5IdGenerator.generateIdentity(sourceId, databaseName.toUpperCase(), tableName.toUpperCase(), columnName.toUpperCase()); }
From source file:com.github.hilcode.versionator.Result.java
public static final <ANY, F, S> Result<F, S> asFailure(final Result<F, ANY> result) { Preconditions.checkArgument(result.isFailure(), "Invalid cast, this Result represents a Success."); @SuppressWarnings("unchecked") final Result<F, S> result_ = (Result<F, S>) result; return result_; }
From source file:org.terasology.cities.noise.Wave.java
/** * Creates a function that looks like this: * <pre>//w w w . j a v a 2 s . co m * /\ /\ * / \ / \ * / \/ \ * </pre> * @param waveLength the width of one hat * @param multipliers the heights of the hats * @return an univariate function */ public static Wave getHat(final double waveLength, final double[] multipliers) { return new Wave() { public double get(double v) { Preconditions.checkArgument(v >= 0 && v <= 1, "Value must be in range [0..1]"); double hpos = getWaveletPos(waveLength, v); int suppIdx = getIndex(v, waveLength); return multipliers[suppIdx] * hpos; } }; }
From source file:org.kitesdk.data.spi.predicates.RegisteredPredicate.java
public static void register(String name, Factory factory) { Preconditions.checkArgument(NAME.matcher(name).matches(), "Invalid name, must be alphanumeric (plus _): " + name); REGISTRY.put(name, factory);/* www . j a v a 2s.co m*/ }
From source file:org.adridadou.ethereum.values.EthAddress.java
private EthAddress(byte[] address) { Preconditions.checkArgument(address.length <= 32, "byte array of the address cannot be bigger than 32.value:" + Hex.toHexString(address)); this.address = address; }
From source file:ch.ge.ve.commons.crypto.utils.SaltUtils.java
/** * Generates a salt using Java SecureRandom * * @param lengthInBits desired length of the salt * @return the salt//from www.j a va2 s . c o m */ public static byte[] generateSalt(int lengthInBits) { Preconditions.checkArgument(lengthInBits % 8 == 0, String.format("The salt length must be a multiple of 8, but was %d!", lengthInBits)); byte[] salt = new byte[lengthInBits / 8]; SECURE_RANDOM.nextBytes(salt); return salt; }
From source file:org.haiku.haikudepotserver.dataobjects.PkgVersionLocalization.java
public static Optional<PkgVersionLocalization> getForPkgVersionAndNaturalLanguageCode(ObjectContext context, PkgVersion pkgVersion, final String naturalLanguageCode) { Preconditions.checkArgument(null != context, "the context must be supplied"); Preconditions.checkArgument(null != pkgVersion, "the pkg version must be supplied"); Preconditions.checkArgument(!Strings.isNullOrEmpty(naturalLanguageCode), "the natural language code is required"); return getForPkgVersion(context, pkgVersion).stream() .filter(pvl -> pvl.getNaturalLanguage().getCode().equals(naturalLanguageCode)) .collect(SingleCollector.optional()); }