From bec3e386513d3e213414ed9ed0d4044e936f412d Mon Sep 17 00:00:00 2001 From: Jurgen Date: Thu, 6 Aug 2020 16:16:21 +0200 Subject: [PATCH] Fix ParStyle equals & indent (#943) --- .../fxmisc/richtext/demo/richtext/Indent.java | 17 +++++++++++++++++ .../fxmisc/richtext/demo/richtext/ParStyle.java | 15 ++++++--------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/richtextfx-demos/src/main/java/org/fxmisc/richtext/demo/richtext/Indent.java b/richtextfx-demos/src/main/java/org/fxmisc/richtext/demo/richtext/Indent.java index 0dbf20aba..5d3c50eb5 100644 --- a/richtextfx-demos/src/main/java/org/fxmisc/richtext/demo/richtext/Indent.java +++ b/richtextfx-demos/src/main/java/org/fxmisc/richtext/demo/richtext/Indent.java @@ -4,4 +4,21 @@ public class Indent { double width = 15; int level = 1; + + Indent() {} + + Indent( int level ) + { + if ( level > 0 ) this.level = level; + } + + Indent increase() + { + return new Indent( level+1 ); + } + + Indent decrease() + { + return new Indent( level-1 ); + } } diff --git a/richtextfx-demos/src/main/java/org/fxmisc/richtext/demo/richtext/ParStyle.java b/richtextfx-demos/src/main/java/org/fxmisc/richtext/demo/richtext/ParStyle.java index 5a696d2c6..39fa10d64 100644 --- a/richtextfx-demos/src/main/java/org/fxmisc/richtext/demo/richtext/ParStyle.java +++ b/richtextfx-demos/src/main/java/org/fxmisc/richtext/demo/richtext/ParStyle.java @@ -73,7 +73,7 @@ public ParStyle(Optional alignment, Optional backgroundCol @Override public int hashCode() { - return Objects.hash(alignment, backgroundColor); + return Objects.hash(alignment, backgroundColor, indent); } @Override @@ -81,7 +81,8 @@ public boolean equals(Object other) { if(other instanceof ParStyle) { ParStyle that = (ParStyle) other; return Objects.equals(this.alignment, that.alignment) && - Objects.equals(this.backgroundColor, that.backgroundColor); + Objects.equals(this.backgroundColor, that.backgroundColor) && + Objects.equals(this.indent, that.indent); } else { return false; } @@ -134,16 +135,12 @@ public ParStyle updateIndent(Indent indent) { } public ParStyle increaseIndent() { - if ( indent.isPresent() ) indent.get().level++; - else return updateIndent( new Indent() ); - return this; + return updateIndent( indent.map( Indent::increase ).orElseGet( Indent::new ) ); } public ParStyle decreaseIndent() { - if ( indent.isPresent() && --indent.get().level == 0 ) { - return updateIndent( null ); - } - return this; + return updateIndent( indent.filter( in -> in.level > 1 ) + .map( Indent::decrease ).orElse( null ) ); } }