List of usage examples for com.google.common.base Preconditions checkNotNull
public static <T> T checkNotNull(T reference)
From source file:cz.cuni.mff.ms.brodecva.botnicek.ide.utils.data.Comparisons.java
/** * Zjist, zda-li jsou prvky navzjem rzn. * //from w ww.j av a2 s .co m * @param elements * prvky * @return zda-li jsou vechny prvky navzjem rzn */ @SafeVarargs public static <E> boolean allDifferent(final E... elements) { Preconditions.checkNotNull(elements); return ImmutableSet.copyOf(elements).size() == elements.length; }
From source file:org.opendaylight.controller.netconf.cli.commands.output.OutputDefinition.java
public static OutputDefinition fromOutput(final ContainerSchemaNode output) { Preconditions.checkNotNull(output); return new OutputDefinition(output.getChildNodes()); }
From source file:us.eharning.atomun.mnemonic.spi.bip0039.BIP0039MnemonicIndexGenerator.java
/** * Take the input entropy and output an array of word indices. * * @param entropy// w w w . j a v a 2 s . co m * generated entropy to process. * * @return array of integer indices into dictionary. */ @Nonnull public static int[] generateIndices(@Nonnull byte[] entropy) { Preconditions.checkNotNull(entropy); byte[] joined = new byte[entropy.length + 256 / 8]; System.arraycopy(entropy, 0, joined, 0, entropy.length); BIP0039MnemonicUtility.sha256digest(joined, 0, entropy.length, joined, entropy.length); /* Convert the length to bits for purpose of BIP0039 specification match-up */ int entropyBitCount = entropy.length * 8; int checksumBitCount = entropyBitCount / 32; int totalBitCount = entropyBitCount + checksumBitCount; int mnemonicSentenceLength = totalBitCount / 11; BitReader bitReader = new ByteArrayBitReader(joined); int[] indexValues = new int[mnemonicSentenceLength]; for (int i = 0; i < mnemonicSentenceLength; i++) { int index = bitReader.read(11); indexValues[i] = index; } return indexValues; }
From source file:edu.byu.nlp.classify.NaiveBayesClassifier.java
public static NaiveBayesClassifier newClassifier(double[] logPOfY, double[] logPOfXGivenY, boolean copy) { Preconditions.checkNotNull(logPOfY); Preconditions.checkNotNull(logPOfXGivenY); Preconditions.checkArgument(logPOfXGivenY.length % logPOfY.length == 0); if (copy) {/*from w w w.ja v a 2s . c o m*/ logPOfY = logPOfY.clone(); logPOfXGivenY = logPOfXGivenY.clone(); } return new NaiveBayesClassifier(logPOfY, logPOfXGivenY); }
From source file:com.facebook.buck.java.classes.FileLikes.java
public static String getFileNameWithoutClassSuffix(FileLike fileLike) { Preconditions.checkNotNull(fileLike); String name = fileLike.getRelativePath(); return name.substring(0, name.length() - CLASS_NAME_SUFFIX.length()); }
From source file:xml.entity.mutableelement.Elements.java
/** * Match elements by name.//from w ww. j ava 2 s . co m */ public static Predicate<Element> byName(@Nonnull final String name) { Preconditions.checkNotNull(name); return new Predicate<Element>() { @Override public boolean apply(@Nonnull final Element input) { return name.equals(input.name()); } @Override public String toString() { return name; } }; }
From source file:com.google.template.soy.types.ListType.java
public static ListType of(SoyType elementType) { Preconditions.checkNotNull(elementType); return new ListType(elementType); }
From source file:com.cloudera.impala.catalog.HiveStorageDescriptorFactory.java
/** * Creates and returns a Hive StoreDescriptor for the given FileFormat and RowFormat. * Currently supports creating StorageDescriptors for Parquet, Text, Sequence, and * RC file.//www . j ava 2 s . c o m * TODO: Add support for HBase */ public static StorageDescriptor createSd(THdfsFileFormat fileFormat, RowFormat rowFormat) { Preconditions.checkNotNull(fileFormat); Preconditions.checkNotNull(rowFormat); StorageDescriptor sd = null; switch (fileFormat) { case PARQUET: sd = createParquetFileSd(); break; case RC_FILE: sd = createRcFileSd(); break; case SEQUENCE_FILE: sd = createSequenceFileSd(); break; case TEXT: sd = createTextSd(); break; case AVRO: sd = createAvroSd(); break; default: throw new UnsupportedOperationException("Unsupported file format: " + fileFormat); } if (rowFormat.getFieldDelimiter() != null) { sd.getSerdeInfo().putToParameters("serialization.format", rowFormat.getFieldDelimiter()); sd.getSerdeInfo().putToParameters("field.delim", rowFormat.getFieldDelimiter()); } if (rowFormat.getEscapeChar() != null) { sd.getSerdeInfo().putToParameters("escape.delim", rowFormat.getEscapeChar()); } if (rowFormat.getLineDelimiter() != null) { sd.getSerdeInfo().putToParameters("line.delim", rowFormat.getLineDelimiter()); } return sd; }
From source file:org.trancecode.collection.TcSets.java
public static <T> ImmutableSet<T> immutableSet(final Iterable<T> set, final T element) { Preconditions.checkNotNull(set); Preconditions.checkNotNull(element); if (set instanceof Set && ((Set<?>) set).contains(element)) { return ImmutableSet.copyOf(set); }/*from w ww. j a va2 s.c o m*/ final Builder<T> builder = ImmutableSet.builder(); return builder.addAll(set).add(element).build(); }
From source file:org.eclipse.buildship.core.util.file.RelativePathUtils.java
/** * Calculates the relative path from a base to a target path. * * @param base the base path to make the target path relative to * @param target the target file to which the relative path is calculated * @return the relative path from the base to the target location * @throws NullPointerException if an argument is {@code null} * @throws IllegalArgumentException if an argument does not denote an absolute path *///from w w w . j a v a 2s . c o m public static IPath getRelativePath(IPath base, IPath target) { Preconditions.checkNotNull(base); Preconditions.checkNotNull(target); Preconditions.checkArgument(base.isAbsolute()); Preconditions.checkArgument(target.isAbsolute()); return target.makeRelativeTo(base); }