2525import static net .itarray .automotion .internal .geometry .Direction .*;
2626import static net .itarray .automotion .internal .geometry .Rectangle .ORIGIN_CORNER ;
2727import static net .itarray .automotion .internal .geometry .Scalar .scalar ;
28+ import static net .itarray .automotion .validation .properties .Expression .equalTo ;
2829import static org .apache .commons .lang3 .text .WordUtils .capitalize ;
2930
3031public class UIElement {
@@ -127,10 +128,13 @@ public Vector getCorner() {
127128 }
128129
129130 private <V extends MetricSpace <V >> boolean hasEqualExtendAs (UIElement other , ExtendGiving <V > direction , Context context ) {
130- Expression <Boolean > equal = Expression .equalTo (
131- ElementPropertyExpression .extend (direction , this ),
132- ElementPropertyExpression .extend (direction , other ));
133- return equal .evaluateIn (context , direction );
131+ return equalTo (
132+ extend (direction ),
133+ other .extend (direction )).evaluateIn (context , direction );
134+ }
135+
136+ public <V extends MetricSpace <V >> Expression <V > extend (ExtendGiving <V > direction ) {
137+ return ElementPropertyExpression .extend (direction , this );
134138 }
135139
136140 public boolean hasSameWidthAs (UIElement other , Context context ) {
@@ -173,7 +177,7 @@ private Scalar getOffset(Direction direction, UIElement page) {
173177 }
174178
175179 private boolean hasEqualOppositeOffsets (Direction direction , UIElement page , Context context ) {
176- return Expression . equalTo (
180+ return equalTo (
177181 new ConstantExpression <>(getOffset (direction , page )),
178182 new ConstantExpression <>(getOffset (direction .opposite (), page ))).evaluateIn (context , direction );
179183 }
@@ -239,10 +243,10 @@ public void validateBottomAlignedWith(UIElement element, Context context, Errors
239243 validateEqualEnd (DOWN , element , context , errors );
240244 }
241245
242- private void validateEqualEnd (Direction direction , UIElement element , Context context , Errors errors ) {
243- boolean valid = Expression . equalTo (
244- ElementPropertyExpression . end (direction , this ),
245- ElementPropertyExpression .end (direction , element )
246+ private < V extends MetricSpace < V >> void validateEqualEnd (ExtendGiving < V > direction , UIElement element , Context context , Errors errors ) {
247+ boolean valid = equalTo (
248+ end (direction ),
249+ element .end (direction )
246250 ).evaluateIn (context , direction );
247251 if (!valid ) {
248252 errors .add (String .format ("Element %s has not the same %s offset as element %s" ,
@@ -253,6 +257,10 @@ private void validateEqualEnd(Direction direction, UIElement element, Context co
253257 }
254258 }
255259
260+ public <V extends MetricSpace <V >> Expression <V > end (ExtendGiving <V > direction ) {
261+ return ElementPropertyExpression .end (direction , this );
262+ }
263+
256264 public void validateSameSize (UIElement element , Context context , Errors errors ) {
257265 validateSameExtend (ORIGIN_CORNER , element , context , errors );
258266 }
@@ -405,8 +413,7 @@ public void validateWidth(Condition<Scalar> condition, Context context, Errors e
405413 }
406414
407415 private void validateExtend (Direction direction , Condition <Scalar > condition , Context context , Errors errors ) {
408- ElementPropertyExpression <Scalar > property = ElementPropertyExpression .extend (direction , this );
409- Expression <Boolean > assertion = condition .applyTo (property );
416+ Expression <Boolean > assertion = condition .applyTo (extend (direction ));
410417 if (!assertion .evaluateIn (context , direction )) {
411418 errors .add (
412419 assertion .getDescription (context , direction ));
0 commit comments