Example usage for com.google.common.base Preconditions checkNotNull

List of usage examples for com.google.common.base Preconditions checkNotNull

Introduction

In this page you can find the example usage for com.google.common.base Preconditions checkNotNull.

Prototype

public static <T> T checkNotNull(T reference) 

Source Link

Document

Ensures that an object reference passed as a parameter to the calling method is not null.

Usage

From source file:com.turn.griffin.utils.GriffinConfig.java

public static String getProperty(String propertyName) {
    Preconditions.checkNotNull(propertyName);
    if (properties == null) {
        init();/*from w  w w  . ja  v  a2  s.c o m*/
    }
    return properties.getProperty(propertyName);
}

From source file:com.google.appengine.tools.mapreduce.ConfigurationXmlUtil.java

/**
 * Reconstitutes a Configuration from an XML string.
 *
 * @param serializedConf an XML document in Hadoop configuration format
 * @return the Configuration corresponding to the XML
 *///from  www. j a va2s . co m
public static Configuration getConfigurationFromXml(String serializedConf) {
    Preconditions.checkNotNull(serializedConf);

    try {
        byte[] serializedConfBytes = serializedConf.getBytes("UTF8");
        ByteArrayInputStream serializedConfStream = new ByteArrayInputStream(serializedConfBytes);

        // false makes Configuration not try to read defaults from the filesystem.
        Configuration conf = new Configuration(false);
        conf.addResource(serializedConfStream);
        return conf;
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException("JDK doesn't understand UTF8", e);
    }
}

From source file:com.isotrol.impe3.api.Name.java

/**
 * Returns a new content type with specified id and localized name.
 * @param displayName Display name./*from w  w  w.jav  a  2 s .c om*/
 * @param path Path segment.
 * @return The requested content type.
 */
public static Name of(final String displayName, final String path) {
    Preconditions.checkNotNull(displayName);
    return new Name(displayName, path);
}

From source file:com.visural.common.collection.FluentLists.java

public static <T> T remove(List<T> list, int index) {
    Preconditions.checkNotNull(list);
    index = basicAdjustIndex(index, list);
    return list.remove(index);
}

From source file:com.facebook.buck.parser.PartialGraphFactory.java

/**
 * Creates a PartialGraph via dependency injection.
 * <p>//from  w  w w  . j  a va  2  s .co  m
 * Normally, a PartialGraph is created via factory methods that ensure the integrity of the
 * PartialGraph by construction. This factory is used for tests, so it sidesteps the integrity
 * checks. Therefore, it is the responsibility of the caller to ensure that the graph is a
 * DependencyGraph built from the list of targets.
 */
public static PartialGraph newInstance(DependencyGraph graph, List<BuildTarget> targets) {
    Preconditions.checkNotNull(graph);
    Preconditions.checkNotNull(targets);
    return new PartialGraph(graph, targets);
}

From source file:edu.byu.nlp.math.RealVectors.java

/**
 * Adds vector a to b and stores the results in a.
 * //from w  w  w. j  a  va  2 s.  c o m
 * @throws NullPointerException if a or b are null 
 */
public static void addToSelf(RealVector a, RealVector b) {
    Preconditions.checkNotNull(a);
    Preconditions.checkNotNull(b);
    if (a.getDimension() != b.getDimension()) {
        throw new DimensionMismatchException(b.getDimension(), a.getDimension());
    }

    a.combineToSelf(1.0, 1.0, b);
}

From source file:com.android.builder.core.BootClasspathBuilder.java

@NonNull
public static ImmutableList<File> computeFullBootClasspath(@NonNull IAndroidTarget target,
        @NonNull File annotationsJar) {
    Preconditions.checkNotNull(target);
    Preconditions.checkNotNull(annotationsJar);

    ImmutableList.Builder<File> classpath = ImmutableList.builder();

    for (String p : target.getBootClasspath()) {
        classpath.add(new File(p));
    }//from   w  w  w . java 2s.  c  om

    // add additional libraries if any
    List<IAndroidTarget.OptionalLibrary> libs = target.getAdditionalLibraries();
    for (IAndroidTarget.OptionalLibrary lib : libs) {
        File jar = lib.getJar();
        Verify.verify(jar != null, "Jar missing from additional library %s.", lib.getName());
        classpath.add(jar);
    }

    // add optional libraries if any
    List<IAndroidTarget.OptionalLibrary> optionalLibraries = target.getOptionalLibraries();
    for (IAndroidTarget.OptionalLibrary lib : optionalLibraries) {
        File jar = lib.getJar();
        Verify.verify(jar != null, "Jar missing from optional library %s.", lib.getName());
        classpath.add(jar);
    }

    // add annotations.jar if needed.
    if (target.getVersion().getApiLevel() <= 15) {
        classpath.add(annotationsJar);
    }

    return classpath.build();
}

From source file:io.github.msdk.util.MsSpectrumUtil.java

/**
 * Returns the m/z range of given data points. Can return null if the data
 * point list is empty./*from w w w  .j a  va  2 s  .c  o  m*/
 *
 * @return a {@link com.google.common.collect.Range} object.
 * @param mzValues
 *            an array of double.
 * @param size
 *            a {@link java.lang.Integer} object.
 */
@Nullable
public static Range<Double> getMzRange(@Nonnull double mzValues[], @Nonnull Integer size) {

    // Parameter check
    Preconditions.checkNotNull(mzValues);
    Preconditions.checkNotNull(size);
    Preconditions.checkPositionIndex(size, mzValues.length);

    if (size == 0)
        return null;

    double min = mzValues[0];
    double max = mzValues[size - 1];
    return Range.closed(min, max);
}

From source file:org.janusgraph.hadoop.config.ModifiableHadoopConfiguration.java

public static ModifiableHadoopConfiguration of(ConfigNamespace root, Configuration c) {
    Preconditions.checkNotNull(c);
    return new ModifiableHadoopConfiguration(root, c, Restriction.NONE);
}

From source file:com.google.caliper.memory.Chain.java

static Chain root(Object value) {
    return new Chain(null, Preconditions.checkNotNull(value)) {
        @Override//from w ww. j  a  va  2 s.co  m
        public Class<?> getValueType() {
            return getValue().getClass();
        }
    };
}