本文整理汇总了Java中com.googlecode.objectify.annotation.Ignore类的典型用法代码示例。如果您正苦于以下问题:Java Ignore类的具体用法?Java Ignore怎么用?Java Ignore使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Ignore类属于com.googlecode.objectify.annotation包,在下文中一共展示了Ignore类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSchema
import com.googlecode.objectify.annotation.Ignore; //导入依赖的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();
}
示例2: getPersistedFieldTypes
import com.googlecode.objectify.annotation.Ignore; //导入依赖的package包/类
/**
* Returns the set of Class objects of all persisted fields. This includes the parameterized
* type(s) of any fields (if any).
*/
static Set<Class<?>> getPersistedFieldTypes(Class<?> clazz) {
ImmutableSet.Builder<Class<?>> builder = new ImmutableSet.Builder<>();
for (Field field : getAllFields(clazz).values()) {
// Skip fields that aren't persisted to Datastore.
if (field.isAnnotationPresent(Ignore.class)) {
continue;
}
// If the field's type is the same as the field's class object, then it's a non-parameterized
// type, and thus we just add it directly. We also don't bother looking at the parameterized
// types of Key objects, since they are just references to other objects and don't actually
// embed themselves in the persisted object anyway.
Class<?> fieldClazz = field.getType();
Type fieldType = field.getGenericType();
builder.add(fieldClazz);
if (fieldType.equals(fieldClazz) || Key.class.equals(clazz)) {
continue;
}
// If the field is a parameterized type, then also add the parameterized field.
if (fieldType instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) fieldType;
for (Type actualType : parameterizedType.getActualTypeArguments()) {
if (actualType instanceof Class<?>) {
builder.add((Class<?>) actualType);
} else {
// We intentionally ignore types that are parameterized on non-concrete types. In theory
// we could have collections embedded within collections, but Objectify does not allow
// that.
}
}
}
}
return builder.build();
}
示例3: getAllPotentiallyIndexedFieldPaths
import com.googlecode.objectify.annotation.Ignore; //导入依赖的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;
}