@Test public void testMetadataFromMatchGroups() throws Exception { List<String> keys = Arrays.asList(new String[] {"key1", "key2"}); Matcher matcher = Pattern.compile("/path/(.*)/(.*)").matcher("/path/value1/value2"); matcher.matches(); Set<MetadataElement> metadata = metadataFromMatchGroups(matcher, keys); assertEquals(2, metadata.size()); }
public static Set<MetadataElement> metadataFromMatchGroups(MatchResult matchResult, List<String> metadataKeys) throws CoreException { Set<MetadataElement> result = new HashSet<>(); List<String> keys = Collections.unmodifiableList(metadataKeys); if (matchResult.groupCount() > keys.size()) { throw new CoreException( String.format("%d available match-groups, but only %d metadata keys defined", matchResult.groupCount(), keys.size())); } for (int i = 1; i <= matchResult.groupCount(); i++) { result.add(new MetadataElement(keys.get(i - 1), matchResult.group(i))); } return result; }
MetadataHelper { public static Set<MetadataElement> metadataFromMatchGroups(MatchResult matchResult, List<String> metadataKeys) throws CoreException { Set<MetadataElement> result = new HashSet<>(); List<String> keys = Collections.unmodifiableList(metadataKeys); if (matchResult.groupCount() > keys.size()) { throw new CoreException( String.format("%d available match-groups, but only %d metadata keys defined", matchResult.groupCount(), keys.size())); } for (int i = 1; i <= matchResult.groupCount(); i++) { result.add(new MetadataElement(keys.get(i - 1), matchResult.group(i))); } return result; } }
MetadataHelper { public static Set<MetadataElement> metadataFromMatchGroups(MatchResult matchResult, List<String> metadataKeys) throws CoreException { Set<MetadataElement> result = new HashSet<>(); List<String> keys = Collections.unmodifiableList(metadataKeys); if (matchResult.groupCount() > keys.size()) { throw new CoreException( String.format("%d available match-groups, but only %d metadata keys defined", matchResult.groupCount(), keys.size())); } for (int i = 1; i <= matchResult.groupCount(); i++) { result.add(new MetadataElement(keys.get(i - 1), matchResult.group(i))); } return result; }  }
MetadataHelper { public static Set<MetadataElement> metadataFromMatchGroups(MatchResult matchResult, List<String> metadataKeys) throws CoreException { Set<MetadataElement> result = new HashSet<>(); List<String> keys = Collections.unmodifiableList(metadataKeys); if (matchResult.groupCount() > keys.size()) { throw new CoreException( String.format("%d available match-groups, but only %d metadata keys defined", matchResult.groupCount(), keys.size())); } for (int i = 1; i <= matchResult.groupCount(); i++) { result.add(new MetadataElement(keys.get(i - 1), matchResult.group(i))); } return result; }  static Properties convertToProperties(Collection<MetadataElement> s); static Set<MetadataElement> convertFromProperties(Properties p); static Set<MetadataElement> convertFromKeyValuePairs(KeyValuePairBag bag); static Set<MetadataElement> metadataFromMatchGroups(MatchResult matchResult, List<String> metadataKeys); }
MetadataHelper { public static Set<MetadataElement> metadataFromMatchGroups(MatchResult matchResult, List<String> metadataKeys) throws CoreException { Set<MetadataElement> result = new HashSet<>(); List<String> keys = Collections.unmodifiableList(metadataKeys); if (matchResult.groupCount() > keys.size()) { throw new CoreException( String.format("%d available match-groups, but only %d metadata keys defined", matchResult.groupCount(), keys.size())); } for (int i = 1; i <= matchResult.groupCount(); i++) { result.add(new MetadataElement(keys.get(i - 1), matchResult.group(i))); } return result; }  static Properties convertToProperties(Collection<MetadataElement> s); static Set<MetadataElement> convertFromProperties(Properties p); static Set<MetadataElement> convertFromKeyValuePairs(KeyValuePairBag bag); static Set<MetadataElement> metadataFromMatchGroups(MatchResult matchResult, List<String> metadataKeys);  }