/** * Merges all fields specified by this FieldMaskTree from {@code source} to {@code destination}. */ void merge(Message source, Message.Builder destination, FieldMaskUtil.MergeOptions options) { if (source.getDescriptorForType() != destination.getDescriptorForType()) { throw new IllegalArgumentException("Cannot merge messages of different types."); } if (root.children.isEmpty()) { return; } merge(root, "", source, destination, options); }
/** * Checks whether a given field path is valid. */ public static boolean isValid(Class<? extends Message> type, String path) { Descriptor descriptor = Internal.getDefaultInstance(type).getDescriptorForType(); return isValid(descriptor, path); }
/** * Checks whether paths in a given fields mask are valid. */ public static boolean isValid(Class<? extends Message> type, FieldMask fieldMask) { Descriptor descriptor = Internal.getDefaultInstance(type).getDescriptorForType(); return isValid(descriptor, fieldMask); }
/** * Constructs a FieldMask from the passed field numbers. * * @throws IllegalArgumentException if any of the fields are invalid for the message. */ public static FieldMask fromFieldNumbers( Class<? extends Message> type, Iterable<Integer> fieldNumbers) { Descriptor descriptor = Internal.getDefaultInstance(type).getDescriptorForType(); FieldMask.Builder builder = FieldMask.newBuilder(); for (Integer fieldNumber : fieldNumbers) { FieldDescriptor field = descriptor.findFieldByNumber(fieldNumber); checkArgument( field != null, String.format("%s is not a valid field number for %s.", fieldNumber, type)); builder.addPaths(field.getName()); } return builder.build(); }
Message.Builder destination, FieldMaskUtil.MergeOptions options) { if (source.getDescriptorForType() != destination.getDescriptorForType()) { throw new IllegalArgumentException( String.format( "source (%s) and destination (%s) descriptor must be equal", source.getDescriptorForType(), destination.getDescriptorForType())); Descriptor descriptor = source.getDescriptorForType(); for (Entry<String, Node> entry : node.children.entrySet()) { FieldDescriptor field = descriptor.findFieldByName(entry.getKey());