This repository has been archived by the owner on Dec 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDocuments.java
85 lines (63 loc) · 2.43 KB
/
Documents.java
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package com.github.derrop.documents;
import com.github.derrop.documents.storage.DocumentStorage;
import com.github.derrop.documents.storage.JsonDocumentStorage;
import com.github.derrop.documents.storage.YamlDocumentStorage;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
public class Documents {
private static final DocumentStorage JSON = new JsonDocumentStorage();
private static final DocumentStorage YAML = new YamlDocumentStorage();
public static Document newDocument() {
return new DefaultDocument();
}
public static Document newDocument(JsonElement jsonElement) {
return new DefaultDocument(jsonElement);
}
public static Document newDocument(JsonObject jsonObject) {
return new DefaultDocument(jsonObject);
}
public static Document newDocument(String key, String value) {
return new DefaultDocument(key, value);
}
public static Document newDocument(String key, Number value) {
return new DefaultDocument(key, value);
}
public static Document newDocument(String key, Character value) {
return new DefaultDocument(key, value);
}
public static Document newDocument(String key, Boolean value) {
return new DefaultDocument(key, value);
}
public static Document newDocument(String key, Object value) {
return new DefaultDocument(key, value);
}
public static Document newDocument(Object object) {
return new DefaultDocument(DefaultDocument.GSON.toJsonTree(object));
}
public static Document newJsonDocument(byte[] bytes) {
return newJsonDocument(new String(bytes, StandardCharsets.UTF_8));
}
public static Document newYamlDocument(byte[] bytes) {
return newYamlDocument(new String(bytes, StandardCharsets.UTF_8));
}
public static Document newJsonDocument(Path path) {
return jsonStorage().read(path);
}
public static Document newYamlDocument(Path path) {
return yamlStorage().read(path);
}
public static Document newJsonDocument(String input) {
return jsonStorage().read(input);
}
public static Document newYamlDocument(String input) {
return yamlStorage().read(input);
}
public static DocumentStorage jsonStorage() {
return JSON;
}
public static DocumentStorage yamlStorage() {
return YAML;
}
}