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:br.com.objectos.comuns.relational.jdbc.ParamValue.java

public static ParamValue<?> valueOf(int index, Object value) {
    Preconditions.checkNotNull(value, "Cannot treat null values this way.");

    ParamValue<?> val; // so we never forget a if condition

    if (value instanceof BigDecimal) {
        val = new ParamBigDecimal(index, (BigDecimal) value);

    } else if (value instanceof Date) {
        val = new ParamDate(index, (Date) value);

    } else if (value instanceof DateTime) {
        val = new ParamDateTime(index, (DateTime) value);

    } else if (value instanceof Double) {
        val = new ParamDouble(index, (Double) value);

    } else if (value instanceof Float) {
        val = new ParamFloat(index, (Float) value);

    } else if (value instanceof Integer) {
        val = new ParamInt(index, (Integer) value);

    } else if (value instanceof LocalDate) {
        val = new ParamLocalDate(index, (LocalDate) value);

    } else if (value instanceof Long) {
        val = new ParamLong(index, (Long) value);

    } else if (value instanceof String) {
        val = new ParamString(index, (String) value);

    } else {//from  w  ww.  j  a v a  2s  .  c o  m
        throw new UnsupportedOperationException("Don't know how to treat typeof " + value.getClass());

    }

    return val;
}

From source file:net.awired.visuwall.plugin.hudson.States.java

public static final State asVisuwallState(String hudsonState) {
    Preconditions.checkNotNull(hudsonState, "hudsonState is mandatory");
    hudsonState = hudsonState.toLowerCase();
    State state = STATE_MAPPING.get(hudsonState);
    if (state == null) {
        state = State.UNKNOWN;
        LOG.warn(hudsonState + " is not available in Hudson plugin. Please report it to Visuwall dev team.");
    }//from  ww  w  . j a va 2s .co m
    return state;
}

From source file:org.zalando.crypto.Decrypters.java

public static List<Decrypter> findByPrefix(List<Decrypter> decrypters, String prefix) {
    Preconditions.checkNotNull(decrypters, "'Decrypter's-list should not be null");
    Preconditions.checkArgument(!Strings.isNullOrEmpty(prefix), "'prefix' should never be null or empty.");
    return Lists.newArrayList(Iterables.filter(decrypters,
            Predicates.and(new PrefixedDecrypterPredicate(), new PrefixPredicate(prefix))));
}

From source file:com.github.jcustenborder.kafka.connect.utils.config.TaskConfigs.java

/**
 * Method is used to generate a list of taskConfigs based on the supplied settings.
 *
 * @param settings//from w ww .j a v  a2s.  c  o m
 * @param taskCount
 * @return
 */
public static List<Map<String, String>> multiple(Map<String, String> settings, final int taskCount) {
    Preconditions.checkNotNull(settings, "settings cannot be null.");
    Preconditions.checkState(taskCount > 0, "taskCount must be greater than 0.");
    final List<Map<String, String>> result = new ArrayList<>(taskCount);
    for (int i = 0; i < taskCount; i++) {
        result.add(settings);
    }
    return ImmutableList.copyOf(result);
}

From source file:org.apache.james.mailbox.elasticsearch.json.EMailers.java

public static EMailers from(Set<EMailer> emailers) {
    Preconditions.checkNotNull(emailers, "'emailers' is mandatory");
    return new EMailers(emailers);
}

From source file:org.apache.james.mailbox.elasticsearch.json.Subjects.java

public static Subjects from(Set<String> subjects) {
    Preconditions.checkNotNull(subjects, "'subjects' is mandatory");
    return new Subjects(subjects);
}

From source file:com.google.security.zynamics.zylib.yfileswrap.yfiles.YHelpers.java

/**
 * Closes a group node./*from w  w  w .  ja va  2s  .  c o  m*/
 * 
 * @param graph The graph the group node belongs to.
 * @param groupNode The group node to be closed.
 */
public static void closeGroup(final Graph2D graph, final Node groupNode) {
    Preconditions.checkNotNull(graph, "Error: Graph argument can not be null");
    Preconditions.checkNotNull(groupNode, "Error: Group node argument can not be null");

    final HierarchyManager hierarchy = graph.getHierarchyManager();

    final double w = graph.getWidth(groupNode);
    final double h = graph.getHeight(groupNode);

    final NodeList groupNodes = new NodeList();
    groupNodes.add(groupNode);

    graph.firePreEvent();
    for (final NodeCursor nc = groupNodes.nodes(); nc.ok(); nc.next()) {
        hierarchy.closeGroup(nc.node());
    }
    graph.firePostEvent();

    // if the node size has changed, delete source ports of out-edges
    // and target ports of in-edges to ensure that all edges still connect
    // to the node
    if ((w != graph.getWidth(groupNode)) || (h != graph.getHeight(groupNode))) {
        for (final EdgeCursor ec = groupNode.outEdges(); ec.ok(); ec.next()) {
            graph.setSourcePointRel(ec.edge(), YPoint.ORIGIN);
        }
        for (final EdgeCursor ec = groupNode.inEdges(); ec.ok(); ec.next()) {
            graph.setTargetPointRel(ec.edge(), YPoint.ORIGIN);
        }
    }

    graph.updateViews();

}

From source file:io.druid.common.guava.MoreSequences.java

/**
 * Fixed version of {@link com.metamx.common.guava.Sequences#withBaggage(Sequence, Closeable)}, closes the baggage
 * after the yielder of the wrapped sequence.
 *///from  w  w w  .  ja  va 2s . com
public static <T> Sequence<T> withBaggage(Sequence<T> sequence, final Closeable baggage) {
    Preconditions.checkNotNull(baggage, "baggage");
    return wrap(sequence, new SequenceWrapper() {
        @Override
        public void open() {
            // do nothing
        }

        @Override
        public void close() {
            try {
                baggage.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    });
}

From source file:com.outerspacecat.openid.rp.AssociationType.java

/**
 * Returns whether or not {@code value} represents an association type.
 * /*ww  w  .  ja v  a2 s .  c o  m*/
 * @param value the value to test. Must be non {@code null}.
 * @return whether or not {@code value} represents an association type
 */
static boolean isValidValue(final String value) {
    Preconditions.checkNotNull(value, "value required");

    return value.equalsIgnoreCase(HMAC_SHA1.getValue()) || value.equalsIgnoreCase(HMAC_SHA256.getValue());
}

From source file:org.apache.apex.malhar.lib.utils.FileContextUtils.java

public static FileContext getFileContext(@NotNull String path) throws UnsupportedFileSystemException {
    Preconditions.checkNotNull(path, "path");
    return getFileContext(new Path(path), null);
}