List of usage examples for com.google.common.base Preconditions checkNotNull
public static <T> T checkNotNull(T reference)
From source file:com.palantir.lock.AtlasRowLockDescriptor.java
/** Returns a {@code LockDescriptor} instance for the given table and row. */ public static LockDescriptor of(String tableName, byte[] rowName) { Preconditions.checkArgument(!Strings.isNullOrEmpty(tableName)); Preconditions.checkNotNull(rowName); byte[] tableBytes = tableName.getBytes(); byte[] bytes = new byte[tableBytes.length + 1 + rowName.length]; System.arraycopy(tableBytes, 0, bytes, 0, tableBytes.length); System.arraycopy(rowName, 0, bytes, tableBytes.length + 1, rowName.length); return new LockDescriptor(bytes); }
From source file:biz.ganttproject.impex.csv.SpreadsheetFormat.java
public static SpreadsheetFormat getSpreadsheetFormat(String extension) { extension = Preconditions.checkNotNull(extension); for (SpreadsheetFormat format : values()) { if (format.getExtension().equalsIgnoreCase(extension)) { return format; }//w w w .j a v a 2s .c o m } throw new IllegalArgumentException("No enum constant extension: " + extension); }
From source file:io.pravega.controller.store.stream.StreamProperty.java
public static <T> StreamProperty<T> complete(final T complete) { Preconditions.checkNotNull(complete); return new StreamProperty<>(complete, false); }
From source file:com.minlia.cloud.framework.test.common.web.util.HTTPLinkHeaderUtil.java
/** * ex. <br>/*from w w w. j a v a 2 s . c o m*/ * https://api.github.com/users/steveklabnik/gists?page=2>; rel="next", <https://api.github.com/users/steveklabnik/gists?page=3>; rel="last" */ public static List<String> extractAllURIs(final String linkHeader) { Preconditions.checkNotNull(linkHeader); final List<String> linkHeaders = Lists.newArrayList(); final String[] links = linkHeader.split(", "); for (final String link : links) { final int positionOfSeparator = link.indexOf(';'); linkHeaders.add(link.substring(1, positionOfSeparator - 1)); } return linkHeaders; }
From source file:com.google.devtools.build.xcode.util.Mapping.java
/** * Returns the value mapped to the given key for a map. If the mapping is not present, an absent * {@code Optional} is returned.//from w ww . java2s .co m * @throws NullPointerException if the map or key argument is null */ public static <K, V> Optional<V> of(Map<K, V> map, K key) { Preconditions.checkNotNull(key); return Optional.fromNullable(map.get(key)); }
From source file:cz.cuni.mff.ms.brodecva.botnicek.ide.utils.swing.graphics.Rendering.java
/** * Pednastav vykreslovn pltna.// www . j a va 2 s .c o m * * @param graphics2d * pltno pro kreslen */ public static void preset(final Graphics2D graphics2d) { Preconditions.checkNotNull(graphics2d); graphics2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); graphics2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); graphics2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); graphics2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); graphics2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); graphics2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); }
From source file:edu.byu.nlp.stats.SymmetricDirichletOptimizationHelper.java
public static SymmetricDirichletOptimizationHelper newHelper(double[][] data) { Preconditions.checkNotNull(data); Preconditions.checkArgument(data.length > 0); double sum = 0.0; for (double[] theta : data) { sum += DoubleArrays.sum(theta);/*from w ww.java 2s . co m*/ } return new SymmetricDirichletOptimizationHelper(data[0].length, data.length, sum); }
From source file:com.cloudera.oryx.common.lang.JVMUtils.java
/** * Adds a shutdown hook that try to call {@link Closeable#close()} on the given argument * at JVM shutdown.//from w ww . jav a 2 s.c o m * * @param closeable thing to close */ public static void closeAtShutdown(Closeable closeable) { Preconditions.checkNotNull(closeable); synchronized (closeAtShutdown) { if (closeAtShutdown.isEmpty()) { Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { synchronized (closeAtShutdown) { for (Closeable c : closeAtShutdown) { IOUtils.closeQuietly(c); } } } })); } closeAtShutdown.push(closeable); } }
From source file:org.opendaylight.bgpcep.programming.tunnel.TunnelProgrammingUtil.java
public static InstanceIdentifier<Link> linkIdentifier(final InstanceIdentifier<Topology> topology, final BaseTunnelInput input) { Preconditions.checkNotNull(input.getLinkId()); return topology.child(Link.class, new LinkKey(input.getLinkId())); }
From source file:com.palantir.lock.AtlasCellLockDescriptor.java
/** Returns a {@code LockDescriptor} instance for the given table, row, and column. */ public static LockDescriptor of(String tableName, byte[] rowName, byte[] colName) { Preconditions.checkArgument(!Strings.isNullOrEmpty(tableName)); Preconditions.checkNotNull(rowName); Preconditions.checkNotNull(colName); byte[] tableBytes = tableName.getBytes(); byte[] bytes = new byte[tableBytes.length + 1 + rowName.length + 1 + colName.length]; System.arraycopy(tableBytes, 0, bytes, 0, tableBytes.length); System.arraycopy(rowName, 0, bytes, tableBytes.length + 1, rowName.length); System.arraycopy(colName, 0, bytes, tableBytes.length + 1 + rowName.length + 1, colName.length); return new LockDescriptor(bytes); }