Class FieldScope
- java.lang.Object
-
- com.google.common.truth.extensions.proto.FieldScope
-
public abstract class FieldScope extends Object
An immutable, abstract representation of a set of specific field paths. SeeFieldScopesfor entry points to obtain aFieldScopeobject.A
FieldScopeis similar in concept to aFieldMask, which is an explicitly enumerated set of specific field paths. A FieldScope is more general, allowing for the description of arbitrary classes of specific field paths to be included or excluded from its definition. For example, given a large protocol buffer with many field definitions, and a single string field named 'x', it is arduous to specify "All fields except 'x'" as aFieldMask. With aFieldScope, it is simplyFieldScopes.ignoringFields(MyMessage.X_FIELD_NUMBER).All inclusion and exclusion operations on message-type fields are recursive, but may be overridden by subsequent operations. In this way, a complex
FieldScopesuch as:
...will match all fields on A, except fields on the message type B, but including B's flag field. Thus, two messages of type A will compare equal even if their sub messages of type B are completely different, so long as the 'flag' fields for each B matches. Because of this, method ordering matters. Generally, exclusions should come after inclusions.FieldScopes.ignoringFields(A.B_FIELD_NUMBER) .allowingFieldDescriptors(B.getDescriptor().findFieldByName("flag"))FieldScopes are not designed to be compact or efficient, trading flexibility of use for runtime efficiency, generally composing themselves as recursive structures. For this reason, it is not recommended to useFieldScopein production code. Prefer to use properFieldMasks, directly in production code.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description abstract FieldScopeallowingFieldDescriptors(Descriptors.FieldDescriptor firstFieldDescriptor, Descriptors.FieldDescriptor... rest)Returns aFieldScopeequivalent to this one, plus all fields matching the givenDescriptors.FieldDescriptors.abstract FieldScopeallowingFieldDescriptors(Iterable<Descriptors.FieldDescriptor> fieldDescriptors)Returns aFieldScopeequivalent to this one, plus all fields matching the givenDescriptors.FieldDescriptors.abstract FieldScopeallowingFields(int firstFieldNumber, int... rest)Returns aFieldScopeequivalent to this one, plus all fields defined by the given field numbers.abstract FieldScopeallowingFields(Iterable<Integer> fieldNumbers)Returns aFieldScopeequivalent to this one, plus all fields defined by the given field numbers.abstract FieldScopeignoringFieldDescriptors(Descriptors.FieldDescriptor firstFieldDescriptor, Descriptors.FieldDescriptor... rest)Returns aFieldScopeequivalent to this one, minus all fields matching the givenDescriptors.FieldDescriptors.abstract FieldScopeignoringFieldDescriptors(Iterable<Descriptors.FieldDescriptor> fieldDescriptors)Returns aFieldScopeequivalent to this one, minus all fields defined by the given field numbers.abstract FieldScopeignoringFields(int firstFieldNumber, int... rest)Returns aFieldScopeequivalent to this one, minus all fields defined by the given field numbers.abstract FieldScopeignoringFields(Iterable<Integer> fieldNumbers)Returns aFieldScopeequivalent to this one, minus all fields defined by the given field numbers.
-
-
-
Method Detail
-
ignoringFields
public abstract FieldScope ignoringFields(int firstFieldNumber, int... rest)
Returns aFieldScopeequivalent to this one, minus all fields defined by the given field numbers.Validation of the field numbers is performed when the
FieldScopeis invoked (typically byProtoFluentAssertion.isEqualTo(com.google.protobuf.Message)). A runtime exception will occur if bad field numbers are encountered.The field numbers are ignored recursively on this type. That is, if
YourMessagecontains anotherYourMessagesomewhere within its subtree, aFieldScope ignoringFields(X)will ignore field numberXfor all submessages of typeYourMessage, as well as for the top-level message.
-
ignoringFields
public abstract FieldScope ignoringFields(Iterable<Integer> fieldNumbers)
Returns aFieldScopeequivalent to this one, minus all fields defined by the given field numbers.Validation of the field numbers is performed when the
FieldScopeis invoked (typically byProtoFluentAssertion.isEqualTo(com.google.protobuf.Message)). A runtime exception will occur if bad field numbers are encountered.The field numbers are ignored recursively on this type. That is, if
YourMessagecontains anotherYourMessagesomewhere within its subtree, aFieldScope ignoringFields(X)will ignore field numberXfor all submessages of typeYourMessage, as well as for the top-level message.
-
ignoringFieldDescriptors
public abstract FieldScope ignoringFieldDescriptors(Descriptors.FieldDescriptor firstFieldDescriptor, Descriptors.FieldDescriptor... rest)
Returns aFieldScopeequivalent to this one, minus all fields matching the givenDescriptors.FieldDescriptors.The
Descriptors.FieldDescriptors are not validated, as that would require scanning the entire protobuf schema recursively from this message type. If aDescriptors.FieldDescriptoris provided which refers to a field that is not part of this message, or any possible recursive submessages, it is silently ignored.The field descriptors are also ignored recursively on the message type. That is, if
FooMessage.field_baris ignored,field_barwill be ignored for all submessages of the parent type of typeFooMessage.
-
ignoringFieldDescriptors
public abstract FieldScope ignoringFieldDescriptors(Iterable<Descriptors.FieldDescriptor> fieldDescriptors)
Returns aFieldScopeequivalent to this one, minus all fields defined by the given field numbers.The
Descriptors.FieldDescriptors are not validated, as that would require scanning the entire protobuf schema recursively from this message type. If aDescriptors.FieldDescriptoris provided which refers to a field that is not part of this message, or any possible recursive submessages, it is silently ignored.The field descriptors are also ignored recursively on the message type. That is, if
FooMessage.field_baris ignored,field_barwill be ignored for all submessages of the parent type of typeFooMessage.
-
allowingFields
public abstract FieldScope allowingFields(int firstFieldNumber, int... rest)
Returns aFieldScopeequivalent to this one, plus all fields defined by the given field numbers.Validation of the field numbers is performed when the
FieldScopeis invoked (typically byProtoFluentAssertion.isEqualTo(com.google.protobuf.Message)). A runtime exception will occur if bad field numbers are encountered.The field numbers are included recursively on this type. That is, if
YourMessagecontains anotherYourMessagesomewhere within its subtree, aFieldScope allowingFields(X)will include field numberXfor all submessages of typeYourMessage, as well as for the top-level message.
-
allowingFields
public abstract FieldScope allowingFields(Iterable<Integer> fieldNumbers)
Returns aFieldScopeequivalent to this one, plus all fields defined by the given field numbers.Validation of the field numbers is performed when the
FieldScopeis invoked (typically byProtoFluentAssertion.isEqualTo(com.google.protobuf.Message)). A runtime exception will occur if bad field numbers are encountered.The field numbers are included recursively on this type. That is, if
YourMessagecontains anotherYourMessagesomewhere within its subtree, aFieldScope allowingFields(X)will include field numberXfor all submessages of typeYourMessage, as well as for the top-level message.
-
allowingFieldDescriptors
public abstract FieldScope allowingFieldDescriptors(Descriptors.FieldDescriptor firstFieldDescriptor, Descriptors.FieldDescriptor... rest)
Returns aFieldScopeequivalent to this one, plus all fields matching the givenDescriptors.FieldDescriptors.The
Descriptors.FieldDescriptors are not validated, as that would require scanning the entire protobuf schema from this message type. If aDescriptors.FieldDescriptoris provided which refers to a field that is not part of this message, or any possible recursive submessages, it is silently ignored.The field descriptors are also included recursively on the message type. That is, if
FooMessage.field_baris included,field_barwill be included for all submessages of the parent type of typeFooMessage.
-
allowingFieldDescriptors
public abstract FieldScope allowingFieldDescriptors(Iterable<Descriptors.FieldDescriptor> fieldDescriptors)
Returns aFieldScopeequivalent to this one, plus all fields matching the givenDescriptors.FieldDescriptors.The
Descriptors.FieldDescriptors are not validated, as that would require scanning the entire protobuf schema from this message type. If aDescriptors.FieldDescriptoris provided which refers to a field that is not part of this message, or any possible recursive submessages, it is silently ignored.The field descriptors are also included recursively on the message type. That is, if
FooMessage.field_baris included,field_barwill be included for all submessages of the parent type of typeFooMessage.
-
-