本文整理了Java中org.nutz.lang.Lang.first()
方法的一些代码示例,展示了Lang.first()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Lang.first()
方法的具体详情如下:
包路径:org.nutz.lang.Lang
类名称:Lang
方法名:first
[英]如果是数组或集合取得第一个对象。 否则返回自身
[中]如果是数组或集合取得第一个对象。 否则返回自身
代码示例来源: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
public int update(final Object obj, String actived, String locked, boolean ignoreNull) {
Object first = Lang.first(obj);
if (null == first)
return 0;
return update(obj, FieldFilter.create(first.getClass(), actived, locked, ignoreNull));
}
代码示例来源:origin: nutzam/nutz
@SuppressWarnings("unchecked")
public Object get(ServletContext sc, HttpServletRequest req, HttpServletResponse resp, Object refer) {
if (refer == null)
return null;
Object obj = ((Map<String, Object>) refer).get(name);
if (obj == null || Lang.eleSize(obj) == 0)
return EMTRY;
if (Lang.eleSize(obj) == 1) {
Object tmp = Lang.first(obj);
if (tmp == null || !(tmp instanceof TempFile))
return EMTRY;
return new TempFile[]{(TempFile)tmp};
}
final List<TempFile> list = new ArrayList<TempFile>();
Lang.each(obj, new Each<Object>() {
public void invoke(int index, Object ele, int length) throws ExitLoop, ContinueLoop, LoopException {
if (ele instanceof TempFile) {
list.add((TempFile)ele);
}
}
});
if (list.isEmpty())
return EMTRY;
return list.toArray(new TempFile[list.size()]);
}
代码示例来源:origin: nutzam/nutz
public Pojo addUpdate(final Entity<?> en, final Object obj) {
if (null == en)
return null;
Pojo pojo = dao.pojoMaker.makeUpdate(en, null)
.append(Pojos.Items.cndAuto(en, Lang.first(obj)))
.setOperatingObject(obj);
pojoList.add(pojo);
return pojo;
}
代码示例来源:origin: nutzam/nutz
public int update(final Object obj, String actived) {
Object first = Lang.first(obj);
if (null == first)
return 0;
if (Strings.isBlank(actived))
return update(obj);
return update(obj, FieldFilter.create(first.getClass(), actived));
}
代码示例来源:origin: nutzam/nutz
public <T> T insertOrUpdate(T t, final FieldFilter insertFieldFilter, final FieldFilter updateFieldFilter) {
if (t == null)
return null;
Object obj = Lang.first(t);
final Entity<?> en = getEntity(obj.getClass());
Lang.each(t, new Each<Object>() {
代码示例来源:origin: nutzam/nutz
public <T> T insert(T obj, String actived) {
Object first = Lang.first(obj);
if (null == first)
return null;
if (Strings.isBlank(actived))
return insert(obj);
return insert(obj, FieldFilter.create(first.getClass(), actived));
}
代码示例来源:origin: nutzam/nutz
public int updateWithVersion(Object obj, FieldFilter fieldFilter) {
return updateAndIncrIfMatch(obj, fieldFilter, getEntity(Lang.first(obj).getClass()).getVersionField().getName());
}
代码示例来源:origin: nutzam/nutz
/**
* 根据一个对象获取实体
* <p>
* 对象如果是集合或者数组,则取其第一个元素进行判断
*
* @param obj
* 对象
* @return 实体
*/
@SuppressWarnings("unchecked")
public Entity<?> getEntityBy(Object obj) {
// 正常的构建一个 Entity
Object first = Lang.first(obj);
// 对象为空,不能构建实体
if (first == null)
return null;
// 这是一个 Map,试图构建一个 entity
if (first instanceof Map<?, ?>) {
Object tableName = ((Map<String, ?>) first).get(".table");
if (null == tableName)
throw Lang.makeThrow("Can not insert map without key '.table' : \n%s",
Json.toJson(first, JsonFormat.forLook()));
return makeEntity(tableName.toString(), (Map<String, ?>) first);
}
// 作为 POJO 构建
return getEntity(first.getClass());
}
代码示例来源:origin: nutzam/nutz
Object first = Lang.first(obj);
if (first != null && first instanceof Map) {
final Map<String, Object> tmp = new HashMap<String, Object>();
代码示例来源:origin: nutzam/nutz
Object first = Lang.first(value);
if (null == first)
return null;
代码示例来源:origin: nutzam/nutz
public <T> T insert(final T t, boolean ignoreNull, boolean ignoreZero, boolean ignoreBlankStr) {
Object obj = Lang.first(t);
Entity<?> en = getEntity(obj.getClass());
List<String> names = new ArrayList<String>();
for (MappingField mf : en.getMappingFields()) {
if (mf.isName() || mf.isPk() || mf.isId()) {
names.add(mf.getName());
continue;
}
Object tmp = mf.getValue(obj);
if (ignoreNull && tmp == null) {
continue;
}
if (ignoreZero && (tmp == null || (tmp instanceof Number && ((Number)tmp).intValue() == 0))) {
continue;
}
if (ignoreBlankStr && (tmp instanceof CharSequence && Strings.isBlank((CharSequence)tmp)))
continue;
names.add(mf.getName());
}
FieldFilter ff = FieldFilter.create(obj.getClass(), "^("+Strings.join("|", names.toArray())+")$");
Molecule<T> m = new Molecule<T>() {
public void run() {
insert(t);
setObj(t);
}
};
return ff.run(m);
}
代码示例来源:origin: nutzam/nutz
if (obj == null)
return false;
obj = Lang.first(obj);
if (obj == null) {
return false;
代码示例来源:origin: nutzam/nutz
public Pojo addUpdateAndIncrIfMatch(final Entity<?> en, final Object obj, String fieldName) {
if (null == en)
return null;
MappingField mf = en.getField(fieldName);
Pojo pojo = dao.pojoMaker.makeUpdate(en, null)
.append(new Static("," + mf.getColumnNameInSql() + "=" + mf.getColumnNameInSql() + "+1"))
.append(Pojos.Items.cndAuto(en, Lang.first(obj)))
.setOperatingObject(obj);
pojo.append(new Static("AND")).append(((AbstractPItem)Pojos.Items.cndColumn(mf, null)).setTop(false));
pojoList.add(pojo);
return pojo;
}
代码示例来源:origin: nutzam/nutz
public static List<MappingField> getFieldsForUpdate(Entity<?> en, FieldMatcher fm, Object refer) {
List<MappingField> re = new ArrayList<MappingField>(en.getMappingFields().size());
Object tmp = Lang.first(refer);
for (MappingField mf : en.getMappingFields()) {
if (mf.isPk()) {
if (en.getPkType() == PkType.ID && mf.isId())
continue;
if (en.getPkType() == PkType.NAME && mf.isName())
continue;
if (en.getPkType() == PkType.COMPOSITE && mf.isCompositePk())
continue;
}
if (mf.isReadonly() || mf.isAutoIncreasement() || !mf.isUpdate())
continue;
if (fm == null) {
re.add(mf);
}
else if (tmp == null) {
if (fm.match(mf.getName()))
re.add(mf);
}
else {
if (fm.match(mf, tmp))
re.add(mf);
}
}
if (re.isEmpty() && log.isDebugEnabled())
log.debug("none field for update!");
return re;
}
代码示例来源:origin: nutzam/nutz
public <T> T insert(final T obj) {
Object first = Lang.first(obj);
final EntityOperator opt = _optBy(first);
if (null == opt)
return null;
int size = Lang.eleSize(obj);
opt.addInsert(opt.entity, first);
if (size > 1) {
if (opt.getPojoListSize() == 1) {
// 单一操作,可以转为批量插入
return fastInsert(obj);
}
Lang.each(obj, false, new Each<Object>() {
public void invoke(int i, Object ele, int length) throws ExitLoop, LoopException {
if (i != 0)
opt.addInsert(opt.entity, ele);
}
});
}
opt.exec();
return obj;
}
代码示例来源:origin: nutzam/nutz
public Pojo addUpdateByPkAndCnd(final Entity<?> en, final Object obj, final Condition cnd) {
if (null == en)
return null;
Pojo pojo = dao.pojoMaker.makeUpdate(en, null);
boolean pureCnd = en.getPkType() == PkType.UNKNOWN;
if (!pureCnd) {
pojo.append(Pojos.Items.cndAuto(en, Lang.first(obj)));
pojo.append(new Static(" AND "));
}
if (cnd instanceof Criteria) {
// 只取它的where条件
pojo.append(((Criteria)cnd).where().setTop(pureCnd));
} else {
pojo.append(new ConditionPItem(cnd).setTop(pureCnd));
}
pojo.setOperatingObject(obj);
pojoList.add(pojo);
return pojo;
}
代码示例来源:origin: nutzam/nutz
public static PItem cndAuto(Entity<?> en, Object obj) {
obj = Lang.first(obj);
switch (en.getPkType()) {
case ID:
代码示例来源:origin: nutzam/nutz
Method m;
if (hasNullArg) {
m = (Method) Lang.first(mi.findMethods(ss[1],args.length));
if (m == null)
throw new IocException(ing.getObjectName(), "Factory method not found --> ", iobj.getFactory());
代码示例来源:origin: org.nutz/nutz
public Pojo addUpdateAndIncrIfMatch(final Entity<?> en, final Object obj, String fieldName) {
if (null == en)
return null;
MappingField mf = en.getField(fieldName);
Pojo pojo = dao.pojoMaker.makeUpdate(en, null)
.append(new Static("," + mf.getColumnNameInSql() + "=" + mf.getColumnNameInSql() + "+1"))
.append(Pojos.Items.cndAuto(en, Lang.first(obj)))
.setOperatingObject(obj);
pojo.append(new Static("AND")).append(((AbstractPItem)Pojos.Items.cndColumn(mf, null)).setTop(false));
pojoList.add(pojo);
return pojo;
}
内容来源于网络,如有侵权,请联系作者删除!