Skip to content

Commit 1f37a77

Browse files
committed
Merge branch 'release/2'
2 parents 8dca619 + 3fc2812 commit 1f37a77

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1181
-905
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
### General options ###
33
javaVersion=1.8
44
gradleVersion=3.5
5-
pluginVersion=1
5+
pluginVersion=2
66
# if set the 'idePath' then the version ignoring
77
# if 'sandboxDir' not set then use default sandbox directory (build/${product}-sandbox)
88
# if 'ideVersion' not set then use LATEST-EAP-SNAPSHOT

stepik-java-api/src/main/java/org/stepik/api/objects/attempts/Dataset.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import org.jetbrains.annotations.Nullable;
66

77
import java.util.ArrayList;
8-
import java.util.Arrays;
98
import java.util.List;
109

1110
/**
@@ -14,10 +13,10 @@
1413
public class Dataset {
1514
@SerializedName("is_multiple_choice")
1615
private boolean multipleChoice;
17-
private String[] options;
16+
private List<String> options;
1817
@SerializedName("is_text_disabled")
1918
private boolean textDisabled;
20-
private List<Pair> pairs;
19+
private List<StringPair> pairs;
2120
private List<String> rows;
2221
private List<String> columns;
2322
@SerializedName("is_checkbox")
@@ -80,14 +79,14 @@ public void setMultipleChoice(@Nullable Boolean multipleChoice) {
8079
}
8180

8281
@NotNull
83-
public String[] getOptions() {
82+
public List<String> getOptions() {
8483
if (options == null) {
85-
options = new String[0];
84+
options = new ArrayList<>();
8685
}
8786
return options;
8887
}
8988

90-
public void setOptions(@Nullable String[] options) {
89+
public void setOptions(@Nullable List<String> options) {
9190
this.options = options;
9291
}
9392

@@ -100,14 +99,14 @@ public void setTextDisabled(@Nullable Boolean textDisabled) {
10099
this.textDisabled = textDisabled;
101100
}
102101

103-
public List<Pair> getPairs() {
102+
public List<StringPair> getPairs() {
104103
if (pairs == null) {
105104
pairs = new ArrayList<>();
106105
}
107106
return pairs;
108107
}
109108

110-
public void setPairs(List<Pair> pairs) {
109+
public void setPairs(List<StringPair> pairs) {
111110
this.pairs = pairs;
112111
}
113112

@@ -133,8 +132,7 @@ public boolean equals(Object o) {
133132
if (multipleChoice != dataset.multipleChoice) return false;
134133
if (textDisabled != dataset.textDisabled) return false;
135134
if (isCheckbox != dataset.isCheckbox) return false;
136-
// Probably incorrect - comparing Object[] arrays with Arrays.equals
137-
if (!Arrays.equals(options, dataset.options)) return false;
135+
if (options != null ? !options.equals(dataset.options) : dataset.options != null) return false;
138136
if (pairs != null ? !pairs.equals(dataset.pairs) : dataset.pairs != null) return false;
139137
if (rows != null ? !rows.equals(dataset.rows) : dataset.rows != null) return false;
140138
if (columns != null ? !columns.equals(dataset.columns) : dataset.columns != null) return false;
@@ -146,7 +144,7 @@ public boolean equals(Object o) {
146144
@Override
147145
public int hashCode() {
148146
int result = (multipleChoice ? 1 : 0);
149-
result = 31 * result + Arrays.hashCode(options);
147+
result = 31 * result + (options != null ? options.hashCode() : 0);
150148
result = 31 * result + (textDisabled ? 1 : 0);
151149
result = 31 * result + (pairs != null ? pairs.hashCode() : 0);
152150
result = 31 * result + (rows != null ? rows.hashCode() : 0);

stepik-java-api/src/main/java/org/stepik/api/objects/attempts/DatasetDeserializer.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,12 @@ public Dataset deserialize(JsonElement json, Type typeOfT, JsonDeserializationCo
4949
Boolean textDisabled = getBoolean(object, "is_text_disabled");
5050
dataset.setTextDisabled(textDisabled);
5151

52-
JsonArray options = getJsonArray(object, "options");
53-
if (options != null) {
54-
List<String> optionsArray = new ArrayList<>();
55-
options.forEach(option -> optionsArray.add(option.getAsString()));
56-
dataset.setOptions(optionsArray.toArray(new String[optionsArray.size()]));
57-
}
52+
dataset.setOptions(getStringList(object, "options"));
5853

5954
JsonArray pairs = getJsonArray(object, "pairs");
6055
if (pairs != null) {
61-
List<Pair> array = new ArrayList<>();
62-
pairs.forEach(pair -> array.add(context.deserialize(pair, Pair.class)));
56+
List<StringPair> array = new ArrayList<>();
57+
pairs.forEach(pair -> array.add(context.deserialize(pair, StringPair.class)));
6358
dataset.setPairs(array);
6459
}
6560

stepik-java-api/src/main/java/org/stepik/api/objects/attempts/Pair.java renamed to stepik-java-api/src/main/java/org/stepik/api/objects/attempts/StringPair.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
/**
44
* @author meanmail
55
*/
6-
public class Pair {
6+
public class StringPair {
77
private String first;
88
private String second;
99

10-
public Pair(String first, String second) {
10+
public StringPair(String first, String second) {
1111
this.first = first;
1212
this.second = second;
1313
}
@@ -39,7 +39,7 @@ public boolean equals(Object o) {
3939
if (this == o) return true;
4040
if (o == null || getClass() != o.getClass()) return false;
4141

42-
Pair pair = (Pair) o;
42+
StringPair pair = (StringPair) o;
4343

4444
//noinspection SimplifiableIfStatement
4545
if (first != null ? !first.equals(pair.first) : pair.first != null) return false;
Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,43 @@
11
package org.stepik.api.objects.recommendations;
22

3+
import org.jetbrains.annotations.NotNull;
4+
5+
import java.util.Arrays;
6+
import java.util.HashMap;
7+
38
/**
49
* @author meanmail
510
*/
611
public enum ReactionValues {
7-
TOO_EASY(-1), TOO_HARD(0), INTERESTING(1), SOLVED(2);
12+
UNKNOWN(Integer.MIN_VALUE), TOO_EASY(-1), TOO_HARD(0), INTERESTING(1), SOLVED(2);
813

14+
private static HashMap<String, ReactionValues> map;
915
private final int value;
1016

1117
ReactionValues(int value) {
1218
this.value = value;
1319
}
1420

21+
public static ReactionValues of(@NotNull String value) {
22+
if (map == null) {
23+
map = new HashMap<>();
24+
Arrays.stream(values())
25+
.forEach(reactionValues -> map.put(reactionValues.name().toLowerCase(), reactionValues));
26+
}
27+
return map.getOrDefault(value, UNKNOWN);
28+
}
29+
1530
public int getValue() {
1631
return value;
1732
}
33+
34+
public boolean in(ReactionValues... values) {
35+
for (ReactionValues value : values) {
36+
if (this.equals(value)) {
37+
return true;
38+
}
39+
}
40+
41+
return false;
42+
}
1843
}

stepik-java-api/src/main/java/org/stepik/api/objects/submissions/Reply.java

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,11 @@ public void setAttachments(@Nullable List<Attachment> attachments) {
7171
this.attachments = attachments;
7272
}
7373

74-
@Nullable
74+
@NotNull
7575
public String getText() {
76+
if (text == null) {
77+
text = "";
78+
}
7679
return text;
7780
}
7881

@@ -120,17 +123,23 @@ public void setOrdering(@Nullable List<Integer> ordering) {
120123
this.ordering = ordering;
121124
}
122125

123-
@Nullable
126+
@NotNull
124127
public String getNumber() {
128+
if (number == null) {
129+
number = "";
130+
}
125131
return number;
126132
}
127133

128134
public void setNumber(@Nullable String number) {
129135
this.number = number;
130136
}
131137

132-
@Nullable
138+
@NotNull
133139
public String getFile() {
140+
if (file == null) {
141+
file = "";
142+
}
134143
return file;
135144
}
136145

@@ -161,4 +170,41 @@ public List<String> getBlanks() {
161170
public void setBlanks(@Nullable List<String> blanks) {
162171
this.blanks = blanks;
163172
}
173+
174+
@Override
175+
public boolean equals(Object o) {
176+
if (this == o) return true;
177+
if (o == null || getClass() != o.getClass()) return false;
178+
179+
Reply reply = (Reply) o;
180+
181+
if (!getLanguage().equals(reply.getLanguage())) return false;
182+
if (!getCode().equals(reply.getCode())) return false;
183+
if (!getFormula().equals(reply.getFormula())) return false;
184+
if (!getAttachments().equals(reply.getAttachments())) return false;
185+
if (!getText().equals(reply.getText())) return false;
186+
if (!getFiles().equals(reply.getFiles())) return false;
187+
if (!getChoices().equals(reply.getChoices())) return false;
188+
if (!getOrdering().equals(reply.getOrdering())) return false;
189+
if (!getNumber().equals(reply.getNumber())) return false;
190+
//noinspection SimplifiableIfStatement
191+
if (!getFile().equals(reply.getFile())) return false;
192+
return getBlanks().equals(reply.getBlanks());
193+
}
194+
195+
@Override
196+
public int hashCode() {
197+
int result = getLanguage().hashCode();
198+
result = 31 * result + getCode().hashCode();
199+
result = 31 * result + getFormula().hashCode();
200+
result = 31 * result + getAttachments().hashCode();
201+
result = 31 * result + getText().hashCode();
202+
result = 31 * result + getFiles().hashCode();
203+
result = 31 * result + getChoices().hashCode();
204+
result = 31 * result + getOrdering().hashCode();
205+
result = 31 * result + getNumber().hashCode();
206+
result = 31 * result + getFile().hashCode();
207+
result = 31 * result + getBlanks().hashCode();
208+
return result;
209+
}
164210
}

stepik-java-api/src/main/java/org/stepik/api/objects/submissions/Submission.java

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,18 @@
55
import org.jetbrains.annotations.Nullable;
66
import org.stepik.api.objects.AbstractObject;
77

8+
import java.text.ParseException;
9+
import java.text.SimpleDateFormat;
10+
import java.time.Instant;
11+
import java.util.Date;
12+
import java.util.TimeZone;
13+
814
/**
915
* @author meanmail
1016
*/
1117
public class Submission extends AbstractObject {
18+
private final static SimpleDateFormat timeISOFormat = getTimeISOFormat();
19+
1220
private String status;
1321
private double score;
1422
private String hint;
@@ -20,6 +28,14 @@ public class Submission extends AbstractObject {
2028
private int attempt;
2129
private String session;
2230
private double eta;
31+
private transient Date utcTime;
32+
33+
private static SimpleDateFormat getTimeISOFormat() {
34+
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
35+
TimeZone tz = TimeZone.getTimeZone("UTC");
36+
format.setTimeZone(tz);
37+
return format;
38+
}
2339

2440
@NotNull
2541
public String getStatus() {
@@ -57,13 +73,21 @@ public void setReply(@Nullable Reply reply) {
5773
this.reply = reply;
5874
}
5975

60-
@Nullable
61-
public String getTime() {
62-
return time;
76+
@NotNull
77+
public Date getTime() {
78+
if (utcTime == null) {
79+
try {
80+
utcTime = timeISOFormat.parse(time);
81+
} catch (ParseException e) {
82+
return Date.from(Instant.EPOCH);
83+
}
84+
}
85+
return utcTime;
6386
}
6487

65-
public void setTime(@Nullable String time) {
66-
this.time = time;
88+
public void setTime(@Nullable Date time) {
89+
this.time = timeISOFormat.format(time);
90+
utcTime = time;
6791
}
6892

6993
public double getScore() {

stepik-java-api/src/main/java/org/stepik/api/objects/submissions/SubmissionPost.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.stepik.api.objects.submissions;
22

33
import org.jetbrains.annotations.NotNull;
4+
import org.jetbrains.annotations.Nullable;
45

56
/**
67
* @author meanmail
@@ -17,6 +18,10 @@ public Reply getReply() {
1718
return reply;
1819
}
1920

21+
public void setReply(@Nullable Reply reply) {
22+
this.reply = reply;
23+
}
24+
2025
public long getAttempt() {
2126
return attempt;
2227
}

stepik-java-api/src/main/java/org/stepik/api/queries/submissions/StepikSubmissionsPostQuery.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.jetbrains.annotations.Nullable;
55
import org.stepik.api.actions.StepikAbstractAction;
66
import org.stepik.api.objects.submissions.Attachment;
7+
import org.stepik.api.objects.submissions.Reply;
78
import org.stepik.api.objects.submissions.Submissions;
89
import org.stepik.api.objects.submissions.SubmissionsPost;
910
import org.stepik.api.queries.StepikAbstractPostQuery;
@@ -98,4 +99,9 @@ public StepikSubmissionsPostQuery code(@NotNull String value) {
9899
protected String getBody() {
99100
return getJsonConverter().toJson(submissions);
100101
}
102+
103+
public StepikSubmissionsPostQuery reply(@NotNull Reply reply) {
104+
submissions.getSubmission().setReply(reply);
105+
return this;
106+
}
101107
}

stepik-union/src/main/java/org/stepik/core/StudyUtils.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package org.stepik.core;
22

3-
import com.intellij.ide.ui.LafManager;
4-
import com.intellij.ide.ui.laf.darcula.DarculaLookAndFeelInfo;
53
import com.intellij.openapi.diagnostic.Logger;
64
import com.intellij.openapi.project.Project;
75
import com.intellij.openapi.vfs.VirtualFile;
@@ -18,14 +16,11 @@
1816
import org.stepik.api.objects.steps.Step;
1917
import org.stepik.api.objects.steps.Steps;
2018
import org.stepik.core.courseFormat.StudyNode;
21-
import org.stepik.core.courseFormat.stepHelpers.StepHelper;
22-
import org.stepik.core.templates.Templater;
2319
import org.stepik.core.ui.StudyToolWindow;
2420
import org.stepik.core.ui.StudyToolWindowFactory;
2521
import org.stepik.core.utils.ProjectFilesUtils;
2622

2723
import javax.swing.*;
28-
import java.util.HashMap;
2924
import java.util.regex.Matcher;
3025
import java.util.regex.Pattern;
3126

@@ -76,20 +71,6 @@ static StudyToolWindow getStudyToolWindow(@NotNull final Project project) {
7671
return null;
7772
}
7873

79-
@NotNull
80-
public static String getStepContent(@NotNull StepHelper stepHelper) {
81-
return processTemplate(stepHelper, "quiz/" + stepHelper.getType());
82-
}
83-
84-
@NotNull
85-
private static String processTemplate(@NotNull StepHelper stepHelper, @NotNull String templateName) {
86-
HashMap<String, Object> params = new HashMap<>();
87-
params.put("stepNode", stepHelper);
88-
params.put("darcula", LafManager.getInstance().getCurrentLookAndFeel() instanceof DarculaLookAndFeelInfo);
89-
90-
return Templater.processTemplate(templateName, params);
91-
}
92-
9374
@Nullable
9475
public static StudyPluginConfigurator getConfigurator(@NotNull final Project project) {
9576
StudyPluginConfigurator[] extensions = StudyPluginConfigurator.EP_NAME.getExtensions();

0 commit comments

Comments
 (0)