Skip to content

Commit

Permalink
Fix ParStyle equals & indent (#943)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jugen authored Aug 6, 2020
1 parent 14534d0 commit bec3e38
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,16 @@ public ParStyle(Optional<TextAlignment> alignment, Optional<Color> backgroundCol

@Override
public int hashCode() {
return Objects.hash(alignment, backgroundColor);
return Objects.hash(alignment, backgroundColor, indent);
}

@Override
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;
}
Expand Down Expand Up @@ -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 ) );
}

}

0 comments on commit bec3e38

Please sign in to comment.