当前位置: 首页>>代码示例>>Java>>正文


Java Parent类代码示例

本文整理汇总了Java中com.googlecode.objectify.annotation.Parent的典型用法代码示例。如果您正苦于以下问题:Java Parent类的具体用法?Java Parent怎么用?Java Parent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Parent类属于com.googlecode.objectify.annotation包,在下文中一共展示了Parent类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getParentType

import com.googlecode.objectify.annotation.Parent; //导入依赖的package包/类
private Class<?> getParentType(Class<?> clazz) {
  for (; clazz != null; clazz = clazz.getSuperclass()) {
    for (Field field : clazz.getDeclaredFields()) {
      if (field.isAnnotationPresent(Parent.class)) {
        try {
          return getSystemClassLoader().loadClass(
              ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0]
                  .toString()
                  .replace("? extends ", "")
                  .replace("class ", ""));
        } catch (ClassNotFoundException e) {
          throw new RuntimeException(e);
        }
      }
    }
  }
  return Object.class;
}
 
开发者ID:google,项目名称:nomulus,代码行数:19,代码来源:GetSchemaTreeCommand.java

示例2: getSchema

import com.googlecode.objectify.annotation.Parent; //导入依赖的package包/类
/** Return a string representing the persisted schema of a type or enum. */
static String getSchema(Class<?> clazz) {
  StringBuilder stringBuilder = new StringBuilder();
  Stream<?> body;
  if (clazz.isEnum()) {
    stringBuilder.append("enum ");
    body = Arrays.stream(clazz.getEnumConstants());
  } else {
    stringBuilder.append("class ");
    body =
        getAllFields(clazz)
            .values()
            .stream()
            .filter(field -> !field.isAnnotationPresent(Ignore.class))
            .map(
                field -> {
                  String annotation =
                      field.isAnnotationPresent(Id.class)
                          ? "@Id "
                          : field.isAnnotationPresent(Parent.class) ? "@Parent " : "";
                  String type =
                      field.getType().isArray()
                          ? field.getType().getComponentType().getName() + "[]"
                          : field.getGenericType().toString().replaceFirst("class ", "");
                  return String.format("%s%s %s", annotation, type, field.getName());
                });
  }
  return stringBuilder
      .append(clazz.getName())
      .append(" {\n  ")
      .append(body.map(Object::toString).sorted().collect(Collectors.joining(";\n  ")))
      .append(";\n}")
      .toString();
}
 
开发者ID:google,项目名称:nomulus,代码行数:35,代码来源:ModelUtils.java

示例3: getAllPotentiallyIndexedFieldPaths

import com.googlecode.objectify.annotation.Parent; //导入依赖的package包/类
/** List all field paths so we can verify that we checked everything. */
private Set<String> getAllPotentiallyIndexedFieldPaths(Class<?> clazz) {
  Set<String> fields = Sets.newHashSet();
  for (; clazz != Object.class; clazz = clazz.getSuperclass()) {
    for (final Field field : clazz.getDeclaredFields()) {
      // Ignore static, @Serialize, @Parent and @Ignore fields, since these are never indexed.
      if (!Modifier.isStatic(field.getModifiers())
          && !field.isAnnotationPresent(Ignore.class)
          && !field.isAnnotationPresent(Parent.class)
          && !field.isAnnotationPresent(Serialize.class)) {
        Class<?> fieldClass = field.getType();
        // If the field is a collection, just pretend that it was a field of that type,
        // because verifyIndexingHelper knows how to descend into collections.
        if (Collection.class.isAssignableFrom(fieldClass)) {
          Type inner = ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0];
          fieldClass = inner instanceof ParameterizedType
              ? (Class<?>) ((ParameterizedType) inner).getRawType()
              : (Class<?>) inner;
        }
        // Descend into persisted ImmutableObject classes, but not anything else.
        if (ImmutableObject.class.isAssignableFrom(fieldClass)) {
          getAllPotentiallyIndexedFieldPaths(fieldClass)
              .stream()
              .map(subfield -> field.getName() + "." + subfield)
              .distinct()
              .forEachOrdered(fields::add);
        } else {
          fields.add(field.getName());
        }
      }
    }
  }
  return fields;
}
 
开发者ID:google,项目名称:nomulus,代码行数:35,代码来源:EntityTestCase.java


注:本文中的com.googlecode.objectify.annotation.Parent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。