Skip to content

Commit 7db2b73

Browse files
committed
cleanup
1 parent d62fa5d commit 7db2b73

File tree

10 files changed

+26
-38
lines changed

10 files changed

+26
-38
lines changed

src/main/java/org/htmlunit/SgmlPage.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public boolean isHtmlPage() {
269269
*/
270270
@Override
271271
public DomNodeList<DomElement> getElementsByTagName(final String tagName) {
272-
return new AbstractDomNodeList<DomElement>(this) {
272+
return new AbstractDomNodeList<>(this) {
273273
@Override
274274
protected List<DomElement> provideElements() {
275275
final List<DomElement> res = new ArrayList<>();
@@ -291,26 +291,25 @@ protected List<DomElement> provideElements() {
291291
*/
292292
@Override
293293
public DomNodeList<DomElement> getElementsByTagNameNS(final String namespaceURI, final String localName) {
294-
return new AbstractDomNodeList<DomElement>(this) {
294+
return new AbstractDomNodeList<>(this) {
295295
@Override
296296
protected List<DomElement> provideElements() {
297297
final List<DomElement> res = new ArrayList<>();
298298
final Comparator<String> comparator;
299299

300300
if (hasCaseSensitiveTagNames()) {
301301
comparator = Comparator.nullsFirst(String::compareTo);
302-
}
303-
else {
302+
} else {
304303
comparator = Comparator.nullsFirst(String::compareToIgnoreCase);
305304
}
306305

307306
for (final DomElement elem : getDomElementDescendants()) {
308307
final String locName = elem.getLocalName();
309308

310309
if ((StringUtils.equalsChar('*', namespaceURI)
311-
|| comparator.compare(namespaceURI, elem.getNamespaceURI()) == 0)
310+
|| comparator.compare(namespaceURI, elem.getNamespaceURI()) == 0)
312311
&& (StringUtils.equalsChar('*', locName)
313-
|| comparator.compare(locName, elem.getLocalName()) == 0)) {
312+
|| comparator.compare(locName, elem.getLocalName()) == 0)) {
314313
res.add(elem);
315314
}
316315
}

src/main/java/org/htmlunit/WebClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1423,7 +1423,7 @@ private WebResponse makeWebResponseForFileUrl(final WebRequest webRequest) throw
14231423
}
14241424

14251425
String fileUrl = cleanUrl.toExternalForm();
1426-
fileUrl = URLDecoder.decode(fileUrl, UTF_8.name());
1426+
fileUrl = URLDecoder.decode(fileUrl, UTF_8);
14271427
final File file = new File(fileUrl.substring(5));
14281428
if (!file.exists()) {
14291429
// construct 404

src/main/java/org/htmlunit/html/DomElement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ public DomNodeList<HtmlElement> getElementsByTagName(final String tagName) {
651651
* @return A list of matching elements.
652652
*/
653653
<E extends HtmlElement> DomNodeList<E> getElementsByTagNameImpl(final String tagName) {
654-
return new AbstractDomNodeList<E>(this) {
654+
return new AbstractDomNodeList<>(this) {
655655
@Override
656656
@SuppressWarnings("unchecked")
657657
protected List<E> provideElements() {

src/main/java/org/htmlunit/html/HtmlPage.java

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,13 +1607,12 @@ public HtmlElement tabToNextElement() {
16071607
// The element with focus isn't on this page
16081608
elementToGiveFocus = elements.get(0);
16091609
}
1610+
else if (index == elements.size() - 1) {
1611+
// if at last jump to start
1612+
elementToGiveFocus = elements.get(0);
1613+
}
16101614
else {
1611-
if (index == elements.size() - 1) {
1612-
elementToGiveFocus = elements.get(0);
1613-
}
1614-
else {
1615-
elementToGiveFocus = elements.get(index + 1);
1616-
}
1615+
elementToGiveFocus = elements.get(index + 1);
16171616
}
16181617
}
16191618

@@ -1645,13 +1644,12 @@ public HtmlElement tabToPreviousElement() {
16451644
// The element with focus isn't on this page
16461645
elementToGiveFocus = elements.get(elements.size() - 1);
16471646
}
1647+
else if (index == 0) {
1648+
// first; back to the last
1649+
elementToGiveFocus = elements.get(elements.size() - 1);
1650+
}
16481651
else {
1649-
if (index == 0) {
1650-
elementToGiveFocus = elements.get(elements.size() - 1);
1651-
}
1652-
else {
1653-
elementToGiveFocus = elements.get(index - 1);
1654-
}
1652+
elementToGiveFocus = elements.get(index - 1);
16551653
}
16561654
}
16571655

@@ -2894,8 +2892,7 @@ public synchronized void clear() {
28942892
computedStyles_.clear();
28952893
}
28962894

2897-
public synchronized Map<String, ComputedCssStyleDeclaration> remove(
2898-
final DomNode element) {
2895+
public synchronized Map<String, ComputedCssStyleDeclaration> remove(final DomNode element) {
28992896
return computedStyles_.remove(element);
29002897
}
29012898

src/main/java/org/htmlunit/html/impl/SimpleRange.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ private static int getMaxOffset(final DomNode node) {
549549
/**
550550
* @return a list with all nodes contained in this range
551551
*/
552-
public List<DomNode> containedNodes() {
552+
public List containedNodes() {
553553
final DomNode ancestor = getCommonAncestorContainer();
554554
if (ancestor == null) {
555555
return Collections.EMPTY_LIST;

src/main/java/org/htmlunit/html/xpath/XPathHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
*/
4141
public final class XPathHelper {
4242

43-
private static final ThreadLocal<Boolean> PROCESS_XPATH_ = new ThreadLocal<Boolean>() {
43+
private static final ThreadLocal<Boolean> PROCESS_XPATH_ = new ThreadLocal<>() {
4444
@Override
4545
protected synchronized Boolean initialValue() {
4646
return Boolean.FALSE;

src/main/java/org/htmlunit/javascript/host/dom/Document.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ public HTMLElement getBody() {
847847
if (doc != null) {
848848
for (final DomNode node : doc.getChildren()) {
849849
if (node instanceof HtmlFrameSet) {
850-
return (HTMLElement) node.getScriptableObject();
850+
return node.getScriptableObject();
851851
}
852852
}
853853
}

src/main/java/org/htmlunit/javascript/host/html/HTMLTableElement.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,13 @@ public HtmlUnitScriptable getCaption() {
8383
*/
8484
@JsxSetter
8585
public void setCaption(final Object o) {
86-
if (!(o instanceof HTMLTableCaptionElement)) {
86+
if (!(o instanceof HTMLTableCaptionElement caption)) {
8787
throw JavaScriptEngine.typeError("Not a caption");
8888
}
8989

9090
// remove old caption (if any)
9191
deleteCaption();
9292

93-
final HTMLTableCaptionElement caption = (HTMLTableCaptionElement) o;
9493
getDomNodeOrDie().appendChild(caption.getDomNodeOrDie());
9594
}
9695

@@ -122,8 +121,7 @@ public void setTFoot(final Object o) {
122121
// remove old caption (if any)
123122
deleteTFoot();
124123

125-
final HTMLTableSectionElement tfoot = (HTMLTableSectionElement) o;
126-
getDomNodeOrDie().appendChild(tfoot.getDomNodeOrDie());
124+
getDomNodeOrDie().appendChild(element.getDomNodeOrDie());
127125
}
128126

129127
/**
@@ -154,8 +152,7 @@ public void setTHead(final Object o) {
154152
// remove old caption (if any)
155153
deleteTHead();
156154

157-
final HTMLTableSectionElement thead = (HTMLTableSectionElement) o;
158-
getDomNodeOrDie().appendChild(thead.getDomNodeOrDie());
155+
getDomNodeOrDie().appendChild(element.getDomNodeOrDie());
159156
}
160157

161158
/**

src/main/java/org/htmlunit/javascript/host/xml/XMLHttpRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ public void send(final Object content) {
771771
else {
772772
// Create and start a thread in which to execute the request.
773773
final HtmlUnitContextFactory cf = client.getJavaScriptEngine().getContextFactory();
774-
final ContextAction<Object> action = new ContextAction<Object>() {
774+
final ContextAction<Object> action = new ContextAction<>() {
775775
@Override
776776
public Object run(final Context cx) {
777777
doSend();

src/main/java/org/htmlunit/util/UrlUtils.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,12 +1356,7 @@ public static String encodeQueryPart(final String part) {
13561356
return "";
13571357
}
13581358

1359-
try {
1360-
return URLEncoder.encode(part, "UTF-8");
1361-
}
1362-
catch (final UnsupportedEncodingException e) {
1363-
return part;
1364-
}
1359+
return URLEncoder.encode(part, UTF_8);
13651360
}
13661361

13671362
/**

0 commit comments

Comments
 (0)