예제 #1
0
파일: Daos.java 프로젝트: GaoHuijian/nutz
  @SuppressWarnings({"unchecked", "rawtypes"})
  public static boolean filterFields(
      Object obj, FieldMatcher matcher, Dao dao, Callback2<MappingField, Object> callback) {
    if (obj == null) return false;
    obj = Lang.first(obj);
    if (obj == null) {
      return false;
    }
    if (obj.getClass() == Class.class) {
      throw Lang.impossible();
    }
    if (obj instanceof String || obj instanceof Number || obj instanceof Boolean) {
      throw Lang.impossible();
    }
    Entity en = dao.getEntity(obj.getClass());
    if (en == null) {
      throw Lang.impossible();
    }

    List<MappingField> mfs = en.getMappingFields();
    if (matcher != null) {
      Iterator<MappingField> it = mfs.iterator();
      while (it.hasNext()) {
        MappingField mf = it.next();
        if (!matcher.match(mf.getName())) it.remove();
      }
    }
    boolean flag = false;
    for (MappingField mf : mfs) {
      if (matcher.isIgnoreId() && mf.isId()) continue;
      if (matcher.isIgnoreName() && mf.isName()) continue;
      if (matcher.isIgnorePk() && mf.isCompositePk()) continue;
      Object val = mf.getValue(obj);
      if (val == null) {
        if (matcher.isIgnoreNull()) continue;
      }
      if (val instanceof Number && ((Number) val).doubleValue() == 0.0) {
        if (matcher.isIgnoreZero()) continue;
      }
      if (val instanceof Date) {
        if (matcher.isIgnoreDate()) continue;
      }
      callback.invoke(mf, val);
      flag = true;
    }
    return flag;
  }
예제 #2
0
파일: ParameterMod.java 프로젝트: naily/iph
  private Chain cov(Parameter pa, boolean ignoreNull) {
    FieldMatcher fm = FieldMatcher.make(null, "parameterID|ids|station$", ignoreNull);
    Chain ch = Chain.from(pa, fm);

    return ch;
  }