List of usage examples for com.google.common.base Preconditions checkNotNull
public static <T> T checkNotNull(T reference)
From source file:in.tum.de.ase.db.TicketsHandler.java
/** * Inserts the provided single ticket to the database * * @param eticket/*from w w w . j ava 2 s . c o m*/ * provided ticket * @throws NullPointerException * if argument is null */ public static void insertTicket(final Eticket eticket) { Preconditions.checkNotNull(eticket); if (eticket.getType() == EticketType.SINGLE) { EnvironmentInitializer.getInstance().getCollection().save(eticket); } }
From source file:org.apache.gobblin.compliance.utils.PartitionUtils.java
/** * Add single quotes to the string, if not present. * TestString will be converted to 'TestString' *///from ww w.j a v a 2 s. co m public static String getQuotedString(String st) { Preconditions.checkNotNull(st); String quotedString = ""; if (!st.startsWith(SINGLE_QUOTE)) { quotedString += SINGLE_QUOTE; } quotedString += st; if (!st.endsWith(SINGLE_QUOTE)) { quotedString += SINGLE_QUOTE; } return quotedString; }
From source file:com.spotify.sshagenttls.CertKeyPaths.java
private static Path checkExists(final Path path) { Preconditions.checkNotNull(path); Preconditions.checkArgument(path.toFile().canRead(), path + " does not exist or cannot be read"); return path;// w w w . j a v a 2 s . c o m }
From source file:com.empcraft.xpbank.util.ChunkUtil.java
public static Optional<Chunk> getLoadedChunk(World world, Location loc) { Preconditions.checkNotNull(loc); Optional<Chunk> loadedChunk = Optional.absent(); final Chunk chunkAt = world.getChunkAt(loc); if (chunkAt.isLoaded()) { loadedChunk = Optional.of(chunkAt); }// ww w . j a v a 2 s. c o m return loadedChunk; }
From source file:li.klass.fhem.util.BuildVersion.java
public static void execute(VersionDependent versionDependent, int buildVersion) { Preconditions.checkNotNull(versionDependent); Preconditions.checkArgument(buildVersion > 0); int apiVersion = android.os.Build.VERSION.SDK_INT; if (apiVersion >= buildVersion) { versionDependent.ifAboveOrEqual(); } else {/*from w ww . j a va2 s. c o m*/ versionDependent.ifBelow(); } }
From source file:edu.byu.nlp.stats.GammaDistribution.java
/** * self-contained gamma generator. Multiply result with scale parameter (or * divide by rate parameter). After Teh (npbayes). * /*from w ww . j a va 2s . c o m*/ * Taken From knowceans. */ public static double sample(double shape, RandomGenerator rnd) { Preconditions.checkArgument(shape > 0.0); Preconditions.checkNotNull(rnd); if (shape == 1.0) { /* Exponential */ return -Math.log(rnd.nextDouble()); } else if (shape < 1.0) { /* Use Johnk's generator */ double cc = 1.0 / shape; double dd = 1.0 / (1.0 - shape); while (true) { double xx = Math.pow(rnd.nextDouble(), cc); double yy = xx + Math.pow(rnd.nextDouble(), dd); if (yy <= 1.0) { // FIXME: assertion error for rr = 0.010817814317923407 // assert yy != 0 && xx / yy > 0 : "rr = " + rr; // INFO: this if is a hack if (yy != 0 && xx / yy > 0) { return -Math.log(rnd.nextDouble()) * xx / yy; } } } } else { /* rr > 1.0 */ /* Use bests algorithm */ double bb = shape - 1.0; double cc = 3.0 * shape - 0.75; while (true) { double uu = rnd.nextDouble(); double vv = rnd.nextDouble(); double ww = uu * (1.0 - uu); double yy = Math.sqrt(cc / ww) * (uu - 0.5); double xx = bb + yy; if (xx >= 0) { double zz = 64.0 * ww * ww * ww * vv * vv; assert zz > 0 && bb != 0 && xx / bb > 0; if ((zz <= (1.0 - 2.0 * yy * yy / xx)) || (Math.log(zz) <= 2.0 * (bb * Math.log(xx / bb) - yy))) { return xx; } } } } }
From source file:com.cloudera.oryx.computation.common.records.avro.AvroSpec.java
private static DataType getDataType(Schema schema) { Schema.Type st = schema.getType(); Preconditions.checkNotNull(st); switch (st) { case RECORD:// w ww.java 2 s. c om return DataType.RECORD; case INT: return DataType.INT; case BOOLEAN: return DataType.BOOLEAN; case FLOAT: case DOUBLE: return DataType.DOUBLE; case STRING: return DataType.STRING; case LONG: return DataType.LONG; default: throw new IllegalStateException("Cannot support schema type = " + st); } }
From source file:com.facebook.buck.rules.FakeInputRule.java
public static InputRule createWithRuleKey(String absolutePath, RuleKey customRuleKey) { return new FakeInputRule(new File(absolutePath), Preconditions.checkNotNull(customRuleKey)); }
From source file:com.spectralogic.ds3client.helpers.JobPartTrackerFactory.java
public static JobPartTracker buildPartTracker(final Iterable<BulkObject> objects) { final ArrayListMultimap<String, ObjectPart> multimap = ArrayListMultimap.create(); for (final BulkObject bulkObject : Preconditions.checkNotNull(objects)) { multimap.put(bulkObject.getName(), new ObjectPart(bulkObject.getOffset(), bulkObject.getLength())); }// w w w. j av a 2 s . com return new JobPartTrackerImpl(new HashMap<>( Maps.transformEntries(multimap.asMap(), new BuildObjectPartTrackerFromObjectPartGroup()))); }
From source file:com.jivesoftware.os.server.http.jetty.jersey.server.binding.Injectable.java
@SuppressWarnings("unchecked") public static <T2> Injectable<T2> ofUnsafe(Class<T2> injectableType, Object instance) { Preconditions.checkNotNull(injectableType); Preconditions.checkNotNull(instance); Preconditions.checkArgument(injectableType.isAssignableFrom(instance.getClass()), "Injectable must be assignable to type '" + injectableType + "': " + instance); return new Injectable<>(injectableType, (T2) instance); }