Skip to content

Commit 4cfce1a

Browse files
author
nicolaiparlog
committed
Minor improvements of syntax and comments in 'DomEventToHyperlinkEventTransformer'.
1 parent 7566c86 commit 4cfce1a

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/main/java/org/codefx/libfx/dom/DomEventToHyperlinkEventTransformer.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,12 @@ public HyperlinkEvent transform() throws IllegalArgumentException {
9898
*/
9999
private EventType getEventTypeForDomEvent() throws IllegalArgumentException {
100100
Optional<EventType> eventType = getEventTypeFrom(domEvent);
101-
return eventType.orElseThrow(
102-
() -> new IllegalArgumentException(
103-
"The DOM event '" + domEvent + "' of type '" + domEvent.getType()
104-
+ "' can not be transformed to a hyperlink event."));
101+
if (eventType.isPresent())
102+
return eventType.get();
103+
else
104+
throw new IllegalArgumentException(
105+
"The DOM event '" + domEvent + "' of type '" + domEvent.getType()
106+
+ "' can not be transformed to a hyperlink event.");
105107
}
106108

107109
/**
@@ -145,25 +147,25 @@ private static Element getAnchor(Element domElement) throws IllegalArgumentExcep
145147
}
146148

147149
/**
148-
* Searches for an a-tag starting on the specified and recursing to its ancestors.
150+
* Searches for an a-tag starting on the specified node and recursing to its ancestors.
149151
*
150152
* @param domNode
151153
* the node which is checked for the a-tag
152154
* @return an {@link Optional} containing an anchor if one was found; otherwise an empty {@code Optional}
153155
*/
154156
private static Optional<Element> getAnchorAncestor(Optional<Node> domNode) {
155-
// if there is no node, there was no anchor, so return empty
157+
// if there is no node, there can be no anchor, so return empty
156158
if (!domNode.isPresent())
157159
return Optional.empty();
158160

159161
Node node = domNode.get();
160162

161-
// if the node is no element, recurse to its parent
163+
// only elements can be anchors, so if the node is no element, recurse to its parent
162164
boolean nodeIsNoElement = !(node instanceof Element);
163165
if (nodeIsNoElement)
164166
return getAnchorAncestor(Optional.ofNullable(node.getParentNode()));
165167

166-
// if the node is an element, check whether it is an anchor
168+
// if the node is an element, it might be an anchor
167169
Element element = (Element) node;
168170
boolean isAnchor = element.getTagName().equalsIgnoreCase("a");
169171
if (isAnchor)
@@ -191,7 +193,6 @@ private static Optional<URL> createURL(Optional<String> baseURI, String href) {
191193
} catch (MalformedURLException e) {
192194
// if LibFX supports logging, this could be logged:
193195
// "Could not create a URL context from the base URI \"" + baseURI + "\".", e
194-
// until then return empty
195196
}
196197

197198
// create URL from context and href

0 commit comments

Comments
 (0)