public static List<String> getRels(Link link) { List<String> rels; if (link instanceof Affordance) { rels = ((Affordance) link).getRels(); } else { rels = Arrays.asList(link.getRel()); } return rels; }
public static List<String> getRels(Link link) { List<String> rels; if (link instanceof Affordance) { rels = ((Affordance) link).getRels(); } else { rels = Arrays.asList(link.getRel()); } return rels; }
private List<SirenLink> toSirenLinks(List<Link> links) { List<SirenLink> ret = new ArrayList<SirenLink>(); for (Link link : links) { if (link instanceof Affordance) { ret.add(new SirenLink(null, ((Affordance) link).getRels(), link.getHref(), null, null)); } else { ret.add(new SirenLink(null, Collections.singletonList(link.getRel()), link.getHref(), null, null)); } } return ret; }
private List<SirenLink> toSirenLinks(List<Link> links) { List<SirenLink> ret = new ArrayList<SirenLink>(); for (Link link : links) { if (link instanceof Affordance) { ret.add(new SirenLink(null, ((Affordance) link).getRels(), link.getHref(), null, null)); } else { ret.add(new SirenLink(null, Collections.singletonList(link.getRel()), link.getHref(), null, null)); } } return ret; }
private List<SirenEmbeddedLink> toSirenEmbeddedLinks(List<Link> links) { List<SirenEmbeddedLink> ret = new ArrayList<SirenEmbeddedLink>(); for (Link link : links) { if (link instanceof Affordance) { // TODO: how to determine classes? type of target resource? collection/item? ret.add(new SirenEmbeddedLink(null, ((Affordance) link).getRels(), link .getHref(), null, null)); } else { ret.add(new SirenEmbeddedLink(null, Collections.singletonList(link.getRel()), link .getHref(), null, null)); } } return ret; }
private List<SirenEmbeddedLink> toSirenEmbeddedLinks(List<Link> links) { List<SirenEmbeddedLink> ret = new ArrayList<SirenEmbeddedLink>(); for (Link link : links) { if (link instanceof Affordance) { // TODO: how to determine classes? type of target resource? collection/item? ret.add(new SirenEmbeddedLink(null, ((Affordance) link).getRels(), link .getHref(), null, null)); } else { ret.add(new SirenEmbeddedLink(null, Collections.singletonList(link.getRel()), link .getHref(), null, null)); } } return ret; }
@Test public void testConstructorWithoutRels() { final Affordance affordance = new Affordance("http://localhost/things/{id}"); assertEquals("http://localhost/things/{id}", affordance.getHref()); Assert.assertNull("rel must be null", affordance.getRel()); assertEquals(0, affordance.getRels() .size()); Assert.assertThat(affordance.getRels(), Matchers.is(Matchers.empty())); }
@Test public void testConstructorWithSingleRel() { final Affordance affordance = new Affordance("http://localhost/things/{id}", "thing"); assertEquals("http://localhost/things/{id}", affordance.getHref()); assertEquals("thing", affordance.getRel()); Assert.assertThat(affordance.getRels(), Matchers.contains("thing")); }
@Test public void testConstructorWithRels() { final Affordance affordance = new Affordance("http://localhost/things/{id}", "start", "http://example.net/relation/other"); assertEquals("http://localhost/things/{id}", affordance.getHref()); assertEquals("start", affordance.getRel()); Assert.assertThat(affordance.getRels(), Matchers.contains("start", "http://example.net/relation/other")); }