List of usage examples for com.google.common.base Preconditions checkArgument
public static void checkArgument(boolean expression, @Nullable Object errorMessage)
From source file:org.haiku.haikudepotserver.dataobjects.MediaType.java
public static List<MediaType> getAll(ObjectContext context) { Preconditions.checkArgument(null != context, "the context must be provided"); return ObjectSelect.query(MediaType.class).orderBy(CODE.asc()).sharedCache().select(context); }
From source file:org.mayocat.image.util.ImageUtils.java
/** * @param width the width of the image to compute the ratio for * @param height the height of the image to compute the ratio for * @return the image ratio, under the form <code</>x:y</code> where x represents the horizontal dimension and y the * vertical dimension of the ratio *//* w w w .j ava 2s . c om*/ public static String imageRatio(Integer width, Integer height) { Preconditions.checkArgument(!(width == 0 && height == 0), "Cannot compute image ration when both width and height are zero"); Integer gcd = IntMath.gcd(width, height); return (width / gcd) + ":" + (height / gcd); }
From source file:org.janusgraph.util.encoding.ConversionHelper.java
public static final int getTTLSeconds(Duration duration) { Preconditions.checkArgument(duration != null && !duration.isZero(), "Must provide non-zero TTL"); long ttlSeconds = Math.max(1, duration.getSeconds()); assert ttlSeconds > 0; Preconditions.checkArgument(ttlSeconds <= Integer.MAX_VALUE, "tll value is too large [%s] - value overflow", duration);/* www .ja v a 2s .co m*/ return (int) ttlSeconds; }
From source file:org.haiku.haikudepotserver.dataobjects.UserPasswordResetToken.java
public static List<UserPasswordResetToken> findByUser(ObjectContext context, User user) { Preconditions.checkArgument(null != context, "the context must be supplied"); Preconditions.checkArgument(null != user, "the user must be supplied"); return ObjectSelect.query(UserPasswordResetToken.class).where(USER.eq(user)).select(context); }
From source file:org.haiku.haikudepotserver.dataobjects.PkgUrlType.java
public static Optional<PkgUrlType> getByCode(ObjectContext context, String code) { Preconditions.checkArgument(null != context, "the context must be supplied"); Preconditions.checkArgument(!Strings.isNullOrEmpty(code), "a code is required to get the url type"); return getAll(context).stream().filter(put -> put.getCode().equals(code)) .collect(SingleCollector.optional()); }
From source file:com.github.hilcode.versionator.Result.java
public static final <ANY, F, S> Result<F, S> asSuccess(final Result<ANY, S> result) { Preconditions.checkArgument(result.isSuccess(), "Invalid cast, this Result represents a Failure."); @SuppressWarnings("unchecked") final Result<F, S> result_ = (Result<F, S>) result; return result_; }
From source file:com.github.hilcode.versionator.misc.Either.java
public static final <T, L, R> Either<L, R> asLeft(final Either<L, T> either) { Preconditions.checkArgument(either.isLeft(), "Invalid cast, this Either represents a Right."); @SuppressWarnings("unchecked") final Either<L, R> either_ = (Either<L, R>) either; return either_; }
From source file:fr.norad.visuwall.plugin.sonar.QualityMeasures.java
static SonarQualityMeasure asQualityMeasure(Measure measure, String measureKey) { Preconditions.checkNotNull(measure, "measure is mandatory"); Preconditions.checkArgument(!measureKey.isEmpty(), "measureKey is mandatory"); Preconditions.checkNotNull(measure.getValue(), "measure must have a value"); Double value = measure.getValue(); SonarQualityMeasure qualityMeasure = new SonarQualityMeasure(); qualityMeasure.setKey(measureKey);// ww w.ja v a2 s.c o m qualityMeasure.setValue(value); qualityMeasure.setFormattedValue(measure.getFormattedValue()); return qualityMeasure; }
From source file:org.ros.android.view.visualization.TextureBitmapUtilities.java
public static Bitmap createSquareBitmap(int[] pixels, int width, int height, int fillColor) { Preconditions.checkArgument(pixels.length == width * height, String.format( "Pixel data does not match specified dimensions: %d != %d * %d", pixels.length, width, height)); int bitmapSize = Math.max(width, height); int[] squarePixelArray = makeSquarePixelArray(pixels, width, height, bitmapSize, fillColor); return Bitmap.createBitmap(squarePixelArray, bitmapSize, bitmapSize, Bitmap.Config.ARGB_8888); }
From source file:io.warp10.script.fwt.FWT.java
public static double[] forward(Wavelet wavelet, double[] timeBased) { Preconditions.checkArgument(0 == (timeBased.length & (timeBased.length - 1)), "Can only perform FWT on data whose cardinality is a power of 2."); double[] hilbert = Arrays.copyOf(timeBased, timeBased.length); int h = hilbert.length; int transformWavelength = wavelet.getTransformWavelength(); // 2, 4, 8, 16, 32, ... while (h >= transformWavelength) { double[] temp = wavelet.forward(hilbert, h); System.arraycopy(temp, 0, hilbert, 0, h); h = h >> 1;//w ww. j ava 2 s.c om } // levels return hilbert; }