org.javalite.common.Util.empty()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(10.7k)|赞(0)|评价(0)|浏览(235)

本文整理了Java中org.javalite.common.Util.empty()方法的一些代码示例,展示了Util.empty()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.empty()方法的具体详情如下:
包路径:org.javalite.common.Util
类名称:Util
方法名:empty

Util.empty介绍

[英]Returns true if collection is either null or empty.
[中]如果集合为null或空,则返回true。

代码示例

代码示例来源:origin: javalite/activejdbc

/**
 * Joins the items in array with a delimiter, and appends the result to StringBuilder.
 *
 * @param sb StringBuilder to append result to
 * @param array array of items to join.
 * @param delimiter delimiter to insert between elements of array.
 */
public static void join(StringBuilder sb, Object[] array, String delimiter) {
  if (empty(array)) { return; }
  sb.append(array[0]);
  for (int i = 1; i < array.length; i++) {
    sb.append(delimiter);
    sb.append(array[i]);
  }
}

代码示例来源:origin: javalite/activejdbc

/**
 * Joins the items in array with a delimiter.
 *
 * @param array array of items to join.
 * @param delimiter delimiter to insert between elements of array.
 * @return string with array elements separated by delimiter. There is no trailing delimiter in the string.
 */
public static String join(String[] array, String delimiter) {
  if (empty(array)) { return ""; }
  StringBuilder sb = new StringBuilder();
  join(sb, array, delimiter);
  return sb.toString();
}

代码示例来源:origin: javalite/activejdbc

/**
 * Looks for a localized property/message in <code>activejdbc_messages</code> bundle.
 *
 * @param key key of the property.
 * @param locale locale of a bundle, or null for default locale
 * @param params list of parameters for a message. The order of parameters in this list will correspond to the
 * numeric order in the parameters listed in the message and has nothing to do with a physical order. This means
 * that the first parameter in the list will correspond to <code>{0}</code>, second to <code>{1}</code> and so on.
 * @return localized  message merged with parameters (if provided), or key if message not found.
 */
public static String message(String key, Locale locale, Object... params) {
  String pattern;
  try {
    pattern = ResourceBundle.getBundle(BUNDLE, locale == null ? Locale.getDefault() : locale).getString(key);
  } catch (MissingResourceException e) {
    pattern = key;
  }
  return empty(params) ? pattern : new MessageFormat(pattern).format(params);
}

代码示例来源:origin: javalite/activejdbc

public static <T extends Model> LazyList<T> where(Class<T> clazz, String subquery, Object... params) {
  if (subquery.trim().equals("*")) {
    if (empty(params)) {
      return findAll(clazz);
    } else {
      throw new IllegalArgumentException(
          "cannot provide parameters with query: '*', use findAll() method instead");
    }
  }
  return new LazyList<>(subquery, metaModelOf(clazz), params);
}

代码示例来源:origin: javalite/activejdbc

if (pretty) { sb.append('\n'); }
String[] names = !empty(attributeNames) ? attributeNames : attributeNamesLowerCased();
for (String name : names) {
  if (pretty) { sb.append("  ").append(indent); }

代码示例来源:origin: javalite/activejdbc

/**
 * Runs a count query, returns a number of matching records.
 *
 * @param table table in which to count rows.
 * @param query this is a filtering query for the count. If '*' provided, all records will be counted. Example:
 * <code>"age > 65 AND department = 'accounting'"</code>
 * @param params parameters for placeholder substitution.
 * @return count number of records found in a table.
 */
public Long count(String table, String query, Object... params) {
  if (query.trim().equals("*")) {
    if (empty(params)) {
      return count(table);
    } else {
      throw new IllegalArgumentException("cannot use '*' and parameters");
    }
  }
  String sql = "SELECT COUNT(*) FROM " + table + " WHERE " + query;
  return Convert.toLong(firstCell(sql, params));
}

代码示例来源:origin: javalite/activejdbc

sb.append('{');
String[] names = !empty(attributeNames) ? attributeNames : attributeNamesLowerCased();
for (int i = 0; i < names.length; i++) {
  if (i > 0) { sb.append(','); }

代码示例来源:origin: org.javalite/javalite-common

/**
 * Joins the items in array with a delimiter, and appends the result to StringBuilder.
 *
 * @param sb StringBuilder to append result to
 * @param array array of items to join.
 * @param delimiter delimiter to insert between elements of array.
 */
public static void join(StringBuilder sb, Object[] array, String delimiter) {
  if (empty(array)) { return; }
  sb.append(array[0]);
  for (int i = 1; i < array.length; i++) {
    sb.append(delimiter);
    sb.append(array[i]);
  }
}

代码示例来源:origin: com.github.tchoulihan/javalite-common

/**
 * Joins the items in array with a delimiter, and appends the result to StringBuilder.
 *
 * @param sb StringBuilder to append result to
 * @param array array of items to join.
 * @param delimiter delimiter to insert between elements of array.
 */
public static void join(StringBuilder sb, Object[] array, String delimiter) {
  if (empty(array)) { return; }
  sb.append(array[0]);
  for (int i = 1; i < array.length; i++) {
    sb.append(delimiter);
    sb.append(array[i]);
  }
}

代码示例来源:origin: org.javalite/activejdbc

/**
 * Looks for a localized property/message in <code>activejdbc_messages</code> bundle.
 *
 * @param key key of the property.
 * @param locale locale of a bundle, or null for default locale
 * @param params list of parameters for a message. The order of parameters in this list will correspond to the
 * numeric order in the parameters listed in the message and has nothing to do with a physical order. This means
 * that the first parameter in the list will correspond to <code>{0}</code>, second to <code>{1}</code> and so on.
 * @return localized  message merged with parameters (if provided), or key if message not found.
 */
public static String message(String key, Locale locale, Object... params) {
  String pattern;
  try {
    pattern = ResourceBundle.getBundle(BUNDLE, locale == null ? Locale.getDefault() : locale).getString(key);
  } catch (MissingResourceException e) {
    pattern = key;
  }
  return empty(params) ? pattern : new MessageFormat(pattern).format(params);
}

代码示例来源:origin: com.github.tchoulihan/activejdbc

/**
 * Looks for a localized property/message in <code>activejdbc_messages</code> bundle.
 *
 * @param key key of the property.
 * @param locale locale of a bundle, or null for default locale
 * @param params list of parameters for a message. The order of parameters in this list will correspond to the
 * numeric order in the parameters listed in the message and has nothing to do with a physical order. This means
 * that the first parameter in the list will correspond to <code>{0}</code>, second to <code>{1}</code> and so on.
 * @return localized  message merged with parameters (if provided), or key if message not found.
 */
public static String message(String key, Locale locale, Object... params) {
  String pattern;
  try {
    pattern = ResourceBundle.getBundle(BUNDLE, locale == null ? Locale.getDefault() : locale).getString(key);
  } catch (MissingResourceException e) {
    pattern = key;
  }
  return empty(params) ? pattern : new MessageFormat(pattern).format(params);
}

代码示例来源:origin: org.javalite/javalite-common

/**
 * Joins the items in array with a delimiter.
 *
 * @param array array of items to join.
 * @param delimiter delimiter to insert between elements of array.
 * @return string with array elements separated by delimiter. There is no trailing delimiter in the string.
 */
public static String join(String[] array, String delimiter) {
  if (empty(array)) { return ""; }
  StringBuilder sb = new StringBuilder();
  join(sb, array, delimiter);
  return sb.toString();
}

代码示例来源:origin: com.github.tchoulihan/activejdbc

static void logAccess(String query, Object[] params, String access) {
  if (logger.isInfoEnabled()) {
    StringBuilder log = new StringBuilder().append(access).append(", ").append('"').append(query).append('"');
    if (!empty(params)) {
      log.append(", with parameters: ").append('<');
      join(log, params, ">, <");
      log.append('>');
    }
    LogFilter.log(logger, log.toString());
  }
}

代码示例来源:origin: com.github.tchoulihan/javalite-common

/**
 * Joins the items in array with a delimiter.
 *
 * @param array array of items to join.
 * @param delimiter delimiter to insert between elements of array.
 * @return string with array elements separated by delimiter. There is no trailing delimiter in the string.
 */
public static String join(String[] array, String delimiter) {
  if (empty(array)) { return ""; }
  StringBuilder sb = new StringBuilder();
  join(sb, array, delimiter);
  return sb.toString();
}

代码示例来源:origin: org.javalite/activejdbc

public static <T extends Model> LazyList<T> where(Class<T> clazz, String subquery, Object... params) {
  if (subquery.trim().equals("*")) {
    if (empty(params)) {
      return findAll(clazz);
    } else {
      throw new IllegalArgumentException(
          "cannot provide parameters with query: '*', use findAll() method instead");
    }
  }
  return new LazyList<>(subquery, metaModelOf(clazz), params);
}

代码示例来源:origin: com.github.tchoulihan/activejdbc

public static <T extends Model> LazyList<T> where(Class<T> clazz, String subquery, Object... params) {
  if (subquery.trim().equals("*")) {
    if (empty(params)) {
      return findAll(clazz);
    } else {
      throw new IllegalArgumentException(
          "cannot provide parameters with query: '*', use findAll() method instead");
    }
  }
  return new LazyList<T>(subquery, metaModelOf(clazz), params);
}

代码示例来源:origin: com.github.tchoulihan/activejdbc

/**
 * Runs a count query, returns a number of matching records.
 *
 * @param table table in which to count rows.
 * @param query this is a filtering query for the count. If '*' provided, all records will be counted. Example:
 * <code>"age > 65 AND department = 'accounting'"</code>
 * @param params parameters for placeholder substitution.
 * @return count number of records found in a table.
 */
public Long count(String table, String query, Object... params) {
  if (query.trim().equals("*")) {
    if (empty(params)) {
      return count(table);
    } else {
      throw new IllegalArgumentException("cannot use '*' and parameters");
    }
  }
  String sql = "SELECT COUNT(*) FROM " + table + " WHERE " + query;
  return Convert.toLong(firstCell(sql, params));
}

代码示例来源:origin: org.javalite/activejdbc

/**
 * Runs a count query, returns a number of matching records.
 *
 * @param table table in which to count rows.
 * @param query this is a filtering query for the count. If '*' provided, all records will be counted. Example:
 * <code>"age > 65 AND department = 'accounting'"</code>
 * @param params parameters for placeholder substitution.
 * @return count number of records found in a table.
 */
public Long count(String table, String query, Object... params) {
  if (query.trim().equals("*")) {
    if (empty(params)) {
      return count(table);
    } else {
      throw new IllegalArgumentException("cannot use '*' and parameters");
    }
  }
  String sql = "SELECT COUNT(*) FROM " + table + " WHERE " + query;
  return Convert.toLong(firstCell(sql, params));
}

代码示例来源:origin: com.github.tchoulihan/activejdbc

if (pretty) { sb.append('\n'); }
String[] names = !empty(attributeNames) ? attributeNames : attributeNamesLowerCased();
for (String name : names) {
  if (pretty) { sb.append("  ").append(indent); }

代码示例来源:origin: com.github.tchoulihan/activejdbc

static void logQuery(Logger logger, String query, Object[] params, long queryStartTime){
  long time = System.currentTimeMillis() - queryStartTime;
  if (Registry.instance().getConfiguration().collectStatistics()) {
    Registry.instance().getStatisticsQueue().enqueue(new QueryExecutionEvent(query, time));
  }
  if (logger.isInfoEnabled()) {
    StringBuilder log =  new StringBuilder().append("Query: \"").append(query).append('"');
    if (!empty(params)) {
      log.append(", with parameters: ").append('<');
      join(log, params, ">, <");
      log.append('>');
    }
    log(logger, log.append(", took: ").append(time).append(" milliseconds").toString());
  }
}

相关文章