-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMain.java
More file actions
57 lines (50 loc) · 1.48 KB
/
Main.java
File metadata and controls
57 lines (50 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import com.google.gson.*;
import imo.repl.models.*;
import java.nio.file.*;
import java.io.*;
class Main {
public static void main(String[] args) {
try {
var gson = getGson();
var books = FetchAllBooks();
var output = gson.toJson(books);
System.out.println(output);
} catch(Exception ex) {
System.out.println(ex.toString());
}
}
static Gson getGson() {
var builder = new GsonBuilder();
builder = builder.setPrettyPrinting();
return builder.create();
}
static Book[] FetchAllBooks() throws IOException {
var filepath = Paths.get("samples/data.json");
var text = Files.readString(filepath);
var gson = getGson();
Book[] books = gson.fromJson(text, Book[].class);
return books;
}
/// Feature-Request: Clients want to be able to
/// display the names of the Authors we support.
///
static String[] GetAuthors() {
return new String[0];
}
/// Feature-Request: Our support teams want to be able to
/// add new books we support to our data store.
///
static void AddBook(/* Intentionally Blank */) {
return;
}
/// Feature-Request: Clients want to be able to search for books
/// by a certain author.
static Book[] GetBooksByAuthorName(/* Intentionally Blank */) {
return new Book[0];
}
/// Feature-Request: Clients want to be able to search for books
/// within a given genre
static Book[] GetBooksByGenre(/* Intentionally Blank */) {
return new Book[0];
}
}