optimized the word pair save time
This commit is contained in:
parent
c689284af5
commit
3f76f40058
3 changed files with 29 additions and 13 deletions
|
|
@ -86,8 +86,16 @@ public class InsertOps {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StringBuilder sql = new StringBuilder(
|
||||||
|
"INSERT INTO " + Tables.getWordPairs(langId) + " (word1, word2, sequence2) VALUES"
|
||||||
|
);
|
||||||
|
|
||||||
for (WordPair pair : pairs) {
|
for (WordPair pair : pairs) {
|
||||||
db.insert(Tables.getWordPairs(langId), null, pair.toContentValues());
|
sql.append(pair.toSqlRow()).append(",");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sql.setLength(sql.length() - 1);
|
||||||
|
|
||||||
|
db.execSQL(sql.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
package io.github.sspanak.tt9.db.wordPairs;
|
package io.github.sspanak.tt9.db.wordPairs;
|
||||||
|
|
||||||
import android.content.ContentValues;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
|
@ -31,7 +29,7 @@ public class WordPair {
|
||||||
|| word1.isEmpty() || word2.isEmpty()
|
|| word1.isEmpty() || word2.isEmpty()
|
||||||
|| (word1.length() > SettingsStore.WORD_PAIR_MAX_WORD_LENGTH && word2.length() > SettingsStore.WORD_PAIR_MAX_WORD_LENGTH)
|
|| (word1.length() > SettingsStore.WORD_PAIR_MAX_WORD_LENGTH && word2.length() > SettingsStore.WORD_PAIR_MAX_WORD_LENGTH)
|
||||||
|| word1.equals(word2)
|
|| word1.equals(word2)
|
||||||
|| sequence2 == null || word2.length() != sequence2.length()
|
|| sequence2 == null || word2.length() != sequence2.length() || !(new Text(sequence2).isNumeric())
|
||||||
|| !(new Text(word1).isAlphabetic()) || !(new Text(word2).isAlphabetic());
|
|| !(new Text(word1).isAlphabetic()) || !(new Text(word2).isAlphabetic());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -42,15 +40,6 @@ public class WordPair {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public ContentValues toContentValues() {
|
|
||||||
ContentValues values = new ContentValues();
|
|
||||||
values.put("word1", word1);
|
|
||||||
values.put("word2", word2);
|
|
||||||
values.put("sequence2", sequence2);
|
|
||||||
return values;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
if (hash == null) {
|
if (hash == null) {
|
||||||
|
|
@ -67,6 +56,11 @@ public class WordPair {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String toSqlRow() {
|
||||||
|
return "('" + word1 + "','" + word2 + "','" + sequence2 + "')";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,20 @@ public class Text extends TextTools {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isNumeric() {
|
||||||
|
if (text == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0, end = text.length(); i < end; i++) {
|
||||||
|
if (!Character.isDigit(text.charAt(i))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
return text == null || text.isEmpty();
|
return text == null || text.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue