org.nutz.lang.Lang.collection2array()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(6.8k)|赞(0)|评价(0)|浏览(131)

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

Lang.collection2array介绍

[英]将集合变成数组,数组的类型为集合的第一个元素的类型。如果集合为空,则返回 null
[中]

代码示例

代码示例来源:origin: nutzam/nutz

public Object get(ServletContext sc, HttpServletRequest req, HttpServletResponse resp, Object refer) {
  if (refer == null)
    return null;
  Object obj = ((Map<?, ?>) refer).get(name);
  if (obj == null)
    return null;
  if (obj instanceof List) {
    return Lang.collection2array((List<?>) ((List<?>) obj));
  }
  Object re = Array.newInstance(eleType, 1);
  Array.set(re, 0, obj);
  return re;
}

代码示例来源:origin: nutzam/nutz

@Override
public Object cast(Map src, Class<?> toType, String... args) throws FailToCastObjectException {
  return Lang.collection2array(src.values(), toType.getComponentType());
}

代码示例来源:origin: nutzam/nutz

/**
 * 将集合变成数组,数组的类型为集合的第一个元素的类型。如果集合为空,则返回 null
 *
 * @param coll
 *            集合对象
 * @return 数组
 */
@SuppressWarnings("unchecked")
public static <E> E[] collection2array(Collection<E> coll) {
  if (null == coll)
    return null;
  if (coll.size() == 0)
    return (E[]) new Object[0];
  Class<E> eleType = (Class<E>) Lang.first(coll).getClass();
  return collection2array(coll, eleType);
}

代码示例来源:origin: nutzam/nutz

/**
 * sql参数处理,在这里处理Array Collection类型参数,方便SQL IN 表达式的设置
 * 
 * @param params
 *            参数map,无参数时,可为null
 * 
 * @return 包含处理IN表达式的sql
 */
private Map<String, Object> paramProcess(Map<String, Object> params) {
  if (params == null || params.size() == 0)
    return null;
  Map<String, Object> newParams = new HashMap<String, Object>(params);
  for (Entry<String, Object> entry : params.entrySet()) {
    String paramName = entry.getKey();
    Object paramObj = entry.getValue();
    if (paramObj.getClass().isArray()) {
      inParamProcess(paramName, paramObj, newParams);
      newParams.remove(paramName);
    }
    if (paramObj instanceof Collection) {
      Collection<?> collection = (Collection<?>) paramObj;
      Object[] paramVals = Lang.collection2array(collection);
      inParamProcess(paramName, paramVals, newParams);
      newParams.remove(paramName);
    }
  }
  return newParams;
}

代码示例来源:origin: nutzam/nutz

/**
 * 将Array Collection类型参数对应的sql占位符进行处理
 * 
 * @param originSql
 *            原包含变量占位符的SQL
 * @param params
 *            参数map,无参数时,可为null
 * 
 * @return 包含处理IN表达式的sql
 */
private String sqlProcess(String originSql, Map<String, Object> params) {
  if (params == null || params.size() == 0)
    return originSql;
  String newSql = originSql;
  for (Entry<String, Object> entry : params.entrySet()) {
    String paramName = entry.getKey();
    Object paramObj = entry.getValue();
    if (paramObj.getClass().isArray()) {
      String inSqlExp = inSqlProcess(paramName, paramObj);
      newSql = newSql.replaceAll("@" + paramName, inSqlExp);
    }
    if (paramObj instanceof Collection) {
      Collection<?> collection = (Collection<?>) paramObj;
      Object[] paramVals = Lang.collection2array(collection);
      String inSqlExp = inSqlProcess(paramName, paramVals);
      newSql = newSql.replaceAll("@" + paramName, inSqlExp);
    }
  }
  return newSql;
}

代码示例来源:origin: nutzam/nutz

if (parent.meta.type.equals(this.method.getDeclaringClass().getName())) {
  String key = ClassMetaReader.getKey(this.method);
  this.paramNames = Lang.collection2array(parent.meta.paramNames.get(key), String.class);
  this.lineNumber = parent.meta.methodLines.get(key);

代码示例来源:origin: nutzam/nutz

public void init(Method method) {
  init(method, Lang.collection2array(MethodParamNamesScaner.getParamNames(method), String.class));
}

代码示例来源:origin: nutzam/nutz

return (T) Lang.collection2array(src.values(), toType.getComponentType());
      vv = Lang.collection2array(c, ft.getComponentType());

代码示例来源:origin: org.nutz/nutz

@Override
public Object cast(Map src, Class<?> toType, String... args) throws FailToCastObjectException {
  return Lang.collection2array(src.values(), toType.getComponentType());
}

代码示例来源:origin: org.nutz/nutz

public Object get(ServletContext sc, HttpServletRequest req, HttpServletResponse resp, Object refer) {
  if (refer == null)
    return null;
  Object obj = ((Map<?, ?>) refer).get(name);
  if (obj == null)
    return null;
  if (obj instanceof List) {
    return Lang.collection2array((List<?>) ((List<?>) obj));
  }
  Object re = Array.newInstance(eleType, 1);
  Array.set(re, 0, obj);
  return re;
}

代码示例来源:origin: org.nutz/nutz

/**
 * 将集合变成数组,数组的类型为集合的第一个元素的类型。如果集合为空,则返回 null
 *
 * @param coll
 *            集合对象
 * @return 数组
 */
@SuppressWarnings("unchecked")
public static <E> E[] collection2array(Collection<E> coll) {
  if (null == coll)
    return null;
  if (coll.size() == 0)
    return (E[]) new Object[0];
  Class<E> eleType = (Class<E>) Lang.first(coll).getClass();
  return collection2array(coll, eleType);
}

代码示例来源:origin: org.nutz/nutz

/**
 * sql参数处理,在这里处理Array Collection类型参数,方便SQL IN 表达式的设置
 * 
 * @param params
 *            参数map,无参数时,可为null
 * 
 * @return 包含处理IN表达式的sql
 */
private Map<String, Object> paramProcess(Map<String, Object> params) {
  if (params == null || params.size() == 0)
    return null;
  Map<String, Object> newParams = new HashMap<String, Object>(params);
  for (Entry<String, Object> entry : params.entrySet()) {
    String paramName = entry.getKey();
    Object paramObj = entry.getValue();
    if (paramObj.getClass().isArray()) {
      inParamProcess(paramName, paramObj, newParams);
      newParams.remove(paramName);
    }
    if (paramObj instanceof Collection) {
      Collection<?> collection = (Collection<?>) paramObj;
      Object[] paramVals = Lang.collection2array(collection);
      inParamProcess(paramName, paramVals, newParams);
      newParams.remove(paramName);
    }
  }
  return newParams;
}

代码示例来源:origin: org.nutz/nutz

public void init(Method method) {
  init(method, Lang.collection2array(MethodParamNamesScaner.getParamNames(method), String.class));
}

代码示例来源:origin: org.nutz/nutz

/**
 * 将Array Collection类型参数对应的sql占位符进行处理
 * 
 * @param originSql
 *            原包含变量占位符的SQL
 * @param params
 *            参数map,无参数时,可为null
 * 
 * @return 包含处理IN表达式的sql
 */
private String sqlProcess(String originSql, Map<String, Object> params) {
  if (params == null || params.size() == 0)
    return originSql;
  String newSql = originSql;
  for (Entry<String, Object> entry : params.entrySet()) {
    String paramName = entry.getKey();
    Object paramObj = entry.getValue();
    if (paramObj.getClass().isArray()) {
      String inSqlExp = inSqlProcess(paramName, paramObj);
      newSql = newSql.replaceAll("@" + paramName, inSqlExp);
    }
    if (paramObj instanceof Collection) {
      Collection<?> collection = (Collection<?>) paramObj;
      Object[] paramVals = Lang.collection2array(collection);
      String inSqlExp = inSqlProcess(paramName, paramVals);
      newSql = newSql.replaceAll("@" + paramName, inSqlExp);
    }
  }
  return newSql;
}

代码示例来源:origin: org.nutz/nutz

if (parent.meta.type.equals(this.method.getDeclaringClass().getName())) {
  String key = ClassMetaReader.getKey(this.method);
  this.paramNames = Lang.collection2array(parent.meta.paramNames.get(key), String.class);
  this.lineNumber = parent.meta.methodLines.get(key);

代码示例来源:origin: Rekoe/rk_svnadmin

public boolean mkdirs(String pj) {
  ProjectConfig conf = projectConfigService.get();
  List<String> dirs = conf.getDirs();
  return mkdirs(pj, Lang.collection2array(dirs));
}

代码示例来源:origin: org.nutz/nutz

return (T) Lang.collection2array(src.values(), toType.getComponentType());
      vv = Lang.collection2array(c, ft.getComponentType());

相关文章