Skip to content

Commit b5a0a87

Browse files
committed
Replace size and length comparisons with isEmpty()
1 parent c12eb6f commit b5a0a87

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- Upgraded Android Gradle Plugin to 8.10.1
1313
- Fixed various Gradle-related deprecations
1414
- Replaced `printStackTrace()` with logging
15+
- Replaced `size()` and `length()` comparisons with `isEmpty()` check
1516

1617

1718
## [v1.4.2] (68) 煮者 (2025-01-12)

app/src/main/java/io/github/yawnoc/strokeinput/StrokeInputService.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ private Keyboard loadSavedKeyboard()
219219
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
220220
private static boolean isCommentLine(final String line)
221221
{
222-
return line.startsWith("#") || line.length() == 0;
222+
return line.startsWith("#") || line.isEmpty();
223223
}
224224

225225
@SuppressWarnings("SameParameterValue")
@@ -565,7 +565,7 @@ private void effectStrokeAppend(final String strokeDigit)
565565
{
566566
final String newStrokeDigitSequence = strokeDigitSequence + strokeDigit;
567567
final List<String> newCandidates = computeCandidates(newStrokeDigitSequence);
568-
if (newCandidates.size() > 0)
568+
if (!newCandidates.isEmpty())
569569
{
570570
setStrokeDigitSequence(newStrokeDigitSequence);
571571
setCandidates(newCandidates);
@@ -574,15 +574,15 @@ private void effectStrokeAppend(final String strokeDigit)
574574

575575
private void effectBackspace(final InputConnection inputConnection)
576576
{
577-
if (strokeDigitSequence.length() > 0)
577+
if (!strokeDigitSequence.isEmpty())
578578
{
579579
final String newStrokeDigitSequence = Stringy.removeSuffixRegex("(?s).", strokeDigitSequence);
580580
final List<String> newCandidates = computeCandidates(newStrokeDigitSequence);
581581

582582
setStrokeDigitSequence(newStrokeDigitSequence);
583583
setCandidates(newCandidates);
584584

585-
if (newStrokeDigitSequence.length() == 0)
585+
if (newStrokeDigitSequence.isEmpty())
586586
{
587587
setPhraseCompletionCandidates(inputConnection);
588588
}
@@ -593,7 +593,7 @@ private void effectBackspace(final InputConnection inputConnection)
593593
{
594594
final String upToOneCharacterBeforeCursor = getTextBeforeCursor(inputConnection, 1);
595595

596-
if (upToOneCharacterBeforeCursor.length() > 0)
596+
if (!upToOneCharacterBeforeCursor.isEmpty())
597597
{
598598
final CharSequence selection = inputConnection.getSelectedText(0);
599599
if (TextUtils.isEmpty(selection))
@@ -629,7 +629,7 @@ private void effectKeyboardSwitch(final String keyboardName)
629629

630630
private void effectSpaceKey(final InputConnection inputConnection)
631631
{
632-
if (strokeDigitSequence.length() > 0)
632+
if (!strokeDigitSequence.isEmpty())
633633
{
634634
onCandidate(getFirstCandidate());
635635
}
@@ -641,7 +641,7 @@ private void effectSpaceKey(final InputConnection inputConnection)
641641

642642
private void effectEnterKey(final InputConnection inputConnection)
643643
{
644-
if (strokeDigitSequence.length() > 0)
644+
if (!strokeDigitSequence.isEmpty())
645645
{
646646
onCandidate(getFirstCandidate());
647647
}
@@ -657,7 +657,7 @@ else if (enterKeyHasAction)
657657

658658
private void effectOrdinaryKey(final InputConnection inputConnection, final String valueText)
659659
{
660-
if (strokeDigitSequence.length() > 0)
660+
if (!strokeDigitSequence.isEmpty())
661661
{
662662
return;
663663
}
@@ -820,7 +820,7 @@ private int computeCandidateRank(
820820
final int fineRank;
821821
final int penalty;
822822

823-
final boolean phraseCompletionsIsEmpty = phraseCompletionFirstCodePoints.size() == 0;
823+
final boolean phraseCompletionsIsEmpty = phraseCompletionFirstCodePoints.isEmpty();
824824
final int phraseCompletionIndex = phraseCompletionFirstCodePoints.indexOf(firstCodePoint);
825825
final boolean firstCodePointMatchesPhraseCompletionCandidate = phraseCompletionIndex > 0;
826826

@@ -864,7 +864,7 @@ else if (firstCodePointMatchesPhraseCompletionCandidate)
864864

865865
private List<String> computeCandidates(final String strokeDigitSequence)
866866
{
867-
if (strokeDigitSequence.length() == 0)
867+
if (strokeDigitSequence.isEmpty())
868868
{
869869
return Collections.emptyList();
870870
}
@@ -947,7 +947,7 @@ private List<String> computePhraseCompletionCandidates(final InputConnection inp
947947

948948
for (
949949
String phrasePrefix = getTextBeforeCursor(inputConnection, MAX_PHRASE_LENGTH - 1);
950-
phrasePrefix.length() > 0;
950+
!phrasePrefix.isEmpty();
951951
phrasePrefix = Stringy.removePrefixRegex("(?s).", phrasePrefix)
952952
)
953953
{

app/src/main/java/io/github/yawnoc/strokeinput/StrokeSequenceBar.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2021, 2023 Conway
2+
Copyright 2021, 2023, 2025 Conway
33
Licensed under the GNU General Public License v3.0 (GPL-3.0-only).
44
This is free software with NO WARRANTY etc. etc.,
55
see LICENSE or <https://www.gnu.org/licenses/>.
@@ -25,7 +25,7 @@ public StrokeSequenceBar(Context context, AttributeSet attributes)
2525

2626
public void setStrokeDigitSequence(final String strokeDigitSequence)
2727
{
28-
if (strokeDigitSequence.length() > 0)
28+
if (!strokeDigitSequence.isEmpty())
2929
{
3030
final String strokeSequence =
3131
strokeDigitSequence

0 commit comments

Comments
 (0)