List of usage examples for com.google.common.base Preconditions checkNotNull
public static <T> T checkNotNull(T reference, @Nullable Object errorMessage)
From source file:com.ctriposs.r2.util.URIUtil.java
/** * Returns an array of each path segment, using the definition as defined in RFC 2396. * If present, a leading path separator is removed. * * @param path the path to tokenize//from w w w . j a va 2 s . com * @return an array of the path segments in the given path */ public static String[] tokenizePath(String path) { Preconditions.checkNotNull(path, "uri"); if (!path.isEmpty() && path.charAt(0) == PATH_SEP) { path = path.substring(1); } return PATH_SEP_PATTERN.split(path); }
From source file:com.google.api.ClientCredentials.java
public static void errorIfNotSpecified() { Preconditions.checkNotNull(KEY, "Please enter your API key from https://code.google.com/apis/console/?api=calendar in " + ClientCredentials.class); }
From source file:org.apache.flume.channel.file.encryption.KeyProviderFactory.java
@SuppressWarnings({ "rawtypes", "unchecked" }) public static KeyProvider getInstance(String keyProviderType, Context context) { Preconditions.checkNotNull(keyProviderType, "key provider type must not be null"); // try to find builder class in enum of known providers KeyProviderType type;/* w ww .jav a2 s .c o m*/ try { type = KeyProviderType.valueOf(keyProviderType.toUpperCase()); } catch (IllegalArgumentException e) { logger.debug("Not in enum, loading provider class: {}", keyProviderType); type = KeyProviderType.OTHER; } Class<? extends KeyProvider.Builder> providerClass = type.getBuilderClass(); // handle the case where they have specified their own builder in the config if (providerClass == null) { try { Class c = Class.forName(keyProviderType); if (c != null && KeyProvider.Builder.class.isAssignableFrom(c)) { providerClass = (Class<? extends KeyProvider.Builder>) c; } else { String errMessage = "Unable to instantiate Builder from " + keyProviderType; logger.error(errMessage); throw new FlumeException(errMessage); } } catch (ClassNotFoundException ex) { logger.error("Class not found: " + keyProviderType, ex); throw new FlumeException(ex); } } // build the builder KeyProvider.Builder provider; try { provider = providerClass.newInstance(); } catch (InstantiationException ex) { String errMessage = "Cannot instantiate builder: " + keyProviderType; logger.error(errMessage, ex); throw new FlumeException(errMessage, ex); } catch (IllegalAccessException ex) { String errMessage = "Cannot instantiate builder: " + keyProviderType; logger.error(errMessage, ex); throw new FlumeException(errMessage, ex); } return provider.build(context); }
From source file:com.google.security.zynamics.binnavi.Gui.GraphWindows.CWindowTitle.java
/** * Generates the proper window title for the graph window depending on its current state. * * @param panel The active graph panel./*from w ww . jav a 2 s . c om*/ * * @return The window title of the graph window. */ public static String generate(final IGraphPanel panel) { Preconditions.checkNotNull(panel, "IE01637: Panel argument can not be null"); final INaviView view = panel.getModel().getGraph().getRawView(); final String containerName = panel.getModel().getViewContainer().getName(); final String viewName = view.getName(); final String viewDescription = view.getConfiguration().getDescription(); if ("".equals(viewDescription)) { return String.format("%s - %s - %s", viewName, containerName, Constants.DEFAULT_WINDOW_TITLE); } else { return String.format("%s - %s - %s - %s", viewName, containerName, viewDescription, Constants.DEFAULT_WINDOW_TITLE); } }
From source file:com.b2international.snowowl.datastore.cdo.CDOTransactionAggregatorUtils.java
/** * Checks the {@link ICDOTransactionAggregator aggregator} argument, and returns with the given argument * if can be referenced (not {@code null}) and wraps at least on {@link CDOTransaction transaction}. * @param aggregator the aggregator to check. * @return the argument./*from w w w . j av a 2 s . c o m*/ */ public static <T extends ICDOTransactionAggregator> T check(final T aggregator) { Preconditions.checkNotNull(aggregator, "CDO transaction aggregator argument cannot be null."); if (CompareUtils.isEmpty(aggregator)) { throw new EmptyTransactionAggregatorException(); } return aggregator; }
From source file:com.blurengine.blur.utils.relationalops.RelationalUtils.java
/** * Creates and returns a {@link Relationals#number(Number)} from a String. The relational may be static if the string has an operator (See * {@link #operator(String)})./*w ww. j a va 2 s .c o m*/ * * @param string string to deserialize * @return number relational */ public static Relational<Number> deserializeNumber(@Nonnull String string) { Preconditions.checkNotNull(string, "string cannot be null."); RelationalOperator operator = operator(string); Relational<Number> number = Relationals.number(Double.parseDouble(fixString(string, operator))); if (operator != null) { number = number.staticOp(operator); } return number; }
From source file:com.metamx.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"); if (postAggs != null && !postAggs.isEmpty()) { Set<String> combinedAggNames = Sets .newHashSet(Lists.transform(aggFactories, new Function<AggregatorFactory, String>() { @Override//ww w . jav a 2s.c om public String apply(@Nullable AggregatorFactory input) { return input.getName(); } })); for (PostAggregator postAgg : postAggs) { Set<String> dependencies = postAgg.getDependentFields(); Set<String> missing = Sets.difference(dependencies, combinedAggNames); Preconditions.checkArgument(missing.isEmpty(), "Missing fields [%s] for postAggregator [%s]", missing, postAgg.getName()); combinedAggNames.add(postAgg.getName()); } } }
From source file:com.github.jeluard.guayaba.base.Preconditions2.java
/** * Ensure specified {@link Collection} is not {@link Collection#isEmpty()}. * * @param collection a collection//from w w w. ja v a 2s.co m * @param name a representation of {@code collection} used to build the error message * @throws IllegalArgumentException if {@code collection} is {@link Collection#isEmpty()} */ public static <T extends Collection<?>> T checkNotEmpty(final T collection, final String name) { Preconditions.checkNotNull(name, "null name"); Preconditions.checkArgument(!Preconditions.checkNotNull(collection, "null " + name).isEmpty(), name + " is empty"); return collection; }
From source file:org.apache.flume.formatter.output.PathManagerFactory.java
public static PathManager getInstance(String managerType, Context context) { Preconditions.checkNotNull(managerType, "path manager type must not be null"); // try to find builder class in enum of known output serializers PathManagerType type;// www.j ava2 s. com try { type = PathManagerType.valueOf(managerType.toUpperCase(Locale.ENGLISH)); } catch (IllegalArgumentException e) { logger.debug("Not in enum, loading builder class: {}", managerType); type = PathManagerType.OTHER; } Class<? extends PathManager.Builder> builderClass = type.getBuilderClass(); // handle the case where they have specified their own builder in the config if (builderClass == null) { try { Class c = Class.forName(managerType); if (c != null && PathManager.Builder.class.isAssignableFrom(c)) { builderClass = (Class<? extends PathManager.Builder>) c; } else { String errMessage = "Unable to instantiate Builder from " + managerType + ": does not appear to implement " + PathManager.Builder.class.getName(); throw new FlumeException(errMessage); } } catch (ClassNotFoundException ex) { logger.error("Class not found: " + managerType, ex); throw new FlumeException(ex); } } // build the builder PathManager.Builder builder; try { builder = builderClass.newInstance(); } catch (InstantiationException ex) { String errMessage = "Cannot instantiate builder: " + managerType; logger.error(errMessage, ex); throw new FlumeException(errMessage, ex); } catch (IllegalAccessException ex) { String errMessage = "Cannot instantiate builder: " + managerType; logger.error(errMessage, ex); throw new FlumeException(errMessage, ex); } return builder.build(context); }
From source file:io.airlift.discovery.client.DiscoveryBinder.java
public static DiscoveryBinder discoveryBinder(Binder binder) { Preconditions.checkNotNull(binder, "binder is null"); return new DiscoveryBinder(binder); }