List of usage examples for com.google.common.base Preconditions checkNotNull
public static <T> T checkNotNull(T reference)
From source file:com.bennavetta.aeneas.zookeeper.Servers.java
/** * Generates suitable ZooKeeper configuration from a collection of server instances. The produced map is the parsed * equivalent of the {@code server.N} properties in ZooKeeper's dynamic configuration file. * @param servers the servers to include * @return a configuration chunk as a map */// w w w .java2s. c o m public static Map<String, String> toServerSpecification(ZkServer... servers) { Preconditions.checkNotNull(servers); return Arrays.stream(servers) .collect(Collectors.toMap(s -> "server." + s.getId(), ZkServer::toConnectionSpec)); }
From source file:com.github.mike10004.jenkinsbbhook.ServletInitParamValueProvider.java
public ServletInitParamValueProvider(ServletContext servletContext) { this.servletContext = Preconditions.checkNotNull(servletContext); }
From source file:com.davidbracewell.ml.classification.Classification.java
/** * Calculates the log likelihood of the model give a set of data. * * @param model The model// ww w. j a va2s. c om * @param data The data * @return The log likelihood */ public static double logLikelihood(ClassificationModel model, List<Instance> data) { Preconditions.checkNotNull(model); Preconditions.checkNotNull(data); double ll = 0; for (Instance inst : data) { if (inst.hasTargetValue()) { ll += Math.log(model.estimate(inst).getConfidence(inst.getTargetValue())); } } return ll; }
From source file:org.apache.shindig.common.util.HashUtil.java
/** * Produces a checksum for the given input data. Currently uses a hexified * message digest.//from www. j a va2s. c o m * * @param data * @return The checksum. */ public static String checksum(byte[] data) { byte[] hashBytes = getMessageDigest().digest(Preconditions.checkNotNull(data)); char[] hex = new char[2 * hashBytes.length]; // Convert to hex. possibly change to base64 in the future for smaller // signatures. int offset = 0; for (byte b : hashBytes) { hex[offset++] = HEX_CHARS[(b & 0xF0) >>> 4]; // upper 4 bits hex[offset++] = HEX_CHARS[(b & 0x0F)]; // lower 4 bits } return new String(hex); }
From source file:org.apache.rocketmq.jms.util.ExceptionUtil.java
public static JMSException convertToJmsException(Exception e, String extra) { Preconditions.checkNotNull(extra); Preconditions.checkNotNull(e);// w w w . j a v a2s.co m JMSException jmsException = new JMSException(extra); jmsException.initCause(e); return jmsException; }
From source file:com.sonar.sslr.api.typed.Optional.java
public static <T> Optional<T> of(T reference) { return new Present<T>(Preconditions.checkNotNull(reference)); }
From source file:com.google.api.client.discovery.IconDescription.java
static IconDescription createX16Icon(String url) { IconDescription instance = new IconDescription(); instance.size = Size.X16;//from w ww . j a va2 s .co m instance.url = Preconditions.checkNotNull(url); return instance; }
From source file:com.google.devtools.j2objc.types.JavaMethod.java
/** * Factory method that returns a JavaMethod for a specified method binding. *//*w w w .j a v a 2 s . co m*/ public static JavaMethod getJavaMethod(IMethodBinding binding) { Preconditions.checkNotNull(binding); ITypeBinding classBinding = binding.getDeclaringClass(); if (classBinding == null) { return null; } String clazz = classBinding.getBinaryName(); if (clazz == null) { return null; // true for local variables in unreachable code } return new JavaMethod(binding, classBinding); }
From source file:io.macgyver.core.util.JsonNodes.java
public static void sort(List<JsonNode> n, Comparator<JsonNode> comparator) { Preconditions.checkNotNull(n); Preconditions.checkNotNull(comparator); Collections.sort(n, comparator); }
From source file:com.github.katjahahn.tools.visualizer.ImageUtil.java
/** * Appends rightImage to the right side of leftImage. * <p>// w w w . ja v a2 s . c om * The resulting image type is one of leftImage. * * @param leftImage * first image, must not be null * @param rightImage * second image that is appended to the right side of leftImage, * must not be null * @return appended image */ public static BufferedImage appendImages(BufferedImage leftImage, BufferedImage rightImage) { Preconditions.checkNotNull(leftImage); Preconditions.checkNotNull(rightImage); int width = leftImage.getWidth() + rightImage.getWidth(); int height = Math.max(leftImage.getHeight(), rightImage.getHeight()); BufferedImage result = new BufferedImage(width, height, leftImage.getType()); result.createGraphics().drawImage(leftImage, 0, 0, null); result.createGraphics().drawImage(rightImage, leftImage.getWidth(), 0, null); return result; }