org.nutz.lang.Lang类的使用及代码示例

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

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

Lang介绍

[英]这些帮助函数让 Java 的某些常用功能变得更简单
[中]这些帮助函数让 JAVA的某些常用功能变得更简单

代码示例

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

public Object get(ServletContext sc,
         HttpServletRequest req,
         HttpServletResponse resp,
         Object refer) {
  try {
    return req.getReader();
  }
  catch (IOException e) {
    throw Lang.wrapThrow(e);
  }
}

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

public void invoke(Method m) {
    throw Lang.makeThrow(JsonException.class,
               "JsonField '%s' should be getter/setter pair!",
               m);
  }
};

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

public List<MappingField> getPks() {
  if (null != theId)
    return Lang.list(theId);
  if (null != theName)
    return Lang.list(theName);
  return theComposites;
}

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

/**
 * 根据一段 JSON 字符串,生产一个新的上下文对象
 *
 * @return 一个新创建的上下文对象
 */
public static Context context(String str) {
  return context(map(str));
}

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

@Override
public Map cast(Collection src, Class<?> toType, String... args)
    throws FailToCastObjectException {
  if (null == args || args.length == 0)
    throw Lang.makeThrow(    FailToCastObjectException.class,
                "For the elements in Collection %s, castors don't know which one is the key field.",
                src.getClass().getName());
  return Lang.collection2map((Class<Map<Object, Object>>) toType, src, args[0]);
}

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

@Override
public Map cast(Object src, Class<?> toType, String... args) throws FailToCastObjectException {
  if (null == args || args.length == 0)
    throw Lang.makeThrow(    FailToCastObjectException.class,
                "For the elements in array %s[], castors don't know which one is the key field.",
                src.getClass().getComponentType().getName());
  return Lang.array2map((Class<Map<Object, Object>>) toType, src, args[0]);
}

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

Map<String, Object> map = Lang.map(ti.annMeta.value());
  for (Entry<String, Object> entry : map.entrySet()) {
    en.getMetas().put(entry.getKey(), entry.getValue().toString());
  throw Lang.makeThrow(IllegalArgumentException.class,
             "Pojo(%s) without any Mapping Field!!",
             type);
} catch (Throwable e) {
  holder.remove(en);
  throw Lang.wrapThrow(e);

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

/**
   * 获取指定字符串的 HmacMD5 值
   *
   * @param data   字符串
   * @param secret 密钥
   * @return 指定字符串的 HmacMD5 值
   */
  public static String hmacmd5(String data, String secret) {
    if (isEmpty(data))
      throw new NullPointerException("data is null");
    if (isEmpty(secret))
      throw new NullPointerException("secret is null");
    byte[] bytes = null;
    try {
      SecretKey secretKey = new SecretKeySpec(secret.getBytes(Encoding.UTF8), "HmacMD5");
      Mac mac = Mac.getInstance(secretKey.getAlgorithm());
      mac.init(secretKey);
      bytes = mac.doFinal(data.getBytes(Encoding.UTF8));
    } catch (Exception e) {
      e.printStackTrace();
      throw Lang.wrapThrow(e);
    }
    return fixedHexString(bytes);
  }
}

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

/**
 * 当所有字段增加完成,这个方法必须被调用,用来搜索复合主键
 * 
 * @param names
 *            复合主键的 Java 字段名数组
 */
public void checkCompositeFields(String[] names) {
  if (!Lang.isEmptyArray(names) && names.length > 1) {
    for (String name : names) {
      if (byJava.containsKey(name) && byJava.get(name).isCompositePk())
        theComposites.add(byJava.get(name));
      else
        throw Lang.makeThrow("Fail to find comosite field '%s' in class '%s'!",
                   name,
                   type.getName());
    }
    this.pkType = PkType.COMPOSITE;
  } else if (null != this.theId) {
    this.pkType = PkType.ID;
  } else if (null != this.theName) {
    this.pkType = PkType.NAME;
  }
}

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

public void addCastor(Class<?> klass) {
  try {
    fillMap(klass, settingMap, true);
  }
  catch (Throwable e) {
    throw Lang.wrapThrow(Lang.unwrapThrow(e));
  }
}

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

/**
 * 判断一个对象是否不为空。它支持如下对象类型:
 * <ul>
 * <li>null : 一定为空
 * <li>数组
 * <li>集合
 * <li>Map
 * <li>其他对象 : 一定不为空
 * </ul>
 *
 * @param obj
 *            任意对象
 * @return 是否为空
 */
public static boolean isNotEmpty(Object obj) {
  return !isEmpty(obj);
}

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

@Override
  public int doEndTag() throws JspException {
    // 得到 Message 对象
    NutMessageMap nmm = Mvcs.getMessageMap(pageContext.getRequest());

    // 准备上下文
    String body = this.getBodyContent().getString();
    NutMap map;
    if (!Strings.isBlank(body))
      map = Lang.map(body);
    else
      map = null;

    // 得到字符串
    String str = nmm.get(key, map);

    // 输出
    try {
      pageContext.getOut().write(str);
    }
    catch (IOException e) {
      throw Lang.wrapThrow(e);
    }

    return TagSupport.EVAL_PAGE;
  }
}

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

@Override
@SuppressWarnings("unchecked")
public <T> List<T> getList(String key, final Class<T> eleType, List<T> dft) {
  Object v = get(key);
  if (null == v)
    return dft;
  if (v instanceof CharSequence) {
    return Lang.list(Castors.me().castTo(v, eleType));
  }
  int len = Lang.eleSize(v);
  final List<T> list = new ArrayList<T>(len);
  Lang.each(v, new Each<Object>() {
    @Override
    public void invoke(int index, Object ele, int length) {
      list.add(Castors.me().castTo(ele, eleType));
    }
  });
  return list;
}

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

public static boolean isAnnotationExists(Method method,
                     Class<? extends Annotation>... classes) {
  if (!Lang.isEmptyArray(classes)) {
    for (Class<? extends Annotation> klass : classes) {
      if (getAnnotationDeep(method, klass) != null)
        return true;
    }
  }
  return false;
}

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

public DaoInterceptor makeInterceptor(Object it) {
  if (it == null)
    return null;
  if (it instanceof String) {
    String itName = it.toString().trim();
    if ("log".equals(itName)) {
      return new DaoLogInterceptor();
    }
    else if ("time".equals(itName)) {
      return new DaoTimeInterceptor();
    } 
    else if (itName.contains(".")) {
      Class<?> klass = Lang.loadClassQuite(itName);
      if (klass == null) {
        log.warn("no such interceptor name="+itName);
      } else {
        return (DaoInterceptor) Mirror.me(klass).born();
      }
    } else {
      log.info("unkown interceptor name="+itName);
    }
  }
  else if (it instanceof DaoInterceptor) {
    return (DaoInterceptor) it;
  } else {
    log.info("unkown interceptor -> "+it);
  }
  return null;
}

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

/**
 * 根据一个格式化字符串,生成 Map 对象
 *
 * @param fmt
 *            格式化字符串
 * @param args
 *            字符串参数
 * @return Map 对象
 */
public static NutMap mapf(String fmt, Object... args) {
  return map(String.format(fmt, args));
}

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

public <T> T fetchLinks(final T obj, final String regex, final Condition cnd) {
  if (null == obj)
    return null;
  Lang.each(obj, false, new Each<Object>() {
    public void invoke(int index, Object ele, int length) {
      _fetchLinks(ele, regex, true, true, true, cnd);
    }
  });
  return obj;
}

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

public static void fromRemote(PropertiesProxy conf, String fileName) {
  for (int i = 0; i < 5; i++) {
    for (String host : props.hosts) {
      boolean re = bySimple(conf, host, fileName);
      if (re)
        return;
      Lang.quiteSleep(1000);
    }
  }
  throw new RuntimeException("can't fetch config from remote : " + fileName);
}

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

public void update(long uid, String password, boolean isLocked, Integer[] ids) {
  User user = fetch(uid);
  dao().clearLinks(user, "roles");
  if (!Lang.isEmptyArray(ids)) {
    user.setRoles(dao().query(Role.class, Cnd.where("id", "in", ids)));
  }
  if (StringUtils.isNotBlank(password)) {
    String salt = new SecureRandomNumberGenerator().nextBytes().toBase64();
    user.setSalt(salt);
    user.setPassword(new Sha256Hash(password, salt, 1024).toBase64());
  }
  user.setLocked(isLocked);
  dao().update(user);
  if (!Lang.isEmpty(user.getRoles())) {
    dao().insertRelation(user, "roles");
  }
}

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

@Override
@SuppressWarnings("unchecked")
public <T> T[] getArray(String key, final Class<T> eleType, T[] dft) {
  Object v = get(key);
  if (null == v)
    return dft;
  if (v instanceof CharSequence) {
    return Lang.array(Castors.me().castTo(v, eleType));
  }
  int len = Lang.eleSize(v);
  final Object arr = Array.newInstance(eleType, len);
  final int[] i = new int[]{0};
  Lang.each(v, new Each<Object>() {
    @Override
    public void invoke(int index, Object ele, int length) {
      Array.set(arr, i[0]++, Castors.me().castTo(ele, eleType));
    }
  });
  return (T[]) arr;
}

相关文章