List of usage examples for com.google.common.base Preconditions checkArgument
public static void checkArgument(boolean expression, @Nullable Object errorMessage)
From source file:com.zaradai.kunzite.trader.events.MarketData.java
public static MarketData newInstance(String instrumentId, DateTime timestamp, List<MarketDataField> fields) { Preconditions.checkArgument(!Strings.isNullOrEmpty(instrumentId), "Invalid Instrument"); Preconditions.checkNotNull(timestamp, "Invalid timestamp"); Preconditions.checkNotNull(fields, "Invalid fields specified"); return new MarketData(instrumentId, timestamp, fields); }
From source file:com.continuuity.loom.scheduler.task.TaskId.java
/** * Returns a task id from a string, validating that the string is a valid id. The format is clusterid-jobnum-tasknum. * An IllegalArgumentException will be thrown if the string is invalid. * * @param taskIdStr String of the task id to parse. * @return Task id of the string./*from w w w . jav a 2 s . c o m*/ */ public static TaskId fromString(String taskIdStr) { int index1 = taskIdStr.indexOf("-"); Preconditions.checkArgument(index1 > 0, "invalid task id string " + taskIdStr); String clusterId = taskIdStr.substring(0, index1); int index2 = taskIdStr.indexOf("-", index1 + 1); Preconditions.checkArgument(index2 > 0, "invalid task id string " + taskIdStr); long jobNum = Long.valueOf(taskIdStr.substring(index1 + 1, index2)); Preconditions.checkArgument(taskIdStr.indexOf("-", index2 + 1) < 0, "invalid task id string " + taskIdStr); long taskNum = Long.valueOf(taskIdStr.substring(index2 + 1)); return new TaskId(new JobId(clusterId, jobNum), taskNum); }
From source file:com.cloudera.nav.plugin.model.HiveIdGenerator.java
public static String generateColumnId(String sourceId, String databaseName, String tableName, String columnName) {/*from ww w.j a va 2 s.c om*/ 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, tableName, columnName); }
From source file:org.apache.eagle.metadata.utils.PolicyIdConversions.java
public static String parsePolicyId(String siteId, String generatedUniquePolicyId) { String subffix = String.format("_%s", siteId); if (generatedUniquePolicyId.endsWith(subffix)) { int streamTypeIdLength = generatedUniquePolicyId.length() - subffix.length(); Preconditions.checkArgument(streamTypeIdLength > 0, "Invalid policyId: " + generatedUniquePolicyId + ", policyId is empty"); return generatedUniquePolicyId.substring(0, streamTypeIdLength); } else {//from w w w. j av a2 s. co m return generatedUniquePolicyId; } }
From source file:org.haiku.haikudepotserver.dataobjects.NaturalLanguage.java
public static List<NaturalLanguage> getAll(ObjectContext context) { Preconditions.checkArgument(null != context, "the context must be provided"); return ObjectSelect.query(NaturalLanguage.class).orderBy(NaturalLanguage.NAME.asc()) .cacheStrategy(QueryCacheStrategy.SHARED_CACHE).select(context); }
From source file:tachyon.web.Utils.java
public static String convertMsToClockTime(long Millis) { Preconditions.checkArgument(Millis >= 0, "Negative values are not supported"); long days = Millis / Constants.DAY_MS; long hours = (Millis % Constants.DAY_MS) / Constants.HOUR_MS; long mins = (Millis % Constants.HOUR_MS) / Constants.MINUTE_MS; long secs = (Millis % Constants.MINUTE_MS) / Constants.SECOND_MS; return String.format("%d day(s), %d hour(s), %d minute(s), and %d second(s)", days, hours, mins, secs); }
From source file:com.google.template.soy.jssrc.dsl.MapLiteral.java
static MapLiteral create(ImmutableList<? extends CodeChunk.WithValue> keys, ImmutableList<? extends CodeChunk.WithValue> values) { Preconditions.checkArgument(keys.size() == values.size(), "Mismatch between keys and values."); ImmutableSet.Builder<CodeChunk> initialStatements = ImmutableSet.builder(); for (CodeChunk.WithValue key : keys) { initialStatements.addAll(key.initialStatements()); }/* w ww . j av a 2s . c o m*/ for (CodeChunk.WithValue value : values) { initialStatements.addAll(value.initialStatements()); } return new AutoValue_MapLiteral(initialStatements.build(), keys, values); }
From source file:com.palantir.atlasdb.keyvalue.api.RangeRequests.java
/** * This will return the first byte[] less than the given byte[] lexicographically. * <p>/*from w w w. j a v a 2s . c o m*/ * If name is the array <code> new byte[] { 0 }</code> an empty byte[] will be returned. * <p> * This method will throw if the empty byte array is passed. It will also reject arrays with * length greater than <code>Cell.MAX_NAME_LENGTH</code> */ public static byte[] previousLexicographicName(@Nonnull byte[] name) { Preconditions.checkArgument(name.length <= Cell.MAX_NAME_LENGTH, "name is too long"); Preconditions.checkArgument(name.length > 0, "name is empty"); if (name[name.length - 1] == 0) { byte[] ret = new byte[name.length - 1]; System.arraycopy(name, 0, ret, 0, ret.length); return ret; } byte[] ret = new byte[Cell.MAX_NAME_LENGTH]; System.arraycopy(name, 0, ret, 0, name.length); ret[name.length - 1]--; for (int i = name.length; i < ret.length; i++) { ret[i] = (byte) 0xff; } return ret; }
From source file:com.spotify.sshagenttls.CertKeyPaths.java
private static Path checkExists(final Path path) { Preconditions.checkNotNull(path);//from w w w . j a va 2 s .co m Preconditions.checkArgument(path.toFile().canRead(), path + " does not exist or cannot be read"); return path; }
From source file:net.scriptability.core.util.StringUtils.java
/** * Returns a line by number from a source string. Handles CR+LF, CR and LF line separators. * * @param source source string//from w w w . j av a 2 s. c o m * @param lineNumber line number to return from source string * @return string representing the line at the given line number */ public static String getLine(final String source, final int lineNumber) { Preconditions.checkNotNull(source, "Source cannot be null."); Preconditions.checkArgument(lineNumber > 0, "Line must be greater than 0."); String[] lines; if (source.contains(CR_LF)) { lines = source.split(CR_LF); } else if (source.contains(CR)) { lines = source.split(CR); } else if (source.contains(LF)) { lines = source.split(LF); } else { lines = new String[] { source }; } if (lineNumber > lines.length) { throw new IllegalArgumentException( "Requested line number is greater than the number of lines in source string."); } return lines[lineNumber - 1]; }