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


Java Required类代码示例

本文整理汇总了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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:69,代码来源:Backlink.java

示例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);
        }
    }
}
 
开发者ID:Zhuinden,项目名称:realm-helpers,代码行数:44,代码来源:RealmAutoMigration.java

示例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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:ClassMetaData.java


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