/** * Checks whether paths in a given fields mask are valid. */ public static boolean isValid(Descriptor descriptor, FieldMask fieldMask) { for (String path : fieldMask.getPathsList()) { if (!isValid(descriptor, path)) { return false; } } return true; }
/** * 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 for a list of field paths in a certain type. * * @throws IllegalArgumentException if any of the field path is not valid. */ // TODO(xiaofeng): Consider renaming fromStrings() public static FieldMask fromStringList(Class<? extends Message> type, Iterable<String> paths) { FieldMask.Builder builder = FieldMask.newBuilder(); for (String path : paths) { if (path.isEmpty()) { // Ignore empty field paths. continue; } if (type != null && !isValid(type, path)) { throw new IllegalArgumentException(path + " is not a valid path for " + type); } builder.addPaths(path); } return builder.build(); }