List of usage examples for com.google.common.base Preconditions checkNotNull
public static <T> T checkNotNull(T reference, @Nullable Object errorMessage)
From source file:io.pravega.controller.store.client.impl.StoreClientConfigImpl.java
public static StoreClientConfig withZKClient(ZKClientConfig zkClientConfig) { Preconditions.checkNotNull(zkClientConfig, "zkClientConfig"); return new StoreClientConfigImpl(StoreType.Zookeeper, Optional.of(zkClientConfig)); }
From source file:com.enonic.cms.core.timezone.TimeZoneXmlCreator.java
public Document createTimeZonesDocument(final Collection<DateTimeZone> timeZones) { Preconditions.checkNotNull(timeZones, "timeZones cannot be null"); Element timeZonesEl = new Element("time-zones"); for (DateTimeZone timeZone : timeZones) { timeZonesEl.addContent(doCreateTimeZoneElement(timeZone)); }//from ww w . j a v a 2 s . c om return new Document(timeZonesEl); }
From source file:com.qcadoo.mes.states.service.StateChangePhaseUtil.java
public static boolean canRun(final StateChangeContext stateChangeContext) { List<Entity> messages = stateChangeContext.getAllMessages(); Preconditions.checkNotNull(messages, "entity " + stateChangeContext.getStateChangeEntity() + " should have messages in corresponding hasMany field!"); return stateChangeContext.isOwnerValid() && stateChangeContext.getStatus().canContinue() && !hasFailureMessages(messages) && !hasValidationErrorMessages(messages); }
From source file:com.facebook.util.reflection.ForwardReferenceProxy.java
private static <T> T wrap(Class<T> clazz, final AtomicReference<T> instance) { Preconditions.checkNotNull(instance, "must pass a non-null atomic reference"); InvocationHandler handler = (proxy, method, args) -> method .invoke(Preconditions.checkNotNull(instance.get(), "instance has not been set"), args); T wrapper = (T) Proxy.newProxyInstance(clazz.getClassLoader(), new Class[] { clazz }, handler); return wrapper; }
From source file:alluxio.util.network.HttpUtils.java
/** * Uses the post method to send a url with arguments by http, this method can call RESTful Api. * * @param url the http url/*from w w w . ja v a 2 s .c o m*/ * @param timeout milliseconds to wait for the server to respond before giving up * @param processInputStream the response body stream processor */ public static void post(String url, Integer timeout, IProcessInputStream processInputStream) throws IOException { Preconditions.checkNotNull(timeout, "timeout"); Preconditions.checkNotNull(processInputStream, "processInputStream"); PostMethod postMethod = new PostMethod(url); try { HttpClient httpClient = new HttpClient(); httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(timeout); httpClient.getHttpConnectionManager().getParams().setSoTimeout(timeout); int statusCode = httpClient.executeMethod(postMethod); if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_CREATED) { InputStream inputStream = postMethod.getResponseBodyAsStream(); processInputStream.process(inputStream); } else { throw new IOException("Failed to perform POST request. Status code: " + statusCode); } } finally { postMethod.releaseConnection(); } }
From source file:org.apache.mahout.math.als.AlternatingLeastSquaresSolver.java
public static Vector solve(Iterable<Vector> featureVectors, Vector ratingVector, double lambda, int numFeatures) { Preconditions.checkNotNull(featureVectors, "Feature Vectors cannot be null"); Preconditions.checkArgument(!Iterables.isEmpty(featureVectors)); Preconditions.checkNotNull(ratingVector, "Rating Vector cannot be null"); Preconditions.checkArgument(ratingVector.getNumNondefaultElements() > 0, "Rating Vector cannot be empty"); Preconditions.checkArgument(Iterables.size(featureVectors) == ratingVector.getNumNondefaultElements()); int nui = ratingVector.getNumNondefaultElements(); Matrix MiIi = createMiIi(featureVectors, numFeatures); Matrix RiIiMaybeTransposed = createRiIiMaybeTransposed(ratingVector); /* compute Ai = MiIi * t(MiIi) + lambda * nui * E */ Matrix Ai = miTimesMiTransposePlusLambdaTimesNuiTimesE(MiIi, lambda, nui); /* compute Vi = MiIi * t(R(i,Ii)) */ Matrix Vi = MiIi.times(RiIiMaybeTransposed); /* compute Ai * ui = Vi */ return solve(Ai, Vi); }
From source file:org.codehaus.httpcache4j.cache.Key.java
public static Key create(URI uri, Vary vary) { Preconditions.checkNotNull(uri, "URI may not be null"); Preconditions.checkNotNull(vary, "vary may not be null"); return new Key(URIBuilder.fromURI(uri).toNormalizedURI(), vary); }
From source file:com.google.security.zynamics.binnavi.Gui.SettingsDialog.CActionProvider.java
/** * Prompts the user for the location of the IDA executable. * /*from w ww . j a v a2s.c o m*/ * @param parent Parent component used to display dialogs. * @param initialDirectory The directory to select by default. * * @return The selected IDA executable or null if no executable was selected. */ public static String selectIDADirectory(final Component parent, final String initialDirectory) { Preconditions.checkNotNull(parent, "IE02067: Parent argument can not be null"); Preconditions.checkNotNull(initialDirectory, "IE02259: Initial directory can not be null"); final CIdaSelectionDialog dialog = CIdaSelectionDialog.show(SwingUtilities.getWindowAncestor(parent), initialDirectory); final File selectedFile = dialog.getSelectedFile(); if (selectedFile == null) { return null; } else if (!selectedFile.exists()) { CMessageBox.showError(parent, "File does not exist."); return null; } else if (selectedFile.canExecute()) { return selectedFile.getAbsolutePath(); } else { CMessageBox.showError(parent, "File is not an executable file."); return null; } }