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, @Nullable Object errorMessage) 

Source Link

Document

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

Usage

From source file:monasca.common.util.Exceptions.java

/** Throw <b>any</b> exception as a RuntimeException. */
public static RuntimeException sneakyThrow(Throwable throwable) {
    Preconditions.checkNotNull(throwable, "throwable");
    Exceptions.<RuntimeException>sneakyThrow0(throwable);
    return null;// ww w . ja v a 2  s  . co  m
}

From source file:de.cosmocode.collections.Procedures.java

/**
 * Chains multiple {@link Procedure}s together into a single one.
 * //from  w w w.  jav  a 2s.c  o  m
 * @param <T> the generic procedure type
 * @param first the first procedure
 * @param second the second procedure
 * @param rest the rest
 * @return a {@link Procedure} containing all given {@link Procedure}
 * @throws NullPointerException if any parameter is null
 */
public static <T> Procedure<T> chain(final Procedure<? super T> first, final Procedure<? super T> second,
        final Iterable<? extends Procedure<? super T>> rest) {
    Preconditions.checkNotNull(first, "First");
    Preconditions.checkNotNull(second, "Second");
    Preconditions.checkNotNull(rest, "Rest");
    return new Procedure<T>() {

        @Override
        public void apply(T input) {
            first.apply(input);
            second.apply(input);
            for (Procedure<? super T> procedure : rest) {
                procedure.apply(input);
            }
        }

    };
}

From source file:pt.ua.ri.utils.Divisions.java

public static int countExistingDivisions(final Path indexDir) throws IOException {
    Preconditions.checkNotNull(indexDir, "Directory Path cannot be null");
    return (int) Files.walk(indexDir, 1).filter(Files::isRegularFile).filter(pathMatcher::matches).count();
}

From source file:com.google.security.zynamics.zylib.gml.GmlConverter.java

/**
 * Creates GML code that represents a given directed graph.
 * //from w  w w.  j a  v  a 2 s . co  m
 * @param graph The input graph.
 * 
 * @return The code generated for the input graph.
 */
public static String toGml(final IDirectedGraph<?, ? extends IGraphEdge<?>> graph) {
    Preconditions.checkNotNull(graph, "Graph argument can not be null");

    final StringBuilder sb = new StringBuilder();

    sb.append("graph\n" + "[\n");

    int currentId = 0;

    final Map<Object, Integer> nodeMap = new HashMap<>();

    for (final Object node : graph.getNodes()) {
        sb.append("\tnode\n" + "\t[\n" + "\tid " + "\n");
        sb.append(currentId);
        sb.append("\tlabel \"");
        sb.append(node);
        sb.append("\"\n" + "\t]\n");

        nodeMap.put(node, currentId);

        ++currentId;
    }

    for (final IGraphEdge<?> edge : graph.getEdges()) {
        sb.append("\tedge\n" + "\t[\n" + "\tsource ");
        sb.append(nodeMap.get(edge.getSource()));
        sb.append("\n" + "\ttarget ");
        sb.append(nodeMap.get(edge.getTarget()));
        sb.append("\n" + "\tgraphics\n" + "\t[\n" + "\t\tfill \"#000000\"\n" + "\t\ttargetArrow \"standard\"\n"
                + "\t]\n" + "\t]\n");
    }

    sb.append("]\n");

    return sb.toString();
}

From source file:io.crate.sql.tree.QualifiedName.java

public static QualifiedName of(String first, String... rest) {
    Preconditions.checkNotNull(first, "first is null");
    return new QualifiedName(ImmutableList.copyOf(Lists.asList(first, rest)));
}

From source file:de.cosmocode.palava.ipc.netty.ChannelBuffering.java

/**
 * Adapts a {@link ChannelBuffer} to an {@link InputStream}.
 * /*from w  ww  .  ja v a 2s . c  om*/
 * @deprecated use {@link ChannelBufferInputStream}
 * @param buffer the underlying channel buffer
 * @return an inputstream which reads from the given channel buffer
 * @throws NullPointerException if buffer is null
 */
@Deprecated
public static InputStream asInputStream(final ChannelBuffer buffer) {
    Preconditions.checkNotNull(buffer, "Buffer");
    return new ChannelBufferInputStream(buffer);
}

From source file:com.supaham.commons.bukkit.PlayerTeleportFix.java

private static PlayersSupplierFor<Player> getPlayerTrackingRange(Plugin plugin) {
    Preconditions.checkNotNull(plugin, "plugin cannot be null.");
    final Server server = plugin.getServer();
    // TODO support spigot
    final double radius = server.getViewDistance() * 16;

    // The following is a playersByRadius wrapper that passes the given player's location
    return new PlayersSupplierFor<Player>() {
        PlayersSupplierFor<Location> delegate = Players.playersByRadius(null, radius);

        @Override//from  w ww. java 2s.c  om
        public Collection<Player> get(Player player) {
            return delegate.get(player.getLocation());
        }
    };
}

From source file:de.cosmocode.palava.ipc.xml.rpc.adapters.Adapters.java

/**
 * Adapts the specified adapter to the {@link Function} interface using {@link Adapter#decode(Object)}.
 * /*from ww w.ja  va  2 s  . c o  m*/
 * @since 1.0
 * @param <F> source type
 * @param <T> target type
 * @param adapter the backing adapter
 * @return a function using the decode method of the given adapter
 * @throws NullPointerException if adapter is null
 */
public static <F, T> Function<F, T> asDecoder(final Adapter<? super F, ? extends T> adapter) {
    Preconditions.checkNotNull(adapter, "Adapter");
    return new Function<F, T>() {

        @Override
        public T apply(F from) {
            return adapter.decode(from);
        }

        @Override
        public String toString() {
            return String.format("Adapters.asDecoder(%s)", adapter);
        }

    };
}

From source file:org.kitesdk.data.spi.filesystem.FileSystemUtil.java

/**
 * Creates, if necessary, the given the location for {@code descriptor}.
 *
 * @param conf A Configuration/*from ww  w .j a v  a2  s.c om*/
 * @param descriptor A DatasetDescriptor
 * @throws DatasetIOException
 * @since 0.13.0
 */
public static void ensureLocationExists(DatasetDescriptor descriptor, Configuration conf) {
    Preconditions.checkNotNull(descriptor.getLocation(),
            "Cannot get FileSystem for a descriptor with no location");

    Path dataPath = new Path(descriptor.getLocation());
    FileSystem fs = null;

    try {
        fs = dataPath.getFileSystem(conf);
    } catch (IOException e) {
        throw new DatasetIOException("Cannot get FileSystem for descriptor: " + descriptor, e);
    }

    try {
        if (!fs.exists(dataPath)) {
            fs.mkdirs(dataPath);
        }
    } catch (IOException e) {
        throw new DatasetIOException("Cannot access data location", e);
    }
}

From source file:com.outerspacecat.cassandra.Cassandra.java

/**
 * Creates a list of mutations based on {@code columns}.
 * /*  w w w . ja  v a  2  s.c  om*/
 * @param columns the columns to update. Must be non {@code null}, all
 *        elements must be non {@code null}, may be empty.
 * @return a list of mutations. Never {@code null}.
 */
public static ImmutableList<Mutation> mutations(final Column... columns) {
    Preconditions.checkNotNull(columns, "columns required");
    for (Column column : columns)
        Preconditions.checkNotNull(column, "all columns must be non null");

    ImmutableList.Builder<Mutation> b = ImmutableList.builder();
    for (Column c : columns)
        b.add(new Mutation().setColumn_or_supercolumn(new ColumnOrSuperColumn().setColumn(c)));
    return b.build();
}