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.sk89q.guavabackport.cache.MoreObjects.java

public static <T> T firstNonNull(@Nullable final T first, @Nullable final T second) {
    return (T) ((first != null) ? first : Preconditions.checkNotNull((Object) second));
}

From source file:com.palantir.atlasdb.keyvalue.partition.endpoint.KeyValueEndpoints.java

public static String makeUniqueRackIfNoneSpecified(String rack) {
    if (PartitionedKeyValueConstants.NO_RACK.equals(rack)) {
        return UUID.randomUUID().toString();
    }/*from ww  w  .j a  v a2  s .c o m*/
    return Preconditions.checkNotNull(rack);
}

From source file:com.palantir.lock.ByteArrayLockDescriptor.java

/** Returns a {@code LockDescriptor} instance for the given lock ID. */
public static LockDescriptor of(byte[] bytes) {
    Preconditions.checkNotNull(bytes);
    return new LockDescriptor(bytes.clone());
}

From source file:com.dangdang.config.service.support.spring.ConfigGroupSourceFactory.java

public static PropertySources create(ConfigGroup... configGroups) {
    Preconditions.checkNotNull(configGroups);
    final MutablePropertySources sources = new MutablePropertySources();
    for (ConfigGroup configGroup : configGroups) {
        sources.addLast(new ConfigGroupResource(configGroup));
    }// w w  w . j  a va 2  s . com
    return sources;
}

From source file:cosmos.options.Order.java

public static String direction(Order o) {
    Preconditions.checkNotNull(o);

    return Order.ASCENDING.equals(o) ? FORWARD : REVERSE;
}

From source file:qa.qcri.qnoise.util.CSVTools.java

/**
 * Loads CSV file into database.//from w w  w .ja  v  a  2  s. c o  m
 * @param file CSV file path.
 * @param dbConfig DB connection config.
 * @param tableName target import table name.
 * @param delimiter CSV delimiter.
 * @return the number of bytes loaded into the target database.
 */
public static int load(String file, DBConfig dbConfig, String tableName, char delimiter) throws Exception {
    Preconditions.checkNotNull(dbConfig);
    Preconditions.checkNotNull(file);

    Connection conn = null;
    Statement stat = null;
    BufferedReader reader = null;
    int result = 0;
    try {
        conn = DBTools.createConnection(dbConfig, true);
        stat = conn.createStatement();
        if (DBTools.existTable(dbConfig, tableName)) {
            stat.executeUpdate("DROP TABLE " + tableName);
        }

        // create table based on the header
        reader = new BufferedReader(new FileReader(file));
        String header = reader.readLine();
        if (!Strings.isNullOrEmpty(header)) {
            String[] columns = header.split(Character.toString(delimiter));
            StringBuilder schemaSql = new StringBuilder("CREATE TABLE " + tableName + " (");
            boolean isFirst = true;
            for (String column : columns) {
                if (!isFirst) {
                    schemaSql.append(",");
                }
                isFirst = false;
                schemaSql.append(column).append(" VARCHAR(10240) ");
            }
            schemaSql.append(")");
            stat.execute(schemaSql.toString());

            SQLDialect dialect = dbConfig.getDialect();
            SQLDialectBase dialectBase = SQLDialectBase.createDialectBaseInstance(dialect);
            if (dialectBase.supportBulkLoad()) {
                result = dialectBase.bulkLoad(dbConfig, tableName, file, delimiter);
            } else {
                throw new UnsupportedOperationException("Non-bulk loading is not yet implemented.");
            }
        }
    } finally {
        try {
            if (stat != null) {
                stat.close();
            }

            if (conn != null) {
                conn.close();
            }

            if (reader != null) {
                reader.close();
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    return result;
}

From source file:com.ninjas.movietime.core.util.StringUtils.java

@SneakyThrows(UnsupportedEncodingException.class)
public static String encode(final String toEncode) {
    Preconditions.checkNotNull(toEncode);
    return URLEncoder.encode(toEncode, "UTF-8");
}

From source file:com.facebook.buck.java.classes.FileLikes.java

public static boolean isClassFile(FileLike fileLike) {
    Preconditions.checkNotNull(fileLike);
    return fileLike.getRelativePath().endsWith(CLASS_NAME_SUFFIX);
}

From source file:com.chenchengzhi.windtalkers.core.Issue.java

public static Issue of(StatusCode statusCode, String className, String methodName, String reason) {
    Preconditions.checkNotNull(statusCode);
    Preconditions.checkNotNull(className);
    Preconditions.checkNotNull(methodName);
    Preconditions.checkNotNull(reason);//from  w ww  .  j  av a2 s .  c o m
    Issue issue = new Issue(statusCode);
    issue.className = className;
    issue.methodName = methodName;
    issue.reason = reason;
    return issue;
}

From source file:com.github.fommil.ff.physics.Aftertouch.java

static DVector3 asVector(Collection<Aftertouch> touches) {
    Preconditions.checkNotNull(touches);
    DVector3 aftertouch = new DVector3();
    for (Aftertouch touch : touches) {
        assert touch != null;
        switch (touch) {
        case UP:/* w  w  w. j a v  a  2 s  .  c  o m*/
            aftertouch.add(0, 1, 0);
            break;
        case DOWN:
            aftertouch.sub(0, 1, 0);
            break;
        case LEFT:
            aftertouch.sub(1, 0, 0);
            break;
        case RIGHT:
            aftertouch.add(1, 0, 0);
            break;
        }
    }
    if (aftertouch.length() > 0) {
        aftertouch.normalize();
    }
    return aftertouch;
}