Skip to content

Commit

Permalink
Improve code organization and readability in 'StandardParagraph.java'
Browse files Browse the repository at this point in the history
In the 'StandardParagraph.java' file, some code blocks were rearranged to improve organization and readability. More specifically, we moved the declaration of the 'runs' variable and methods 'firstRun', 'getP', and 'getAffectedRuns'. This commit does not change any functionalities but should help future development by making the code easier to follow.
  • Loading branch information
caring-coder committed Oct 19, 2024
1 parent 551c243 commit d80d724
Showing 1 changed file with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ public class StandardParagraph
implements Paragraph {

private static final Random RANDOM = new Random();

private List<IndexedRun> runs;
private final List<Object> contents;
private final P p;
private List<IndexedRun> runs;

private StandardParagraph(List<Object> paragraphContent, P p) {
this.contents = paragraphContent;
Expand Down Expand Up @@ -93,6 +92,22 @@ public static StandardParagraph from(CTSdtContentRun paragraph) {
return commentWrapper;
}

@Override public R firstRun() {
return (R) paragraphContent().get(0);
}

/**
* Retrieves the P object associated with this StandardParagraph.
*
* @return the P object of this paragraph.
*
* @deprecated Not recommended, as will be replaced by other API
*/
@Deprecated(since = "2.6", forRemoval = true)
@Override public P getP() {
return p;
}

/**
* Replaces the given expression with the replacement object within
* the paragraph.
Expand Down Expand Up @@ -134,21 +149,6 @@ else if (replacement instanceof Br br) {
return contents;
}

@Override public R firstRun() {
return (R) paragraphContent().get(0);
}

/**
* Retrieves the P object associated with this StandardParagraph.
*
* @return the P object of this paragraph.
* @deprecated Not recommended, as will be replaced by other API
*/
@Deprecated(since = "2.6", forRemoval = true) @Override public P getP() {
return p;
}

/**
* Retrieves the parent object of the current paragraph.
*
Expand Down Expand Up @@ -230,6 +230,12 @@ private void replaceWithBr(Placeholder placeholder, Br br) {
}
}

private List<IndexedRun> getAffectedRuns(int startIndex, int endIndex) {
return runs.stream()
.filter(run -> run.isTouchedByRange(startIndex, endIndex))
.toList();
}

private void removeExpression(
IndexedRun firstRun,
int matchStartIndex,
Expand Down Expand Up @@ -262,12 +268,6 @@ private static void replaceWithBr(
}
}

private List<IndexedRun> getAffectedRuns(int startIndex, int endIndex) {
return runs.stream()
.filter(run -> run.isTouchedByRange(startIndex, endIndex))
.toList();
}

/**
* {@inheritDoc}
*/
Expand Down

0 comments on commit d80d724

Please sign in to comment.