@Test public void exampleUsage() { List<PathFragment> fragments = ProtobufPathParser.parse("$.foo.bar.baz"); assertThat(fragments, contains(fragment("foo"), fragment("bar"), fragment("baz"))); }
static List<PathFragment> parse(String protobufPath) { validatePrefix(protobufPath); String[] tokens = protobufPath.substring(2).split("\\."); List<PathFragment> pathFragments = new ArrayList<>(); for (String token : tokens) { Matcher repeatedFieldMatcher = REPEATED_FIELD_PATTERN.matcher(token); if (repeatedFieldMatcher.matches()) { pathFragments.add(parseRepeatedField(protobufPath, repeatedFieldMatcher)); continue; } Matcher plainFieldMatcher = PLAIN_FIELD_PATTERN.matcher(token); if (plainFieldMatcher.matches()) { pathFragments.add(parsePlainField(plainFieldMatcher)); continue; } throw new IllegalArgumentException("Parse error in " + protobufPath + " at " + token); } return pathFragments; }
ProtobufPathParser { static List<PathFragment> parse(String protobufPath) { validatePrefix(protobufPath); String[] tokens = protobufPath.substring(2).split("\\."); List<PathFragment> pathFragments = new ArrayList<>(); for (String token : tokens) { Matcher repeatedFieldMatcher = REPEATED_FIELD_PATTERN.matcher(token); if (repeatedFieldMatcher.matches()) { pathFragments.add(parseRepeatedField(protobufPath, repeatedFieldMatcher)); continue; } Matcher plainFieldMatcher = PLAIN_FIELD_PATTERN.matcher(token); if (plainFieldMatcher.matches()) { pathFragments.add(parsePlainField(plainFieldMatcher)); continue; } throw new IllegalArgumentException("Parse error in " + protobufPath + " at " + token); } return pathFragments; } }
ProtobufPathParser { static List<PathFragment> parse(String protobufPath) { validatePrefix(protobufPath); String[] tokens = protobufPath.substring(2).split("\\."); List<PathFragment> pathFragments = new ArrayList<>(); for (String token : tokens) { Matcher repeatedFieldMatcher = REPEATED_FIELD_PATTERN.matcher(token); if (repeatedFieldMatcher.matches()) { pathFragments.add(parseRepeatedField(protobufPath, repeatedFieldMatcher)); continue; } Matcher plainFieldMatcher = PLAIN_FIELD_PATTERN.matcher(token); if (plainFieldMatcher.matches()) { pathFragments.add(parsePlainField(plainFieldMatcher)); continue; } throw new IllegalArgumentException("Parse error in " + protobufPath + " at " + token); } return pathFragments; }  }
ProtobufPathParser { static List<PathFragment> parse(String protobufPath) { validatePrefix(protobufPath); String[] tokens = protobufPath.substring(2).split("\\."); List<PathFragment> pathFragments = new ArrayList<>(); for (String token : tokens) { Matcher repeatedFieldMatcher = REPEATED_FIELD_PATTERN.matcher(token); if (repeatedFieldMatcher.matches()) { pathFragments.add(parseRepeatedField(protobufPath, repeatedFieldMatcher)); continue; } Matcher plainFieldMatcher = PLAIN_FIELD_PATTERN.matcher(token); if (plainFieldMatcher.matches()) { pathFragments.add(parsePlainField(plainFieldMatcher)); continue; } throw new IllegalArgumentException("Parse error in " + protobufPath + " at " + token); } return pathFragments; }   }
ProtobufPathParser { static List<PathFragment> parse(String protobufPath) { validatePrefix(protobufPath); String[] tokens = protobufPath.substring(2).split("\\."); List<PathFragment> pathFragments = new ArrayList<>(); for (String token : tokens) { Matcher repeatedFieldMatcher = REPEATED_FIELD_PATTERN.matcher(token); if (repeatedFieldMatcher.matches()) { pathFragments.add(parseRepeatedField(protobufPath, repeatedFieldMatcher)); continue; } Matcher plainFieldMatcher = PLAIN_FIELD_PATTERN.matcher(token); if (plainFieldMatcher.matches()) { pathFragments.add(parsePlainField(plainFieldMatcher)); continue; } throw new IllegalArgumentException("Parse error in " + protobufPath + " at " + token); } return pathFragments; }    }