@@ -98,10 +98,12 @@ public HyperlinkEvent transform() throws IllegalArgumentException {
98
98
*/
99
99
private EventType getEventTypeForDomEvent () throws IllegalArgumentException {
100
100
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." );
105
107
}
106
108
107
109
/**
@@ -145,25 +147,25 @@ private static Element getAnchor(Element domElement) throws IllegalArgumentExcep
145
147
}
146
148
147
149
/**
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.
149
151
*
150
152
* @param domNode
151
153
* the node which is checked for the a-tag
152
154
* @return an {@link Optional} containing an anchor if one was found; otherwise an empty {@code Optional}
153
155
*/
154
156
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
156
158
if (!domNode .isPresent ())
157
159
return Optional .empty ();
158
160
159
161
Node node = domNode .get ();
160
162
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
162
164
boolean nodeIsNoElement = !(node instanceof Element );
163
165
if (nodeIsNoElement )
164
166
return getAnchorAncestor (Optional .ofNullable (node .getParentNode ()));
165
167
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
167
169
Element element = (Element ) node ;
168
170
boolean isAnchor = element .getTagName ().equalsIgnoreCase ("a" );
169
171
if (isAnchor )
@@ -191,7 +193,6 @@ private static Optional<URL> createURL(Optional<String> baseURI, String href) {
191
193
} catch (MalformedURLException e ) {
192
194
// if LibFX supports logging, this could be logged:
193
195
// "Could not create a URL context from the base URI \"" + baseURI + "\".", e
194
- // until then return empty
195
196
}
196
197
197
198
// create URL from context and href
0 commit comments