本文整理了Java中org.nutz.lang.Lang.isEmpty()
方法的一些代码示例,展示了Lang.isEmpty()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Lang.isEmpty()
方法的具体详情如下:
包路径:org.nutz.lang.Lang
类名称:Lang
方法名:isEmpty
[英]判断一个对象是否为空。它支持如下对象类型:
代码示例来源: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
/**
* 按长度截取字符串(尾部补足)
*
* @param length
* 长度
* @param s
* 字符串内容
* @param supply
* 补足内容
* @return 截断后的字符串
*/
public static String cutStr(int length, String s, String supply) {
if (Lang.isEmpty(length) || Lang.isEmpty(s))
return null;
else if (s.length() <= length)
return s;
else
return s.substring(0, length - 1) + supply;
}
代码示例来源:origin: nutzam/nutz
/**
* Date日期转Unix时间戳
*
* @param date 日期
* @return 时间戳
*/
public static long d2TS(Date date) {
if (Lang.isEmpty(date)) {
return getTS();
} else {
return date.getTime() / 1000;
}
}
}
代码示例来源: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
private Pojo distinct(Pojo pojo, String names) {
if (!Lang.isEmpty(names) && names.length() != 0) {
List<String> nameList = Arrays.asList(names.trim().split(","));
if (names.toLowerCase().contains(DISTINCT)) {
pojo.append(Pojos.Items.wrap(DISTINCT));
// distinct只能作用一个在一个字段上
// 做一个排序处理,把DISTINCT的字段移到第一个
for (int i = 0; i < nameList.size(); ++i) {
if (nameList.get(i).toLowerCase().contains(DISTINCT)) {
Collections.swap(nameList, 0, i);
// 为了让字段作为正则匹配到列,删除DINSTINCT
nameList.set(0, nameList.get(0).toLowerCase().replace(DISTINCT, "").toLowerCase());
break;
}
}
}
StringBuilder sb = new StringBuilder();
for (String name : nameList) {
sb.append(name.trim());
sb.append("|");
}
sb.setLength(sb.length() - 1);
pojo.getContext().setFieldMatcher(FieldMatcher.make(sb.toString(), null, true));
}
return pojo;
}
代码示例来源:origin: Rekoe/rk_svnadmin
protected int getPageNumber(Integer pageNumber) {
return Lang.isEmpty(pageNumber) ? 1 : pageNumber;
}
代码示例来源:origin: org.nutz/nutz
/**
* Date日期转Unix时间戳
*
* @param date 日期
* @return 时间戳
*/
public static long d2TS(Date date) {
if (Lang.isEmpty(date)) {
return getTS();
} else {
return date.getTime() / 1000;
}
}
}
代码示例来源:origin: Rekoe/rk_svnadmin
protected UserService getUserService() {
if (Lang.isEmpty(userService)) {
Ioc ioc = Mvcs.getIoc();
userService = ioc.get(UserService.class);
}
return userService;
}
代码示例来源:origin: Rekoe/rk_svnadmin
protected RoleService getRoleService() {
if (Lang.isEmpty(roleService)) {
Ioc ioc = Mvcs.getIoc();
roleService = ioc.get(RoleService.class);
}
return roleService;
}
代码示例来源:origin: Rekoe/rk_svnadmin
private Permission permission(List<Permission> pList, String wildcardString) {
if (Lang.isEmpty(pList)) {
return null;
}
for (Permission p : pList) {
String name = p.getName();
boolean isRight = Lang.equals(wildcardString, name);
if (isRight) {
return p;
}
}
return null;
}
代码示例来源:origin: Rekoe/rk_svnadmin
public boolean nameOk(String name) {
if (StringUtils.isBlank(name)) {
return false;
}
char[] chars = name.toCharArray();
for (char c : chars) {
if (Strings.isChineseCharacter(c)) {
return false;
}
}
return Lang.isEmpty(dao().fetch(getEntityClass(), Cnd.where("pj", "=", name)));
}
代码示例来源:origin: nutzam/nutzboot
protected void initFreeMarkerConfigurer() throws IOException, TemplateException {
String path = freemarkerDirectiveFactory.getFreemarker();
File file = Files.findFile(path);
if (!Lang.isEmpty(file)) {
Properties p = new Properties();
p.load(Streams.fileIn(file));
configuration.setSettings(p);
}
File f = Files.findFile(prefix);
if (f == null)
configuration.setClassForTemplateLoading(getClass(), prefix);
else
configuration.setDirectoryForTemplateLoading(f);
}
代码示例来源:origin: Rekoe/rk_svnadmin
public boolean nameOk(String name) {
if (StringUtils.isBlank(name)) {
return false;
}
if (!isUsername(name)) {
return false;
}
return Lang.isEmpty(dao().fetch(getEntityClass(), Cnd.where("usr", "=", name)));
}
代码示例来源:origin: Rekoe/rk_svnadmin
protected boolean isPermitted(String p) {
Subject subject = getSubject();
if (Lang.isEmpty(subject)) {
return false;
}
if (subject.getPrincipal() instanceof User) {
return getSubject().isPermitted(p);
}
return false;
}
代码示例来源:origin: Rekoe/rk_svnadmin
@At("/check/username")
@Ok("raw")
public boolean checkName(@Param("username") String username) {
return Lang.isEmpty(userService.fetchByName(username)) ? true : false;
}
代码示例来源:origin: Rekoe/rk_svnadmin
public void updateRoleRelation(Role role, List<Permission> perms) {
dao().clearLinks(role, "permissions");
role.getPermissions().clear();
dao().update(role);
if (!Lang.isEmpty(perms)) {
role.setPermissions(perms);
dao().insertRelation(role, "permissions");
}
}
代码示例来源:origin: Rekoe/rk_svnadmin
@At
@Ok("fm:template.front.account.create_user")
@RequiresAuthentication
public Object register(@Attr("me") User user) {
if (Lang.isEmpty(user) || user.isSystem()) {
return new ForwardView("/admin/common/unauthorized.rk");
}
return null;
}
}
代码示例来源:origin: Rekoe/rk_svnadmin
public User fetchByOpenID(String openid) {
User user = fetch(Cnd.where("openid", "=", openid));
if (!Lang.isEmpty(user) && !user.isLocked()) {
dao().fetchLinks(user, "servers");
dao().fetchLinks(user, "roles");
}
return user;
}
代码示例来源:origin: Rekoe/rk_svnadmin
@At
@Ok(">>:/admin/user/list")
@RequiresPermissions("system.user:add")
public Object save_user(@Param("::user.") User user, HttpServletRequest req) {
User selectUser = userService.fetchByName(user.getName());
if (Lang.isEmpty(selectUser)) {
userService.regist(user, DruidWebUtils.getRemoteAddr(req));
return Ajax.ok();
}
return Ajax.fail();
}
代码示例来源:origin: Rekoe/rk_svnadmin
@At
@Ok("json")
@RequiresPermissions("project.group:add")
public Message o_save(@Param("::pgu.") PjGr group, HttpServletRequest req) {
PjGr old = projectGroupService.fetch(Cnd.where("pj", "=", group.getPj()).and("gr", "=", group.getGr()));
if (Lang.isEmpty(old)) {
projectGroupService.insert(group);
return Message.success("ok", req);
}
return Message.error("error", req);
}
内容来源于网络,如有侵权,请联系作者删除!