class LinkMapper {

	private static final JsonNodeFactory nodeFactory = JsonNodeFactory.instance;

	private LinkMapper() {
	}

	/**
	 * Map the specified links to a json model. If several links share the same relation,
	 * they are grouped together.
	 * @param links the links to map
	 * @return a model for the specified links
	 */
	public static ObjectNode mapLinks(List<Link> links) {<FILL_FUNCTION_BODY>}

	private static void mapLink(Link link, ObjectNode node) {
		node.put("href", link.getHref());
		if (link.isTemplated()) {
			node.put("templated", true);
		}
		if (link.getDescription() != null) {
			node.put("title", link.getDescription());
		}
	}

}

		ObjectNode result = nodeFactory.objectNode();
		Map<String, List<Link>> byRel = new LinkedHashMap<>();
		links.forEach((it) -> byRel.computeIfAbsent(it.getRel(), (k) -> new ArrayList<>()).add(it));
		byRel.forEach((rel, l) -> {
			if (l.size() == 1) {
				ObjectNode root = JsonNodeFactory.instance.objectNode();
				mapLink(l.get(0), root);
				result.set(rel, root);
			}
			else {
				ArrayNode root = JsonNodeFactory.instance.arrayNode();
				l.forEach((link) -> {
					ObjectNode node = JsonNodeFactory.instance.objectNode();
					mapLink(link, node);
					root.add(node);
				});
				result.set(rel, root);
			}
		});
		return result;
	
<no_super_class>