List of usage examples for com.google.common.base Preconditions checkArgument
public static void checkArgument(boolean expression, @Nullable Object errorMessage)
From source file:io.druid.query.Queries.java
public static void verifyAggregations(List<AggregatorFactory> aggFactories, List<PostAggregator> postAggs) { Preconditions.checkNotNull(aggFactories, "aggregations cannot be null"); Preconditions.checkArgument(aggFactories.size() > 0, "Must have at least one AggregatorFactory"); final Set<String> aggNames = Sets.newHashSet(); for (AggregatorFactory aggFactory : aggFactories) { Preconditions.checkArgument(aggNames.add(aggFactory.getName()), "[%s] already defined", aggFactory.getName());/*from ww w . j a v a 2 s. c o m*/ } if (postAggs != null && !postAggs.isEmpty()) { final Set<String> combinedAggNames = Sets.newHashSet(aggNames); for (PostAggregator postAgg : postAggs) { final Set<String> dependencies = postAgg.getDependentFields(); final Set<String> missing = Sets.difference(dependencies, combinedAggNames); Preconditions.checkArgument(missing.isEmpty(), "Missing fields [%s] for postAggregator [%s]", missing, postAgg.getName()); Preconditions.checkArgument(combinedAggNames.add(postAgg.getName()), "[%s] already defined"); } } }
From source file:org.geogig.osm.internal.log.OSMMappingLogEntry.java
public static OSMMappingLogEntry fromString(String s) { String[] tokens = s.split("\t"); Preconditions.checkArgument(tokens.length == 2, "Wrong mapping log entry definition"); return new OSMMappingLogEntry(ObjectId.valueOf(tokens[0]), ObjectId.valueOf(tokens[1])); }
From source file:org.rpmcomparator.service.ValidatorUtil.java
/** * @param fileName/* w ww . j a va 2 s . c o m*/ * @return * @throws IOException,RuntimeException */ public static File getValideFile(String fileName) { File file = new File(Preconditions.checkNotNull(fileName, "Give file cannot be null")); Preconditions.checkArgument(file.exists(), "Give file:" + fileName + "Should exist"); return file; }
From source file:security.AuthenticationManager.java
public static void authenticateUser(String userName, String password) throws NamingException { Preconditions.checkArgument(!StringUtils.isAnyEmpty(userName, password), "Username or password cannot be empty"); try {//www .j a v a2 s . c o m LoginContext lc = new LoginContext("WHZ-Authentication", new WHZCallbackHandler(userName, password)); lc.login(); } catch (LoginException le) { throw new AuthenticationException(le.toString()); } }
From source file:com.xiaomi.linden.hadoop.indexing.util.LindenConfigBuilder.java
public static LindenConfig build() throws IOException { File lindenProperties = new File("lindenProperties"); Preconditions.checkArgument(lindenProperties.exists(), "can not find linden properties file."); try {//from w ww. j a v a 2 s . c om LindenConfig lindenConf = com.xiaomi.linden.core.LindenConfigBuilder.build(lindenProperties); File lindenSchema = new File("lindenSchema"); Preconditions.checkArgument(lindenSchema.exists(), "can not find linden schema file."); LindenSchema schema; try { schema = LindenSchemaBuilder.build(lindenSchema); } catch (Exception e) { logger.error("Linden schema builder exception", e); throw new IOException(e); } lindenConf.setSchema(schema); lindenConf.setIndexType(LindenConfig.IndexType.RAM); return lindenConf; } catch (Exception e) { logger.error("Linden search config builder exception", e); throw new IOException(e); } }
From source file:io.spikex.core.util.StringTokenizer.java
public static String[] tokenize(final String str, final String delim) { // Sanity checks Preconditions.checkArgument(str != null && str.length() > 0, "str is null or empty"); Preconditions.checkArgument(delim != null && delim.length() > 0, "delim is null or empty"); String[] temp = m_temp.get(); int tempLen = (str.length() / 2) + 2; int delimLen = delim.length(); if (temp == null || temp.length < tempLen) { temp = new String[tempLen]; m_temp.set(temp);// w ww . java2 s. co m } int wordCount = 0; int i = 0; int j = str.indexOf(delim); while (j >= 0) { temp[wordCount++] = str.substring(i, j); i = j + delimLen; j = str.indexOf(delim, i); } //temp[wordCount++] = str.substring(i); m_remaining.set(str.substring(i).getBytes().length); String[] result = new String[wordCount]; System.arraycopy(temp, 0, result, 0, wordCount); return result; }
From source file:org.eclipse.xtend.core.macro.ConditionUtils.java
public static void notRemoved(final EObject object, final String name) { StringConcatenation _builder = new StringConcatenation(); _builder.append(name);//from w w w . j av a 2 s .c o m _builder.append(" cannot be null"); Preconditions.checkArgument((object != null), _builder); Resource _eResource = object.eResource(); boolean _tripleNotEquals = (_eResource != null); StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append(name); _builder_1.append(" cannot be removed"); Preconditions.checkArgument(_tripleNotEquals, _builder_1); }
From source file:de.jackwhite20.cobra.client.CobraClientFactory.java
public static CobraClient create(int connectTimeout) { Preconditions.checkArgument(connectTimeout > 0, "connectTimeout cannot be negative"); return new CobraClientImpl(connectTimeout); }
From source file:com.github.steveash.jg2p.util.Zipper.java
public static <A, B> List<Pair<A, B>> up(Iterable<A> a, Iterable<B> b) { ArrayList<Pair<A, B>> result = Lists.newArrayList(); Iterator<A> iterA = a.iterator(); Iterator<B> iterB = b.iterator(); while (iterA.hasNext()) { Preconditions.checkArgument(iterB.hasNext(), "B is shorter than A, must be same size"); A aa = iterA.next();/* w ww. j a va2 s. c o m*/ B bb = iterB.next(); result.add(Pair.of(aa, bb)); } Preconditions.checkArgument(!iterB.hasNext(), "A is shorter than B, must be same size"); return result; }
From source file:org.apache.beam.sdk.extensions.euphoria.core.translate.OperatorTranslators.java
static <T> PCollection<T> getSingleInput(PCollectionList<T> inputs) { Preconditions.checkArgument(inputs.size() == 1, "There should be exactly one input."); return inputs.get(0); }