本文整理汇总了Java中io.realm.annotations.Required类的典型用法代码示例。如果您正苦于以下问题:Java Required类的具体用法?Java Required怎么用?Java Required使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Required类属于io.realm.annotations包,在下文中一共展示了Required类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateSource
import io.realm.annotations.Required; //导入依赖的package包/类
/**
* Validate the source side of the backlink.
*
* @return true if the backlink source looks good.
*/
public boolean validateSource() {
// A @LinkingObjects cannot be @Required
if (backlink.getAnnotation(Required.class) != null) {
Utils.error(String.format(
Locale.US,
"The @LinkingObjects field \"%s.%s\" cannot be @Required.",
targetClass,
targetField));
return false;
}
// The annotation must have an argument, identifying the linked field
if ((sourceField == null) || sourceField.equals("")) {
Utils.error(String.format(
Locale.US,
"The @LinkingObjects annotation for the field \"%s.%s\" must have a parameter identifying the link target.",
targetClass,
targetField));
return false;
}
// Using link syntax to try to reference a linked field is not possible.
if (sourceField.contains(".")) {
Utils.error(String.format(
Locale.US,
"The parameter to the @LinkingObjects annotation for the field \"%s.%s\" contains a '.'. The use of '.' to specify fields in referenced classes is not supported.",
targetClass,
targetField));
return false;
}
// The annotated element must be a RealmResult
if (!Utils.isRealmResults(backlink)) {
Utils.error(String.format(
Locale.US,
"The field \"%s.%s\" is a \"%s\". Fields annotated with @LinkingObjects must be RealmResults.",
targetClass,
targetField,
backlink.asType()));
return false;
}
if (sourceClass == null) {
Utils.error(String.format(
Locale.US,
"\"The field \"%s.%s\", annotated with @LinkingObjects, must specify a generic type.",
targetClass,
targetField));
return false;
}
// A @LinkingObjects field must be final
if (!backlink.getModifiers().contains(Modifier.FINAL)) {
Utils.error(String.format(
Locale.US,
"A @LinkingObjects field \"%s.%s\" must be final.",
targetClass,
targetField));
return false;
}
return true;
}
示例2: matchMigratedField
import io.realm.annotations.Required; //导入依赖的package包/类
private static void matchMigratedField(RealmObjectSchema objectSchema, String modelFieldName, Field field) {
boolean isIndexed = false;
boolean isRequired = false;
boolean isPrimaryKey = false;
if(field.isAnnotationPresent(Index.class)) {
isIndexed = true;
}
if(field.isAnnotationPresent(Required.class)) {
isRequired = true;
}
if(field.isAnnotationPresent(PrimaryKey.class)) {
isPrimaryKey = true;
}
if(isPrimaryKey && !objectSchema.isPrimaryKey(modelFieldName)) {
if(objectSchema.hasPrimaryKey()) {
objectSchema.removePrimaryKey();
}
objectSchema.addPrimaryKey(modelFieldName);
}
if(!isPrimaryKey && objectSchema.isPrimaryKey(modelFieldName)) {
objectSchema.removePrimaryKey();
}
// index management must be after primary key because removePrimaryKey() removes index as well.
if((isIndexed || isPrimaryKey) && !objectSchema.hasIndex(modelFieldName)) {
objectSchema.addIndex(modelFieldName);
}
if(!isIndexed && !isPrimaryKey /* primary key is indexed by default! */ && objectSchema.hasIndex(modelFieldName)) {
objectSchema.removeIndex(modelFieldName);
}
if(isNonNullPrimitive(field.getType())) {
if(!objectSchema.isRequired(modelFieldName)) {
objectSchema.setNullable(modelFieldName, false);
}
} else {
if(isRequired && objectSchema.isNullable(modelFieldName)) {
objectSchema.setNullable(modelFieldName, false);
}
if(!isRequired && !objectSchema.isNullable(modelFieldName)) {
objectSchema.setNullable(modelFieldName, true);
}
}
}
示例3: hasRequiredAnnotation
import io.realm.annotations.Required; //导入依赖的package包/类
/**
* This method only checks if the field has {@code @Required} annotation.
* In most cases, you should use {@link #isRequiredField(VariableElement)} to take into account
* Kotlin's annotation as well.
*
* @param field target field.
* @return {@code true} if the field has {@code @Required} annotation, {@code false} otherwise.
* @see #isRequiredField(VariableElement)
*/
private boolean hasRequiredAnnotation(VariableElement field) {
return field.getAnnotation(Required.class) != null;
}