Skip to content

Commit

Permalink
Adjust PR code style; use {} around one-line ifs.
Browse files Browse the repository at this point in the history
Also do "return preferredMaximumBreakOffset" instead of "ret = preferredMaximumBreakOffset" in adjustBreakOffsetToWord, as suggested in PR comment. They are logically equivalent at this point in the code.
  • Loading branch information
eirikbakke committed Sep 13, 2018
1 parent 7364449 commit 08cb0cd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
Expand Up @@ -34,8 +34,9 @@ class CharSequenceCharacterIterator implements CharacterIterator {
private int index;

public CharSequenceCharacterIterator(CharSequence charSequence) {
if (charSequence == null)
if (charSequence == null) {
throw new NullPointerException();
}
this.charSequence = charSequence;
}

Expand All @@ -46,8 +47,9 @@ public int getIndex() {

@Override
public char setIndex(int position) {
if (position < getBeginIndex() || position > getEndIndex())
if (position < getBeginIndex() || position > getEndIndex()) {
throw new IllegalArgumentException();
}
this.index = position;
return current();
}
Expand All @@ -70,8 +72,9 @@ public char last() {

@Override
public char next() {
if (index < getEndIndex())
if (index < getEndIndex()) {
index++;
}
return current();
}

Expand Down
Expand Up @@ -785,10 +785,12 @@ static View breakView(int axis, int breakPartStartOffset, float x, float len,
static int adjustBreakOffsetToWord(CharSequence paragraph,
final int preferredMaximumBreakOffset, boolean allowWhitespaceBeyondEnd)
{
if (preferredMaximumBreakOffset < 0)
if (preferredMaximumBreakOffset < 0) {
throw new IllegalArgumentException();
if (preferredMaximumBreakOffset > paragraph.length())
}
if (preferredMaximumBreakOffset > paragraph.length()) {
throw new IllegalArgumentException();
}
/* BreakIterator.getLineInstance already seems to have a cache; creating a new instance here
is just the cost of BreakIterator.clone(). So don't bother trying to cache the BreakIterator
here. */
Expand All @@ -812,16 +814,18 @@ static int adjustBreakOffsetToWord(CharSequence paragraph,
ret = bi.isBoundary(preferredMaximumBreakOffset)
? preferredMaximumBreakOffset
: bi.preceding(preferredMaximumBreakOffset);
if (ret == BreakIterator.DONE)
ret = preferredMaximumBreakOffset;
if (ret == BreakIterator.DONE) {
return preferredMaximumBreakOffset;
}
}
if (ret == 0) {
// Skip forward to next boundary (for words longer than the preferred break offset).
ret = preferredMaximumBreakOffset > 0 && bi.isBoundary(preferredMaximumBreakOffset)
? preferredMaximumBreakOffset
: bi.following(preferredMaximumBreakOffset);
if (ret == BreakIterator.DONE)
if (ret == BreakIterator.DONE) {
ret = preferredMaximumBreakOffset;
}
/* The line-based break iterator will include whitespace trailing a word as well. Strip
this off so we can apply our own policy here. */
int retBeforeTrim = ret;
Expand All @@ -832,8 +836,9 @@ static int adjustBreakOffsetToWord(CharSequence paragraph,
}
/* If allowWhitespaceBeyondEnd is true, allow at most one whitespace character to trail
the word at the end. */
if ((allowWhitespaceBeyondEnd || ret == 0) && retBeforeTrim > ret)
if ((allowWhitespaceBeyondEnd || ret == 0) && retBeforeTrim > ret) {
ret++;
}
}
return ret;
}
Expand Down
Expand Up @@ -225,15 +225,18 @@ public TextWithCaret(String text, int caret) {
}

private TextWithCaret(String text, int caret, boolean check) {
if (text == null)
if (text == null) {
throw new NullPointerException();
if (caret < 0 || caret > text.length())
}
if (caret < 0 || caret > text.length()) {
throw new IllegalArgumentException();
}
this.text = text;
this.caret = caret;

if (check && !equals(fromEncoded(toString())))
if (check && !equals(fromEncoded(toString()))) {
throw new AssertionError();
}
}

/**
Expand All @@ -244,15 +247,17 @@ public static TextWithCaret fromEncoded(String encoded) {
Integer caret = null;
for (char ec : encoded.toCharArray()) {
if (ec == '|') {
if (caret != null)
if (caret != null) {
throw new IllegalArgumentException("Multiple caret positions specified");
}
caret = psb.length();
} else {
psb.append(ec);
}
}
if (caret == null)
if (caret == null) {
throw new IllegalArgumentException("No caret position specified");
}
return new TextWithCaret(psb.toString(), caret, false);
}

Expand All @@ -263,8 +268,9 @@ public String toString() {

@Override
public boolean equals(Object obj) {
if (!(obj instanceof TextWithCaret))
if (!(obj instanceof TextWithCaret)) {
return false;
}
TextWithCaret other = (TextWithCaret) obj;
return this.text.equals(other.text)
&& this.caret == other.caret;
Expand Down

0 comments on commit 08cb0cd

Please sign in to comment.