@Override public HSDeck getDeckDetail(final HSDeck hsDeck, final float n) { try { final Document value = Jsoup.connect(HPDeckSource.BASE_URL + hsDeck.getUrl()).get(); final Elements select = value.select("section.class-listing table.listing td.col-name"); final HashMap<String, String> classHsItemMap = new HashMap<String, String>(); final ArrayList<String> list = new ArrayList<String>(); for (int i = 0; i < select.size(); ++i) { final String text = select.get(i).select("a").get(0).text(); classHsItemMap.put( text, select.get(i).text().trim().substring(select.get(i).text().trim().length() - 1)); list.add(text); } hsDeck.setClassHsItemMap(classHsItemMap); hsDeck.setClassHsItemList(DataBaseManager.getInstance().getAllCardsByNames(list)); final Elements select2 = value.select("section.neutral-listing table.listing td.col-name"); final HashMap<String, String> neutralHsItemMap = new HashMap<String, String>(); final ArrayList<String> list2 = new ArrayList<String>(); for (int j = 0; j < select2.size(); ++j) { final String text2 = select2.get(j).select("a").get(0).text(); neutralHsItemMap.put( text2, select2.get(j).text().trim().substring(select2.get(j).text().trim().length() - 1)); list2.add(text2); } hsDeck.setNeutralHsItemMap(neutralHsItemMap); hsDeck.setNeutralHsItemList(DataBaseManager.getInstance().getAllCardsByNames(list2)); hsDeck.setDescription( HtmlHelper.parseDescription(value.select("div.deck-description").html(), n, false)); return hsDeck; } catch (IOException ex) { ex.printStackTrace(); return hsDeck; } }
@Test public void testByAttributeRegexCombined() { Document doc = Jsoup.parse("<div><table class=x><td>Hello</td></table></div>"); Elements els = doc.select("div table[class~=x|y]"); assertEquals(1, els.size()); assertEquals("Hello", els.text()); }
/** * Find an element by ID, including or under this element. * * <p>Note that this finds the first matching ID, starting with this element. If you search down * from a different starting point, it is possible to find a different element by ID. For unique * element by ID within a Document, use {@link Document#getElementById(String)} * * @param id The ID to search for. * @return The first matching element by ID, starting with this element, or null if none found. */ public Element getElementById(String id) { Validate.notEmpty(id); Elements elements = Collector.collect(new Evaluator.Id(id), this); if (elements.size() > 0) return elements.get(0); else return null; }
@Override public void effectiveComputeValue(final RunningEffect triggerRE) { this.m_value = 0; if (this.m_genericEffect == null) { return; } this.m_value = ((WakfuEffect) this.m_genericEffect) .getParam(0, this.getContainerLevel(), RoundingMethod.LIKE_PREVIOUS_LEVEL); final int elementId = ((WakfuEffect) this.m_genericEffect) .getParam(1, this.getContainerLevel(), RoundingMethod.LIKE_PREVIOUS_LEVEL); final Elements element = Elements.getElementFromId((byte) elementId); if (element == null) { ElementalCharacGain.m_logger.error((Object) ("Mauvais param element inconnu " + elementId)); return; } final FighterCharacteristicType damageBonusCharacteristic = element.getDamageBonusCharacteristic(); int modificator = 0; if (this.m_caster.hasCharacteristic(damageBonusCharacteristic)) { modificator += this.m_caster.getCharacteristicValue(damageBonusCharacteristic); } if (this.m_caster.hasCharacteristic(FighterCharacteristicType.DMG_IN_PERCENT)) { modificator += this.m_caster.getCharacteristicValue(FighterCharacteristicType.DMG_IN_PERCENT); } this.m_value += modificator * this.m_value / 100; }
@Test public void hasAttr() { Document doc = Jsoup.parse("<p title=foo><p title=bar><p class=foo><p class=bar>"); Elements ps = doc.select("p"); assertTrue(ps.hasAttr("class")); assertFalse(ps.hasAttr("style")); }
@Test public void notAdjacent() { String h = "<ol><li id=1>One<li id=2>Two<li id=3>Three</ol>"; Document doc = Jsoup.parse(h); Elements sibs = doc.select("li#1 + li#3"); assertEquals(0, sibs.size()); }
@Test public void testPseudoBetween() { Document doc = Jsoup.parse("<div><p>One</p><p>Two</p><p>Three</>p></div><div><p>Four</p>"); Elements ps = doc.select("div p:gt(0):lt(2)"); assertEquals(1, ps.size()); assertEquals("Two", ps.get(0).text()); }
@Test public void outerHtml() { Document doc = Jsoup.parse("<div><p>Hello</p></div><div><p>There</p></div>"); Elements divs = doc.select("div"); assertEquals( "<div><p>Hello</p></div><div><p>There</p></div>", TextUtil.stripNewlines(divs.outerHtml())); }
@Test public void hasText() { Document doc = Jsoup.parse("<div><p>Hello</p></div><div><p></p></div>"); Elements divs = doc.select("div"); assertTrue(divs.hasText()); assertFalse(doc.select("div + div").hasText()); }
@Test public void testAllWithClass() { String h = "<p class=first>One<p class=first>Two<p>Three"; Document doc = Jsoup.parse(h); Elements ps = doc.select("*.first"); assertEquals(2, ps.size()); }
@Test public void testCombinedWithContains() { Document doc = Jsoup.parse("<p id=1>One</p><p>Two +</p><p>Three +</p>"); Elements els = doc.select("p#1 + :contains(+)"); assertEquals(1, els.size()); assertEquals("Two +", els.text()); assertEquals("p", els.first().tagName()); }
@Test public void is() { String h = "<p>Hello<p title=foo>there<p>world"; Document doc = Jsoup.parse(h); Elements ps = doc.select("p"); assertTrue(ps.is("[title=foo]")); assertFalse(ps.is("[title=bar]")); }
/** * Get sibling elements. If the element has no sibling elements, returns an empty list. An element * is not a sibling of itself, so will not be included in the returned list. * * @return sibling elements */ public Elements siblingElements() { if (parentNode == null) return new Elements(0); List<Element> elements = parent().children(); Elements siblings = new Elements(elements.size() - 1); for (Element el : elements) if (el != this) siblings.add(el); return siblings; }
@Test public void testPseudoGreaterThan() { Document doc = Jsoup.parse("<div><p>One</p><p>Two</p><p>Three</p></div><div><p>Four</p>"); Elements ps = doc.select("div p:gt(0)"); assertEquals(2, ps.size()); assertEquals("Two", ps.get(0).text()); assertEquals("Three", ps.get(1).text()); }
@Test public void adjacentSiblingsWithId() { String h = "<ol><li id=1>One<li id=2>Two<li id=3>Three</ol>"; Document doc = Jsoup.parse(h); Elements sibs = doc.select("li#1 + li#2"); assertEquals(1, sibs.size()); assertEquals("Two", sibs.get(0).text()); }
@Test public void multiChildDescent() { String h = "<div id=foo><h1 class=bar><a href=http://example.com/>One</a></h1></div>"; Document doc = Jsoup.parse(h); Elements els = doc.select("div#foo > h1.bar > a[href*=example]"); assertEquals(1, els.size()); assertEquals("a", els.first().tagName()); }
@Test public void notClass() { Document doc = Jsoup.parse("<div class=left>One</div><div class=right id=1><p>Two</p></div>"); Elements el1 = doc.select("div:not(.left)"); assertEquals(1, el1.size()); assertEquals("1", el1.first().id()); }
@Test public void generalSiblings() { String h = "<ol><li id=1>One<li id=2>Two<li id=3>Three</ol>"; Document doc = Jsoup.parse(h); Elements els = doc.select("#1 ~ #3"); assertEquals(1, els.size()); assertEquals("Three", els.first().text()); }
@Test public void notAll() { Document doc = Jsoup.parse("<p>Two</p> <p><span>Three</span></p>"); Elements el1 = doc.body().select(":not(p)"); // should just be the span assertEquals(2, el1.size()); assertEquals("body", el1.first().tagName()); assertEquals("span", el1.last().tagName()); }
@Test public void containsOwn() { Document doc = Jsoup.parse("<p id=1>Hello <b>there</b> now</p>"); Elements ps = doc.select("p:containsOwn(Hello now)"); assertEquals(1, ps.size()); assertEquals("1", ps.first().id()); assertEquals(0, doc.select("p:containsOwn(there)").size()); }
@Test public void testPseudoCombined() { Document doc = Jsoup.parse( "<div class='foo'><p>One</p><p>Two</p></div><div><p>Three</p><p>Four</p></div>"); Elements ps = doc.select("div.foo p:gt(0)"); assertEquals(1, ps.size()); assertEquals("Two", ps.get(0).text()); }
@Test public void adjacentSiblings() { String h = "<ol><li>One<li>Two<li>Three</ol>"; Document doc = Jsoup.parse(h); Elements sibs = doc.select("li + li"); assertEquals(2, sibs.size()); assertEquals("Two", sibs.get(0).text()); assertEquals("Three", sibs.get(1).text()); }
@Test public void matchesOwn() { Document doc = Jsoup.parse("<p id=1>Hello <b>there</b> now</p>"); Elements p1 = doc.select("p:matchesOwn((?i)hello now)"); assertEquals(1, p1.size()); assertEquals("1", p1.first().id()); assertEquals(0, doc.select("p:matchesOwn(there)").size()); }
@Test public void filter() { String h = "<p>Excl</p><div class=headline><p>Hello</p><p>There</p></div><div class=headline><h1>Headline</h1></div>"; Document doc = Jsoup.parse(h); Elements els = doc.select(".headline").select("p"); assertEquals(2, els.size()); assertEquals("Hello", els.get(0).text()); assertEquals("There", els.get(1).text()); }
@Test public void testGroupOrAttribute() { String h = "<div id=1 /><div id=2 /><div title=foo /><div title=bar />"; Elements els = Jsoup.parse(h).select("[id],[title=foo]"); assertEquals(3, els.size()); assertEquals("1", els.get(0).id()); assertEquals("2", els.get(1).id()); assertEquals("foo", els.get(2).attr("title")); }
@Test public void mixCombinator() { String h = "<div class=foo><ol><li>One<li>Two<li>Three</ol></div>"; Document doc = Jsoup.parse(h); Elements sibs = doc.select("body > div.foo li + li"); assertEquals(2, sibs.size()); assertEquals("Two", sibs.get(0).text()); assertEquals("Three", sibs.get(1).text()); }
@Test public void parents() { Document doc = Jsoup.parse("<div><p>Hello</p></div><p>There</p>"); Elements parents = doc.select("p").parents(); assertEquals(3, parents.size()); assertEquals("div", parents.get(0).tagName()); assertEquals("body", parents.get(1).tagName()); assertEquals("html", parents.get(2).tagName()); }
@Test public void testByAttributeRegexCharacterClass() { Document doc = Jsoup.parse( "<p><img src=foo.png id=1><img src=bar.jpg id=2><img src=qux.JPEG id=3><img src=old.gif id=4></p>"); Elements imgs = doc.select("img[src~=[o]]"); assertEquals(2, imgs.size()); assertEquals("1", imgs.get(0).id()); assertEquals("4", imgs.get(1).id()); }
@Test public void parentChildStar() { String h = "<div id=1><p>Hello<p><b>there</b></p></div><div id=2><span>Hi</span></div>"; Document doc = Jsoup.parse(h); Elements divChilds = doc.select("div > *"); assertEquals(3, divChilds.size()); assertEquals("p", divChilds.get(0).tagName()); assertEquals("p", divChilds.get(1).tagName()); assertEquals("span", divChilds.get(2).tagName()); }
@Test public void testAllElements() { String h = "<div><p>Hello</p><p><b>there</b></p></div>"; Document doc = Jsoup.parse(h); Elements allDoc = doc.select("*"); Elements allUnderDiv = doc.select("div *"); assertEquals(8, allDoc.size()); assertEquals(3, allUnderDiv.size()); assertEquals("p", allUnderDiv.first().tagName()); }