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.onboard.service.account.redis.KeyUtils.java

public static String userToken(String type, Integer uid) {
    Preconditions.checkNotNull(type);
    Preconditions.checkNotNull(uid);/*ww w.j a v  a 2s  .c  om*/
    return String.format("account:%s:%d", type, uid);
}

From source file:com.sk89q.guavabackport.cache.RemovalListeners.java

public static <K, V> RemovalListener<K, V> asynchronous(final RemovalListener<K, V> listener,
        final Executor executor) {
    Preconditions.checkNotNull((Object) listener);
    Preconditions.checkNotNull((Object) executor);
    return new RemovalListener<K, V>() {
        @Override//from w w  w . j a  v a  2 s  .co m
        public void onRemoval(final RemovalNotification<K, V> notification) {
            executor.execute(new Runnable() {
                @Override
                public void run() {
                    listener.onRemoval(notification);
                }
            });
        }
    };
}

From source file:edu.byu.nlp.math.optimize.ConvergenceCheckers.java

public static ConvergenceChecker or(final ConvergenceChecker a, final ConvergenceChecker b) {
    Preconditions.checkNotNull(a);
    Preconditions.checkNotNull(b);//from  w ww  .j  a  v a2  s  .  co  m
    return new ConvergenceChecker() {

        @Override
        public boolean isConverged(int iteration, double prev, double cur) {
            return a.isConverged(iteration, prev, cur) || b.isConverged(iteration, prev, cur);
        }

    };
}

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

public static <T> List<T> set(List<T> list, int index, T element) {
    Preconditions.checkNotNull(list);
    index = basicAdjustIndex(index, list);
    list.set(index, element);//w  w w  .  java2  s .c  o  m
    return list;
}

From source file:com.kamesuta.mc.signpic.asm.lib.VisitorHelper.java

public static byte[] apply(final byte[] bytes, final String name, final TransformProvider context) {
    Preconditions.checkNotNull(bytes);
    final ClassReader cr = new ClassReader(bytes);
    final ClassWriter cw = new ClassWriter(cr, context.flags);
    final ClassVisitor mod = context.createVisitor(name, cw);

    try {/*from w w w  .  j  a  v a2s . co m*/
        cr.accept(mod, 0);
        return cw.toByteArray();
    } catch (final StopTransforming e) {
        return bytes;
    }
}

From source file:aeon.compiler.generators.CodeBlocks.java

public static CodeBlock checkNotNull(@NotNull final String varName) {
    Preconditions.checkNotNull(varName);

    return CodeBlock.builder().addStatement("$T.$L($L)", Utils.class, "checkNotNull", varName).build();
}

From source file:eu.thebluemountain.customers.dctm.brownbag.badcontentslister.CSVWriter.java

static CSVWriter create(PrintWriter printer, char separator) {
    Preconditions.checkNotNull(printer);
    return new CSVWriter(printer, separator);
}

From source file:com.turn.splicer.tsdbutils.expression.Expressions.java

public static ExpressionTree parse(String expr, List<String> metricQueries, TsQuery dataQuery) {
    Preconditions.checkNotNull(expr);
    if (expr.indexOf('(') == -1 || expr.indexOf(')') == -1) {
        throw new RuntimeException("Invalid Expression: " + expr);
    }//from w w  w  . j  a v a  2s .  c  om

    ExprReader reader = new ExprReader(expr.toCharArray());
    reader.skipWhitespaces();

    String funcName = reader.readFuncName();
    Expression rootExpr = ExpressionFactory.getByName(funcName);
    if (rootExpr == null) {
        throw new RuntimeException("Could not find evaluator " + "for function '" + funcName + "'");
    }

    ExpressionTree root = new ExpressionTree(rootExpr, dataQuery);

    reader.skipWhitespaces();
    if (reader.peek() == '(') {
        reader.next();
        parse(reader, metricQueries, root, dataQuery);
    }

    return root;
}

From source file:org.mifos.sdk.internal.ParseUtil.java

/**
 * Parses a date to a particular format and returns the formatted {@link String}.
 * @param date the {@link Date} to parse
 * @param dateFormat the date format//w w w.j a v a2  s . c o  m
 * @param lang the language/locale
 * @return a date {@link String} formatted according to the date format and locale
 */
public static String parseDateToString(final Date date, final String dateFormat, final String lang) {
    Preconditions.checkNotNull(date);
    Preconditions.checkNotNull(dateFormat);
    Preconditions.checkNotNull(lang);

    final Locale locale = new Locale(lang);
    final SimpleDateFormat format = new SimpleDateFormat(dateFormat, locale);

    return format.format(date);
}

From source file:com.twitter.hbc.twitter4j.CreateEvent.java

public static JSONObject createEvent(String eventName, String target, String source,
        @Nullable String targetObject) throws JSONException {

    Preconditions.checkNotNull(eventName);
    Preconditions.checkNotNull(target);/*from  w w  w.  j a  va 2 s  .  c om*/
    Preconditions.checkNotNull(source);
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("event", eventName);
    map.put("target", new JSONObject(target));
    map.put("source", new JSONObject(source));
    if (targetObject != null) {
        map.put("target_object", new JSONObject(targetObject));
    }
    return new JSONObject(map);
}