Skip to content

Commit

Permalink
fix bad bool comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
alextekartik committed Sep 11, 2023
1 parent a04fdc2 commit eb02747
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 143 deletions.
2 changes: 1 addition & 1 deletion app/lib/sequence_validator/sequence_validator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ class SequenceValidator {
var completer = _endValidator = Completer<bool>();
Future<void>.delayed(const Duration(milliseconds: _smallDiff))
.then((_) {
if (completer.isCompleted) {
if (!completer.isCompleted) {
completer.complete(true);
}
});
Expand Down
142 changes: 0 additions & 142 deletions app/test/sequence_validator_test.dart
Original file line number Diff line number Diff line change
@@ -1,145 +1,3 @@
/*
package com.tekartik.utils.sequence;
import android.annotation.SuppressLint;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import static java.lang.Boolean.TRUE;
/**
* Created by alex on 23/05/16.
* <p>
* Basic tap pattern recognition
*/
public abstract class SequenceValidator {
int sequenceIndex = 0;
private long lastTime = 0;
static private boolean smallDiff(long diff) {
return diff <= 500;
}
// Ok in Multi, not ok in Suite for small group
static private boolean mediumDiff(long diff) {
return diff <= 1000;
}
// True if at least 500ms
static private boolean largeDiff(long diff) {
return diff >= 500 && diff < 3000;
}
protected abstract boolean validate(long timestamp, long diff);
public boolean validate(long timestamp) {
long diff = timestamp - lastTime;
if (diff > 1500) {
sequenceIndex = 0;
}
boolean validated = validate(timestamp, diff);
lastTime = timestamp;
return validated;
}
@SuppressWarnings("unused")
public boolean validate() {
return validate(System.currentTimeMillis());
}
static public class Multi extends SequenceValidator {
static final int DEFAULT_MULTI_COUNT = 6;
private final int multiCount; // Default multi count
public Multi() {
this(DEFAULT_MULTI_COUNT);
}
public Multi(int multiCount) {
this.multiCount = multiCount;
}
@Override
protected boolean validate(long timestamp, long diff) {
if (sequenceIndex == 0) {
sequenceIndex = 1;
} else {
if (mediumDiff(diff)) {
sequenceIndex++;
} else {
sequenceIndex = 1;
}
}
if (sequenceIndex == multiCount) {
return true;
}
return false;
}
}
static public class Suite extends SequenceValidator {
static final List<Integer> SUITE_LIST_DEFAUT = Arrays.asList(2, 3, 1);
private final List<Integer> list;
private final int sequenceCount;
@SuppressLint("UseSparseArrays")
private final HashMap<Integer, Boolean> sequenceDiffs = new HashMap<>();
public Suite() {
this(SUITE_LIST_DEFAUT);
}
public Suite(List<Integer> list) {
this.list = list;
int index = 0;
for (int count : list) {
// for the first allow any
index++;
for (int i = 1; i < count; i++) {
// requires small diff then
sequenceDiffs.put(index++, true);
}
}
sequenceCount = index;
}
@Override
protected boolean validate(long timestamp, long diff) {
if (sequenceIndex == 0) {
sequenceIndex = 1;
} else {
Boolean checkSmallDiff = sequenceDiffs.get(sequenceIndex);
if (TRUE.equals(checkSmallDiff)) {
if (SequenceValidator.smallDiff(diff)) {
sequenceIndex++;
} else {
sequenceIndex = 1;
}
} else if (SequenceValidator.largeDiff(diff)) {
sequenceIndex++;
} else {
sequenceIndex = 1;
}
}
if (sequenceIndex == sequenceCount) {
return true;
}
return false;
}
}
}
*/
import 'dart:async';

import 'package:tekartik_app_common_utils/sequence_validator/sequence_validator.dart';
Expand Down

0 comments on commit eb02747

Please sign in to comment.