in src/main/java/com/spotify/github/http/Link.java [119:160]
static Link from(String[] linkValues) {
final Map<String, String> linkResources =
Arrays.stream(linkValues)
.map(
value -> {
final Matcher linkValueMatcher =
Pattern.compile("^<([^>]+)>$").matcher(value.trim());
final Matcher keyValueMatcher =
Pattern.compile("(?<name>\\w+)=\"(?<value>[^\"]+)\"").matcher(value.trim());
if (linkValueMatcher.find()) {
return new AbstractMap.SimpleEntry<>("url", linkValueMatcher.group(1));
} else if (keyValueMatcher.find()) {
return new AbstractMap.SimpleEntry<>(
keyValueMatcher.group("name"), keyValueMatcher.group("value"));
}
return (Map.Entry<String, String>) null;
})
.filter(Objects::nonNull)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
final ImmutableLink.Builder builder =
ImmutableLink.builder()
.url(URI.create(linkResources.get("url")))
.rel(linkResources.get("rel"));
if (linkResources.containsKey("rev")) {
builder.rev(linkResources.get("rev"));
}
if (linkResources.containsKey("type")) {
builder.type(linkResources.get("type"));
}
if (linkResources.containsKey("media")) {
builder.media(linkResources.get("media"));
}
if (linkResources.containsKey("title")) {
builder.title(linkResources.get("title"));
}
if (linkResources.containsKey("anchor")) {
builder.anchor(linkResources.get("anchor"));
}
return builder.build();
}