Skip to content

Commit 4973a8b

Browse files
committed
Typo fixes and slight code cleanup
1 parent 40e8033 commit 4973a8b

File tree

7 files changed

+22
-24
lines changed

7 files changed

+22
-24
lines changed

app/src/main/java/com/phikal/regex/activities/GameActivity.java

+12-13
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@
4242
import static com.phikal.regex.Util.PROGRESS;
4343
import static com.phikal.regex.Util.notif;
4444

45-
class ColumAdapter extends ArrayAdapter {
46-
Context ctx;
47-
Column col;
45+
class ColumnAdapter extends ArrayAdapter {
46+
private Context ctx;
47+
private Column col;
4848

49-
public ColumAdapter(@NonNull Context context, Column column) {
49+
ColumnAdapter(@NonNull Context context, Column column) {
5050
super(context, 0);
5151
this.ctx = context;
5252
this.col = column;
@@ -76,7 +76,7 @@ public class GameActivity extends Activity {
7676
static boolean reload = false;
7777

7878
SharedPreferences prefs;
79-
LinearLayout colums;
79+
LinearLayout columns;
8080
EditText input;
8181
private Game game;
8282
private Task task;
@@ -97,7 +97,7 @@ protected void onCreate(Bundle savedInstanceState) {
9797
if (task == null)
9898
task = game.nextTask(getApplicationContext(), p -> {
9999
prefs.edit()
100-
.putFloat(game.name() + PROGRESS, (float) p.getDifficutly())
100+
.putFloat(game.name() + PROGRESS, (float) p.getDifficulty())
101101
.putInt(game.name() + COUNT, p.getRound())
102102
.apply();
103103
input.getEditableText().clear();
@@ -110,34 +110,33 @@ protected void onCreate(Bundle savedInstanceState) {
110110
return;
111111
}
112112

113-
assert task != null;
114113
assert task.getColumns() != null;
115114
assert task.getInput() != null;
116115

117116
// find and setup views
118-
colums = findViewById(R.id.columns);
117+
columns = findViewById(R.id.columns);
119118
RelativeLayout input_box = findViewById(R.id.input_box);
120119
Button status = input_box.findViewById(R.id.status);
121120
input = input_box.findViewById(R.id.input);
122121
ImageButton settings = input_box.findViewById(R.id.settings);
123122
LinearLayout charmb = findViewById(R.id.chars);
124123

125-
colums.setWeightSum(task.getColumns().size());
124+
columns.setWeightSum(task.getColumns().size());
126125
LayoutInflater inf = LayoutInflater.from(getApplicationContext());
127126
List<ArrayAdapter> adapters = new ArrayList<>(task.getColumns().size());
128127
for (Column col : task.getColumns()) {
129-
View v = inf.inflate(R.layout.column_layout, colums, false);
128+
View v = inf.inflate(R.layout.column_layout, columns, false);
130129

131130
TextView colName = v.findViewById(R.id.col_name);
132131
ListView colList = v.findViewById(R.id.col_list);
133132

134133
colName.setText(col.getHeader());
135134

136-
ColumAdapter ca = new ColumAdapter(getApplicationContext(), col);
135+
ColumnAdapter ca = new ColumnAdapter(getApplicationContext(), col);
137136
colList.setAdapter(ca);
138137
adapters.add(ca);
139138

140-
colums.addView(v);
139+
columns.addView(v);
141140
}
142141

143142
input.setHint(getString(game.name));
@@ -205,7 +204,7 @@ protected void onResume() {
205204
params.setMargins(0, 0, 0,
206205
(int) getResources().getDimension(
207206
show ? R.dimen.dstd : R.dimen.std));
208-
colums.setLayoutParams(params);
207+
columns.setLayoutParams(params);
209208

210209
input.requestFocus();
211210
}

app/src/main/java/com/phikal/regex/activities/SettingsActivity.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ private void stats() {
129129
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
130130
locale = getResources().getConfiguration().getLocales().get(0);
131131
else
132-
//noinspection deprecation
133132
locale = getResources().getConfiguration().locale;
134133

135134
String modeName = prefs.getString(MODE, Game.DEFAULT_GAME.name());
@@ -138,6 +137,6 @@ private void stats() {
138137

139138
// display progress
140139
roundsText.setText(String.valueOf(p.getRound()));
141-
difficultyText.setText(String.format(locale, "%.2f%%", p.getDifficutly() * 100));
140+
difficultyText.setText(String.format(locale, "%.2f%%", p.getDifficulty() * 100));
142141
}
143142
}

app/src/main/java/com/phikal/regex/games/match/IntroMatchTask.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public String getSolution() {
3737

3838
public class IntroMatchTask extends SimpleMatchTask {
3939

40-
// example tasks, ordered by difficutly
40+
// example tasks, ordered by difficulty
4141
private static final Example[] examples = {
4242
// lesson: basic matching
4343
new Example(
@@ -59,12 +59,12 @@ public class IntroMatchTask extends SimpleMatchTask {
5959
new String[]{"ac", "ab"},
6060
new String[]{"ca", "a"},
6161
"a."),
62-
// lesson: asterix operator
62+
// lesson: asterisk operator
6363
new Example(
6464
new String[]{"aaaa", "aaa", "aa", ""},
6565
new String[]{"ab", "ba", "bbbb"},
6666
"a*"),
67-
// lesson: char class, asterix operator
67+
// lesson: char class, asterisk operator
6868
new Example(
6969
new String[]{"acc", "bc", "bccc"},
7070
new String[]{"abc", "Accc", "accb"},
@@ -81,7 +81,7 @@ public class IntroMatchTask extends SimpleMatchTask {
8181
IntroMatchTask(Context ctx, Game g, Progress p, Progress.ProgressCallback pc) {
8282
super(ctx, g, p, pc);
8383

84-
int pos = ((int) (rnd.nextInt(examples.length) * (g.getProgress(ctx).getDifficutly() * 3 / 4 + 1 / 4)) + 1) % examples.length;
84+
int pos = ((int) (rnd.nextInt(examples.length) * (g.getProgress(ctx).getDifficulty() * 3 / 4 + 1 / 4)) + 1) % examples.length;
8585
this.example = examples[pos];
8686
}
8787

app/src/main/java/com/phikal/regex/games/match/MatchTask.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public Input getInput() {
4949
return input;
5050
}
5151

52-
protected class MatchWord extends Word implements Serializable {
52+
protected static class MatchWord extends Word implements Serializable {
5353
private final boolean match;
5454
private final String word;
5555

@@ -103,7 +103,7 @@ public void afterTextChanged(Editable pat) {
103103

104104
Input.Response res = Input.Response.OK;
105105

106-
int maxLength = (int) ((0.8 * Math.pow(getProgress().getDifficutly(), 1.5) + 0.2) * 24);
106+
int maxLength = (int) ((0.8 * Math.pow(getProgress().getDifficulty(), 1.5) + 0.2) * 24);
107107
int charsLeft = maxLength - pat.length();
108108

109109
pat.setFilters(new InputFilter[]{

app/src/main/java/com/phikal/regex/games/match/MutMatchTask.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ protected MatchWord randWord(boolean match) {
2626
char[] c = mutateOn.toCharArray();
2727

2828
for (int i = 0; i < c.length; i++) {
29-
double chance = (getProgress().getDifficutly() * getProgress().getDifficutly()) * (1 - GAMMA) + GAMMA;
29+
double chance = (getProgress().getDifficulty() * getProgress().getDifficulty()) * (1 - GAMMA) + GAMMA;
3030
if (rnd.nextDouble() > chance) {
3131
if (rnd.nextBoolean()) {
3232
int j = rnd.nextInt(c.length);

app/src/main/java/com/phikal/regex/models/Progress.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public Progress next(double factor) {
4141
rounds + 1);
4242
}
4343

44-
public double getDifficutly() {
44+
public double getDifficulty() {
4545
return difficulty;
4646
}
4747

app/src/main/java/com/phikal/regex/models/RegularExpression.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public abstract class RegularExpression {
190190

191191
static RegularExpression produceRE(double diff) {
192192
int opt = rnd.nextInt(4 + (int) Math.floor(4 * (1 - diff)));
193-
switch (opt < 0 ? 0 : opt) {
193+
switch (Math.max(opt, 0)) {
194194
case 0:
195195
return new ConcatRE(diff);
196196
case 1:

0 commit comments

Comments
 (0)