1- /* Copyright 2021 Norconex Inc.
1+ /* Copyright 2021-2022 Norconex Inc.
22 *
33 * Licensed under the Apache License, Version 2.0 (the "License");
44 * you may not use this file except in compliance with the License.
2020import java .util .function .Predicate ;
2121
2222import org .apache .commons .lang3 .StringUtils ;
23- import org .apache .commons .lang3 .builder .EqualsBuilder ;
2423import org .apache .commons .lang3 .builder .EqualsExclude ;
25- import org .apache .commons .lang3 .builder .HashCodeBuilder ;
2624import org .apache .commons .lang3 .builder .HashCodeExclude ;
27- import org .apache .commons .lang3 .builder .ReflectionToStringBuilder ;
2825import org .apache .commons .lang3 .builder .ToStringExclude ;
29- import org .apache .commons .lang3 .builder .ToStringStyle ;
3026
3127import com .norconex .commons .lang .function .Predicates ;
3228import com .norconex .commons .lang .xml .IXMLConfigurable ;
3329import com .norconex .commons .lang .xml .XML ;
3430
31+ import lombok .EqualsAndHashCode ;
32+ import lombok .ToString ;
33+
3534/**
3635 * Represents a single "condition" tag or a "conditions" tag with nested
3736 * "condition" and/or "conditions".
3837 * @author Pascal Essiembre
3938 * @since 2.0.0
4039 */
40+ @ ToString
41+ @ EqualsAndHashCode
4142class XMLCondition <T > implements IXMLConfigurable , Predicate <T > {
4243
4344 enum Operator {
@@ -135,9 +136,7 @@ private Predicate<T> loadConditionFromXML(XML xml) {
135136 Predicate <T > parseConditionGroup (XML xml ) {
136137 List <Predicate <T >> predicateList = new ArrayList <>();
137138 Operator operator = Operator .of (xml .getString ("operator" ));
138- xml .forEach ("*" , x -> {
139- predicateList .add (loadConditionFromXML (x ));
140- });
139+ xml .forEach ("*" , x -> predicateList .add (loadConditionFromXML (x )));
141140 if (predicateList .size () == 1 ) {
142141 return predicateList .get (0 );
143142 }
@@ -149,12 +148,14 @@ Predicate<T> parseSingleCondition(XML predicateXML) {
149148 if (flow .getPredicateAdapter () != null ) {
150149 // If a predicate adapter is set, use it to parse the XML
151150 try {
152- //TODO throw XMLValidationException if there are any errors?
151+ //MAYBE: throw XMLValidationException if there are any errors?
153152 IXMLFlowPredicateAdapter <T > adapter =
154- flow .getPredicateAdapter ().newInstance ();
153+ flow .getPredicateAdapter ()
154+ .getDeclaredConstructor ()
155+ .newInstance ();
155156 adapter .loadFromXML (predicateXML );
156157 p = adapter ;
157- } catch (InstantiationException | IllegalAccessException e ) {
158+ } catch (Exception e ) {
158159 throw new XMLFlowException ("Predicate adapter "
159160 + flow .getPredicateAdapter ().getName () + " could not "
160161 + "resolve this XML: " + predicateXML , e );
@@ -173,18 +174,4 @@ Predicate<T> parseSingleCondition(XML predicateXML) {
173174 }
174175 return p ;
175176 }
176-
177- @ Override
178- public boolean equals (final Object other ) {
179- return EqualsBuilder .reflectionEquals (this , other );
180- }
181- @ Override
182- public int hashCode () {
183- return HashCodeBuilder .reflectionHashCode (this );
184- }
185- @ Override
186- public String toString () {
187- return new ReflectionToStringBuilder (
188- this , ToStringStyle .SHORT_PREFIX_STYLE ).toString ();
189- }
190177}
0 commit comments