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:io.druid.query.Queries.java

public static void verifyAggregations(List<AggregatorFactory> aggFactories, List<PostAggregator> postAggs) {
    Preconditions.checkNotNull(aggFactories, "aggregations cannot be null");
    Preconditions.checkArgument(aggFactories.size() > 0, "Must have at least one AggregatorFactory");

    final Set<String> aggNames = Sets.newHashSet();
    for (AggregatorFactory aggFactory : aggFactories) {
        Preconditions.checkArgument(aggNames.add(aggFactory.getName()), "[%s] already defined",
                aggFactory.getName());/*from   w  w  w  . j  a v a2s.  com*/
    }

    if (postAggs != null && !postAggs.isEmpty()) {
        final Set<String> combinedAggNames = Sets.newHashSet(aggNames);

        for (PostAggregator postAgg : postAggs) {
            final Set<String> dependencies = postAgg.getDependentFields();
            final Set<String> missing = Sets.difference(dependencies, combinedAggNames);

            Preconditions.checkArgument(missing.isEmpty(), "Missing fields [%s] for postAggregator [%s]",
                    missing, postAgg.getName());
            Preconditions.checkArgument(combinedAggNames.add(postAgg.getName()), "[%s] already defined");
        }
    }
}

From source file:com.google.security.zynamics.zylib.date.DateHelpers.java

public static String formatDate(final Date date) {
    Preconditions.checkNotNull(date, "Error: Date argument can't be null.");

    return DateFormat.getDateInstance().format(date);
}

From source file:app.philm.in.util.ColorValueAnimator.java

public static ValueAnimator start(final View rootView, final int[] current, final int[] target,
        final int duration, final OnColorSetListener listener) {

    Preconditions.checkNotNull(rootView, "rootView cannot be null");
    Preconditions.checkNotNull(current, "current cannot be null");
    Preconditions.checkNotNull(target, "target cannot be null");
    Preconditions.checkArgument(current.length == target.length, "current and target must be the same length");

    if (rootView.getDrawingTime() <= 0) {
        listener.onUpdateColor(target);//from   w  ww . j  a v  a2s .  c  o  m
        return null;
    }

    final int[] colors = new int[target.length];

    ValueAnimator animator = new ValueAnimator();
    animator.setFloatValues(0f, 1f);
    animator.setDuration(duration);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            final float currentValue = 1f - (Float) valueAnimator.getAnimatedValue();

            for (int i = 0, z = colors.length; i < z; i++) {
                colors[i] = ColorUtils.blendColors(current[i], target[i], currentValue);
            }

            listener.onUpdateColor(colors);
        }
    });
    animator.start();

    return animator;
}

From source file:io.druid.indexing.common.task.TaskLabels.java

@Nullable
public static String getTaskLabel(Task task) {
    Preconditions.checkNotNull(task, "task");
    Map<String, Object> context = task.getContext();
    Object taskLabel = (context != null) ? context.get(TASK_LABEL_FIELD) : null;
    return taskLabel == null ? null : (String) taskLabel;
}

From source file:org.rpmcomparator.service.ValidatorUtil.java

/**
 * @param fileName/*from  w  ww .  j  a v a 2  s.co m*/
 * @return
 * @throws IOException,RuntimeException
 */
public static File getValideFile(String fileName) {
    File file = new File(Preconditions.checkNotNull(fileName, "Give file cannot be null"));
    Preconditions.checkArgument(file.exists(), "Give file:" + fileName + "Should exist");
    return file;
}

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

/**
 * Method will create a single from the supplied settings.
 *
 * @param settings/*from www  . j  a v  a2s . c  o m*/
 * @return
 */
public static List<Map<String, String>> single(Map<String, String> settings) {
    Preconditions.checkNotNull(settings, "settings cannot be null.");
    return ImmutableList.of(settings);
}

From source file:com.google.cloud.tools.eclipse.appengine.validation.AppEngineWebBlacklist.java

static String getBlacklistElementMessage(String element) {
    Preconditions.checkNotNull(element, "element is null");
    if (!BLACKLIST.containsKey(element)) {
        throw new IllegalArgumentException("element not in blacklist");
    }//from   w  w  w  . j  a  v  a2 s.  c om
    return BLACKLIST.get(element);
}

From source file:com.zaradai.kunzite.optimizer.model.RowSchema.java

public static RowSchema newInstance(InputRowSchema inputRowSchema, OutputRowSchema outputRowSchema) {
    Preconditions.checkNotNull(inputRowSchema, "Invalid Input schema specified");
    Preconditions.checkNotNull(outputRowSchema, "Invalid Output schema specified");

    return new RowSchema(inputRowSchema, outputRowSchema);
}

From source file:com.zaradai.kunzite.optimizer.model.Row.java

public static Row newInstance(InputRow inputRow, OutputRow outputRow) {
    Preconditions.checkNotNull(inputRow, "Invalid input specified");
    Preconditions.checkNotNull(outputRow, "Invalid output specified");

    Row res = new Row();
    res.setInput(inputRow);/*from   w  ww . java2 s. co m*/
    res.setOutput(outputRow);

    return res;
}

From source file:com.zaradai.kunzite.optimizer.model.InputSpec.java

public static InputSpec newInstance(int position, Series series) {
    Preconditions.checkArgument(position >= 0, "Invalid input position specified");
    Preconditions.checkNotNull(series, "Invalid Series supplied");

    return new InputSpec(position, series);
}