List of usage examples for com.google.common.base Preconditions checkArgument
public static void checkArgument(boolean expression, @Nullable Object errorMessage)
From source file:org.impressivecode.depress.mr.judy.JudyEntriesParser.java
public static List<Class> unmarshalResults(final String path) throws JAXBException { Preconditions.checkArgument(!isNullOrEmpty(path), "Path has to be set."); JAXBContext jaxbContext = JAXBContext.newInstance(JudyXmlResult.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); JudyXmlResult result = (JudyXmlResult) unmarshaller.unmarshal(new File(path)); return result.getClasses().getClazz(); }
From source file:org.arbeitspferde.friesian.RandomNumber.java
/** Generates a random number based on the input max and min parameters */ public static int generate(int min, int max, Random rng) { Preconditions.checkArgument(max > 0, "Max must be positive"); Preconditions.checkArgument(min <= max, "Min must be less than or equal to max"); int range = max - min; int result = min; if (range == 0) { return min; }/*from www.j a v a 2s . c o m*/ try { result = min + rng.nextInt(range + 1); } catch (Exception e) { log.log(Level.WARNING, String.format("min: %d min: %d", min, max), e); } return result; }
From source file:com.google.cloud.bigtable.grpc.ResultQueueEntry.java
public static <T> ResultQueueEntry<T> newResult(T response) { Preconditions.checkArgument(response != null, "Response may not be null"); return new ResultQueueEntry<>(null, response, false); }
From source file:io.spikex.core.util.XXHash32.java
public static int hash(final String utf8Str, final int salt) { Preconditions.checkArgument((utf8Str != null && utf8Str.length() > 0), "utf8Str is null or empty"); byte[] data = utf8Str.getBytes(StandardCharsets.UTF_8); return FACTORY.hash32().hash(data, 0, data.length, salt); }
From source file:de.flapdoodle.guava.Either.java
public static <L, R> Either<L, R> leftOrRight(L left, R right, String errorMessage) { Preconditions.checkArgument(Logics.xor(left, right), errorMessage); if (left != null) { return left(left); }/*from w w w . j av a2 s . c o m*/ return right(right); }
From source file:com.cloudera.flume.handlers.debug.NullSink.java
public static SinkBuilder builder() { return new SinkBuilder() { @Override/* w ww . j av a 2 s .co m*/ public EventSink build(Context context, String... argv) { Preconditions.checkArgument(argv.length == 0, "usage: null"); return new NullSink(); } }; }
From source file:org.caleydo.view.bicluster.util.TesselatedBiClusterPolygons.java
public static Band band(List<Vec2f> anchorPoints, final float z, float radiusFirst, float radiusSecond, int numberOfSplinePoints) { Preconditions.checkArgument(anchorPoints.size() >= 2, "at least two points"); List<Vec3f> curve = Splines.spline3(Lists.transform(anchorPoints, new Function<Vec2f, Vec3f>() { @Override// w w w.ja va2s. com public Vec3f apply(Vec2f in) { return new Vec3f(in.x(), in.y(), z); } }), numberOfSplinePoints); return toBand(curve, radiusFirst, radiusSecond); }
From source file:app.philm.in.util.ColorValueAnimator.java
public static ValueAnimator start(final View rootView, final int[] current, final int[] target, final int duration, final OnColorSetListener listener) { Preconditions.checkNotNull(rootView, "rootView cannot be null"); Preconditions.checkNotNull(current, "current cannot be null"); Preconditions.checkNotNull(target, "target cannot be null"); Preconditions.checkArgument(current.length == target.length, "current and target must be the same length"); if (rootView.getDrawingTime() <= 0) { listener.onUpdateColor(target);/*w w w. ja v a 2 s. com*/ return null; } final int[] colors = new int[target.length]; ValueAnimator animator = new ValueAnimator(); animator.setFloatValues(0f, 1f); animator.setDuration(duration); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { final float currentValue = 1f - (Float) valueAnimator.getAnimatedValue(); for (int i = 0, z = colors.length; i < z; i++) { colors[i] = ColorUtils.blendColors(current[i], target[i], currentValue); } listener.onUpdateColor(colors); } }); animator.start(); return animator; }
From source file:com.google.template.soy.jssrc.dsl.ObjectLiteral.java
static ObjectLiteral create(ImmutableList<? extends Expression> keys, ImmutableList<? extends Expression> values) { Preconditions.checkArgument(keys.size() == values.size(), "Mismatch between keys and values."); ImmutableList.Builder<Statement> initialStatements = ImmutableList.builder(); for (Expression key : keys) { initialStatements.addAll(key.initialStatements()); }/*from w w w . ja v a2 s. com*/ for (Expression value : values) { initialStatements.addAll(value.initialStatements()); } return new AutoValue_ObjectLiteral(initialStatements.build(), keys, values); }
From source file:com.amazon.kinesis.streaming.agent.tailing.FileId.java
/** * @see #get(BasicFileAttributes)/* w w w . j a v a 2 s. co m*/ */ public static FileId get(Path file) throws IOException { if (!Files.exists(file)) { return null; } Preconditions.checkArgument(Files.isRegularFile(file), "Can only get ID for real files (no directories and symlinks): " + file); BasicFileAttributes attr = Files.readAttributes(file, BasicFileAttributes.class); return get(attr); }