Skip to content

Commit

Permalink
[#2265][#2267]Fix outdated suggested solution for backend Task 1 (#2268)
Browse files Browse the repository at this point in the history
* Update suggested solution for backend task 1 hint 3

* Remove error

* Update suggested solution for backend task 1 hint 2

---------

Co-authored-by: Ryan Poon <96387349+sopa301@users.noreply.github.com>
  • Loading branch information
lyuanww and sopa301 authored Feb 1, 2025
1 parent 1f5e022 commit 4abd7f4
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions docs/dg/learningBasics.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,31 +98,35 @@ Here are some small tasks for you to gain some basic knowledge of the code relat

<panel header="Hint 2">

After the step in hint 1, the argument is captured by `ArgumentParser`. Now make corresponding changes to `CliArguments.java`, `ConfigCliArguments.java`, and the `parse` method in `ArgsParser.java` to make the return result of `parse` include the new argument.
After the step in hint 1, the argument is captured by `ArgumentParser`. Now make corresponding changes to `CliArguments.java` and the `parse` method in `ArgsParser.java` to make the return result of `parse` include the new argument.

1. Add the following content to `CliArguments` to include `isPrettyPrintingUsed` as a new attribute to the class.

```java
protected boolean isPrettyPrintingUsed;
private boolean isPrettyPrintingUsed;

public boolean isPrettyPrintingUsed() {
return isPrettyPrintingUsed;
}
```

2. In the constructor of `ConfigCliArguments`, add `isPrettyPrintingUsed` as a new parameter of the method, and add the following instruction to the method body.

2. In the `Builder` class within `CliArguments`, add the following method to set `isPrettyPrintingUsed`.
```java
this.isPrettyPrintingUsed = isPrettyPrintingUsed;
public Builder isPrettyPrintingUsed(boolean isPrettyPrintingUsed) {
this.cliArguments.isPrettyPrintingUsed = isPrettyPrintingUsed;
return this;
}
```

3. In the `parse` method of `ArgsParser`, add the following instruction to get `isJsonPrettyPrintingUsed` from `ArgmentParser`.
3. In the `parse` method of `ArgsParser`, add the following instruction to get `isJsonPrettyPrintingUsed` from `ArgumentParser`.

```java
boolean isJsonPrettyPrintingUsed = results.get(JSON_PRINT_MODE_FLAGS[0]);
```

4. Additionally, change the return statement of the `parse` method so that the `ConfigCliArguments` object returned will now include `isJsonPrettyPrintingUsed`.
4. Additionally, add `.isPrettyPrintingUsed(isJsonPrettyPrintingUsed)` to the initialisation of `cliArgumentsBuilder` in the `parse` method of `ArgsParser`.

</panel>

<panel header="Hint 3">
Expand All @@ -149,7 +153,9 @@ Here are some small tasks for you to gain some basic knowledge of the code relat
GsonBuilder gsonBuilder = new GsonBuilder()
.registerTypeAdapter(LocalDateTime.class, (JsonSerializer<LocalDateTime>) (date, typeOfSrc, context)
-> new JsonPrimitive(date.format(DateTimeFormatter.ofPattern(GITHUB_API_DATE_FORMAT))))
.registerTypeAdapter(FileType.class, new FileType.FileTypeSerializer());
.registerTypeAdapter(FileType.class, new FileType.FileTypeSerializer())
.registerTypeAdapter(ZoneId.class, (JsonSerializer<ZoneId>) (zoneId, typeOfSrc, context)
-> new JsonPrimitive(zoneId.toString()));
Gson gson;
if (isPrettyPrintingUsed) {
gson = gsonBuilder.setPrettyPrinting().create();
Expand Down

0 comments on commit 4abd7f4

Please sign in to comment.