Skip to content

Commit

Permalink
from pojo to records
Browse files Browse the repository at this point in the history
  • Loading branch information
gekoramy committed Oct 27, 2024
1 parent 6341d0e commit 50b20aa
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 136 deletions.
2 changes: 1 addition & 1 deletion src/main/java/me/gekoramy/github/quiz/app/AppExam.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import javafx.stage.Stage;
import me.gekoramy.github.quiz.app.exam.ExamPresenter;
import me.gekoramy.github.quiz.app.exam.ExamView;
import me.gekoramy.github.quiz.pojo.Question;
import me.gekoramy.github.quiz.records.Question;
import org.eclipse.egit.github.core.Repository;

import java.util.HashMap;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/gekoramy/github/quiz/app/AppPreview.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import javafx.stage.Stage;
import me.gekoramy.github.quiz.app.preview.PreviewPresenter;
import me.gekoramy.github.quiz.app.preview.PreviewView;
import me.gekoramy.github.quiz.pojo.Question;
import me.gekoramy.github.quiz.records.Question;
import me.gekoramy.github.quiz.service.ExamStarter;
import me.gekoramy.github.quiz.service.OpenLink;
import me.gekoramy.github.quiz.service.UpdateAvailable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import javafx.scene.layout.BorderPane;
import me.gekoramy.github.quiz.app.exam.quiz.QuizPresenter;
import me.gekoramy.github.quiz.app.exam.quiz.QuizView;
import me.gekoramy.github.quiz.pojo.Question;
import me.gekoramy.github.quiz.records.Question;
import me.gekoramy.github.quiz.service.EditContent;
import org.eclipse.egit.github.core.Repository;

Expand Down Expand Up @@ -92,7 +92,7 @@ public void setAccelerators(Scene scene) {
private void createQuiz(int i) {
Map<Object, Object> customProperties = new HashMap<>();
customProperties.put("question", questions.get(i));
customProperties.put("editContent", new EditContent(hostServices, repo, questions.get(i).getId()));
customProperties.put("editContent", new EditContent(hostServices, repo, questions.get(i).id()));

QuizView q = new QuizView(customProperties::get);
QuizPresenter p = ((QuizPresenter) q.getPresenter());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import me.gekoramy.github.quiz.exception.NotLoggedException;
import me.gekoramy.github.quiz.pojo.Question;
import me.gekoramy.github.quiz.records.Question;
import me.gekoramy.github.quiz.service.EditContent;
import me.gekoramy.github.quiz.util.GitHubClients;

Expand Down Expand Up @@ -49,10 +49,10 @@ public class QuizPresenter implements Initializable {

@Override
public void initialize(URL location, ResourceBundle resources) {
String txt = question.getQuestion();
String txt = question.question();
txtQuestion.setText(txt);

for (String answer : question.getAnswers()) {
for (String answer : question.answers()) {
RadioButton tmp = new RadioButton(answer);
tmp.setWrapText(true);
tmp.setToggleGroup(group);
Expand Down Expand Up @@ -145,23 +145,23 @@ private int getChosenAnswer() {
* false otherwise
*/
public boolean isCorrect() {
return getChosenAnswer() == question.getCorrect();
return getChosenAnswer() == question.correct();
}

/**
* highlight the correct answer
*/
public void showCorrect() {
btnPeek.setText("!");
options.get(question.getCorrect()).setBackground(CORRECT_BG);
options.get(question.correct()).setBackground(CORRECT_BG);
}

/**
* make all the answers look the same
*/
private void hideCorrect() {
btnPeek.setText("?");
options.get(question.getCorrect()).setBackground(Background.EMPTY);
options.get(question.correct()).setBackground(Background.EMPTY);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package me.gekoramy.github.quiz.persistance;

import javafx.util.Pair;
import me.gekoramy.github.quiz.pojo.Question;
import me.gekoramy.github.quiz.records.Question;
import me.gekoramy.github.quiz.util.Pool;
import org.eclipse.egit.github.core.Repository;

Expand Down
46 changes: 0 additions & 46 deletions src/main/java/me/gekoramy/github/quiz/pojo/Data.java

This file was deleted.

73 changes: 0 additions & 73 deletions src/main/java/me/gekoramy/github/quiz/pojo/Question.java

This file was deleted.

17 changes: 17 additions & 0 deletions src/main/java/me/gekoramy/github/quiz/records/Data.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package me.gekoramy.github.quiz.records;

import java.util.List;

/**
* @author Luca Mosetti
*/
public record Data(
String question,
List<String> answers,
Character correct
) {
@SuppressWarnings("unused")
public Data() {
this(null, null, null);
}
}
19 changes: 19 additions & 0 deletions src/main/java/me/gekoramy/github/quiz/records/Question.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package me.gekoramy.github.quiz.records;

import java.io.Serializable;
import java.util.List;

/**
* @author Luca Mosetti
*/
public record Question(
String id,
String question,
List<String> answers,
Integer correct
) implements Serializable {
@SuppressWarnings("unused")
public Question() {
this(null, null, null, null);
}
}
6 changes: 3 additions & 3 deletions src/main/java/me/gekoramy/github/quiz/service/Download.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import javafx.concurrent.Service;
import javafx.concurrent.Task;
import javafx.util.Pair;
import me.gekoramy.github.quiz.pojo.Data;
import me.gekoramy.github.quiz.pojo.Question;
import me.gekoramy.github.quiz.records.Data;
import me.gekoramy.github.quiz.records.Question;
import me.gekoramy.github.quiz.util.Pool;
import org.eclipse.egit.github.core.Repository;
import org.eclipse.egit.github.core.RepositoryContents;
Expand Down Expand Up @@ -63,7 +63,7 @@ protected Pair<Repository, Pool<Question>> call() throws Exception {
try {
Data data = mapper.readValue(fetchAndDecode(new ContentsService(client), repo, name), Data.class);
updateProgress(status.incrementAndGet(), max);
return new Question(name, data.getQuestion(), data.getAnswers(), data.getCorrect() - 'A');
return new Question(name, data.question(), data.answers(), data.correct() - 'A');
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import javafx.concurrent.Task;
import javafx.stage.Stage;
import me.gekoramy.github.quiz.app.AppExam;
import me.gekoramy.github.quiz.pojo.Question;
import me.gekoramy.github.quiz.records.Question;
import me.gekoramy.github.quiz.util.Pool;
import org.eclipse.egit.github.core.Repository;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/gekoramy/github/quiz/service/Read.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import javafx.concurrent.Task;
import javafx.util.Pair;
import me.gekoramy.github.quiz.persistance.QuestionsRetrieverOffline;
import me.gekoramy.github.quiz.pojo.Question;
import me.gekoramy.github.quiz.records.Question;
import me.gekoramy.github.quiz.util.Pool;
import org.eclipse.egit.github.core.Repository;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/gekoramy/github/quiz/service/Store.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import javafx.concurrent.Service;
import javafx.concurrent.Task;
import me.gekoramy.github.quiz.persistance.QuestionsRetrieverOffline;
import me.gekoramy.github.quiz.pojo.Question;
import me.gekoramy.github.quiz.records.Question;
import me.gekoramy.github.quiz.util.Pool;
import org.eclipse.egit.github.core.Repository;

Expand Down

0 comments on commit 50b20aa

Please sign in to comment.