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


Java Presence类代码示例

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


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

示例1: MessageInfo

import com.google.ipc.invalidation.common.ProtoValidator.FieldInfo.Presence; //导入依赖的package包/类
/**
 * Constructs a message info.
 *
 * @param messageAccessor descriptor for the protocol buffer
 * @param fields information about the fields
 */
public MessageInfo(Accessor messageAccessor, FieldInfo... fields) {
  // Track which fields in the message descriptor have not yet been covered by a FieldInfo.
  // We'll use this to verify that we get a FieldInfo for every field.
  Set<String> unusedDescriptors = new HashSet<String>();
  unusedDescriptors.addAll(messageAccessor.getAllFieldNames());

  this.messageAccessor = messageAccessor;
  for (FieldInfo info : fields) {
    // Lookup the field given the name in the FieldInfo.
    boolean removed = TypedUtil.remove(unusedDescriptors, info.getFieldDescriptor().getName());
    Preconditions.checkState(removed, "Bad field: %s", info.getFieldDescriptor().getName());

    // Add the field info to the number -> info map.
    fieldInfo.add(info);

    if (info.getPresence() == Presence.REQUIRED) {
      ++numRequiredFields;
    }
  }
  Preconditions.checkState(unusedDescriptors.isEmpty(), "Not all fields specified in %s: %s",
      messageAccessor, unusedDescriptors);
}
 
开发者ID:morristech,项目名称:android-chromium,代码行数:29,代码来源:ProtoValidator.java

示例2: checkMessage

import com.google.ipc.invalidation.common.ProtoValidator.FieldInfo.Presence; //导入依赖的package包/类
/**
 * Returns whether {@code message} is valid.
 * @param messageInfo specification of validity for {@code message}
 */

protected boolean checkMessage(MessageLite message, MessageInfo messageInfo) {
  for (FieldInfo fieldInfo : messageInfo.getAllFields()) {
    Descriptor fieldDescriptor = fieldInfo.getFieldDescriptor();
    boolean isFieldPresent =
        messageInfo.messageAccessor.hasField(message, fieldDescriptor);

    // If the field must be present but isn't, fail.
    if ((fieldInfo.getPresence() == FieldInfo.Presence.REQUIRED) && !(isFieldPresent)) {
      logger.warning("Required field not set: %s", fieldInfo.getFieldDescriptor().getName());
      return false;
    }

    // If the field is present and requires its own validation, validate it.
    if (isFieldPresent && fieldInfo.requiresAdditionalValidation()) {
      for (MessageLite subMessage : TiclMessageValidator2.<MessageLite>getFieldIterable(
          message, messageInfo.messageAccessor, fieldDescriptor)) {
        if (!checkMessage(subMessage, fieldInfo.getMessageInfo())) {
          return false;
        }
      }
    }
  }

  // Once we've validated all fields, post-validate this message.
  if (!messageInfo.postValidate(message)) {
    logger.info("Failed post-validation of message (%s): %s",
        message.getClass().getSimpleName(), message);
    return false;
  }
  return true;
}
 
开发者ID:morristech,项目名称:android-chromium,代码行数:37,代码来源:ProtoValidator.java

示例3: getPresence

import com.google.ipc.invalidation.common.ProtoValidator.FieldInfo.Presence; //导入依赖的package包/类
/** Returns the presence information for the field. */
Presence getPresence() {
  return presence;
}
 
开发者ID:morristech,项目名称:android-chromium,代码行数:5,代码来源:ProtoValidator.java

示例4: newRequired

import com.google.ipc.invalidation.common.ProtoValidator.FieldInfo.Presence; //导入依赖的package包/类
/**
 * Returns a new instance describing a required field with name {@code fieldName} and validation
 * specified by {@code messageInfo}.
 */
public static FieldInfo newRequired(Descriptor fieldDescriptor, MessageInfo messageInfo) {
  return new FieldInfo(fieldDescriptor, Presence.REQUIRED,
      Preconditions.checkNotNull(messageInfo, "messageInfo cannot be null"));
}
 
开发者ID:morristech,项目名称:android-chromium,代码行数:9,代码来源:ProtoValidator.java

示例5: newOptional

import com.google.ipc.invalidation.common.ProtoValidator.FieldInfo.Presence; //导入依赖的package包/类
/**
 * Returns a new instance describing an optional field with name {@code fieldName} and
 * validation specified by {@code messageInfo}.
 */
public static FieldInfo newOptional(Descriptor fieldDescriptor, MessageInfo messageInfo) {
  return new FieldInfo(fieldDescriptor, Presence.OPTIONAL,
      Preconditions.checkNotNull(messageInfo));
}
 
开发者ID:morristech,项目名称:android-chromium,代码行数:9,代码来源:ProtoValidator.java

示例6: FieldInfo

import com.google.ipc.invalidation.common.ProtoValidator.FieldInfo.Presence; //导入依赖的package包/类
/**
 * Constructs an instance.
 *
 * @param fieldDescriptor identifier for the field
 * @param presence required/optional
 * @param messageInfo if not {@code null}, describes how to validate the field
 */
FieldInfo(Descriptor fieldDescriptor, Presence presence,
    MessageInfo messageInfo) {
  this.fieldDescriptor = fieldDescriptor;
  this.presence = presence;
  this.messageInfo = messageInfo;
}
 
开发者ID:morristech,项目名称:android-chromium,代码行数:14,代码来源:ProtoValidator.java


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