/** * There is a special kind of url: a url that may receive a body (with parameters in it), or may * not. For example, when deleting a datacenter, the user may pass nothing in the body, or may * pass <action><force>true</force></action>. * * <p>RSDL builder will encounter both signatures during construction, and when it encounters the * first is has no knowledge of the second yet, so it must create both linke. * * <p>This method will be called at the end of construction, and search for such duplicate links. * It will unite these pairs into a single link with required=false in the <body>. * * @param rsdl */ private void uniteDuplicateLinks(Rsdl rsdl) { Map<String, DetailedLink> linksMap = new HashMap<String, DetailedLink>(); Collection<DetailedLink> linksToDelete = new LinkedList<DetailedLink>(); for (DetailedLink link : rsdl.getLinks().getLinks()) { String linkId = link.getHref() + link.getRel(); if (linksMap.containsKey(linkId)) { // duplicate found, determine which of the two should be deleted DetailedLink linkToDelete = decideWhichToDelete(linksMap.get(linkId), link); if (linkToDelete != null) { linksToDelete.add(linkToDelete); } } else { linksMap.put(linkId, link); } } for (DetailedLink link : linksToDelete) { rsdl.getLinks().getLinks().remove(link); } }
@Override public String toString() { return "RSDL Href: " + getHref() + ", Description:" + getDescription() + ", Links: " + (rsdl != null ? (rsdl.isSetLinks() ? rsdl.getLinks().getLinks().size() : "0") : "0") + "."; }
private Rsdl construct() throws ClassNotFoundException, IOException { Rsdl rsdl = new Rsdl(); rsdl.setLinks(new DetailedLinks()); for (DetailedLink link : getLinks()) { rsdl.getLinks().getLinks().add(link); } uniteDuplicateLinks(rsdl); Collections.sort( rsdl.getLinks().getLinks(), new Comparator<DetailedLink>() { @Override public int compare(DetailedLink dl1, DetailedLink dl2) { int res = dl1.getHref().compareTo(dl2.getHref()); return res != 0 ? res : dl1.getRel().compareTo(dl2.getRel()); } }); return rsdl; }