-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathPrinter.java
159 lines (142 loc) · 4.09 KB
/
Printer.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package com.printnode.api;
import com.google.gson.JsonObject;
import java.io.Serializable;
/**
* Object for a printer.
* */
public class Printer implements Serializable {
/**
* The response body that made this Printer.
* */
private String json;
/**
* The id of the printer.
* */
private int id;
/**
* The computer that relates to this printer.
* */
private Computer computer;
/**
* The name of the printer.
* */
private String name;
/**
* The description of the printer.
* */
private String description;
/**
* The capabilities of this printer.
* */
private Capabilities capabilities;
/**
* The default settings of this printer.
* */
private String defaults;
/**
* The date this printer was added to PrintNode.
* */
private String createTimestamp;
/**
* The current state of the printer.
* */
private String state;
/**
* Parses a JsonObject into Printer.
* Firstly, it begins iterating over the object.
* If the object we are converting is a solo JsonPrimitive, we map it directly to the variable.
* If the object we are converting is an array of JsonPrimitives,
* we firstly create an array of the same size as it.
* Then, iterate over it.
* If the object is a JsonObject with the same mappings each time, it is mapped to a HashMap.
* If the object is a JsonObject with different mappings, it is mapped to a Java Object.
* @param response JsonObject of the response.
* @see JsonObject
* @see com.google.gson.JsonArray
* @see com.google.gson.JsonPrimitive
* @see com.google.gson.JsonElement
* */
public Printer(final JsonObject response) {
if (!response.get("id").isJsonNull()) {
id = response.get("id").getAsInt();
}
if (!response.get("computer").isJsonNull()) {
computer = new Computer(response.get("computer").getAsJsonObject());
}
if (!response.get("description").isJsonNull()) {
description = response.get("description").getAsString();
}
if (!response.get("name").isJsonNull()) {
name = response.get("name").getAsString();
}
if (!response.get("capabilities").isJsonNull()) {
capabilities = new Capabilities(response.get("capabilities").getAsJsonObject());
}
if (!response.get("default").isJsonNull()) {
defaults = response.get("default").getAsString();
}
if (!response.get("createTimestamp").isJsonNull()) {
createTimestamp = response.get("createTimestamp").getAsString();
}
if (!response.get("state").isJsonNull()) {
state = response.get("state").getAsString();
}
json = response.toString();
}
/**
* @return the id of the printer.
* */
public final int getId() {
return id;
}
/**
* @return the name of the printer.
* */
public final String getName() {
return name;
}
/**
* @return the computer attached to this printer.
* @see Computer
* */
public final Computer getComputer() {
return computer;
}
/**
* @return the description of the printer.
* */
public final String getDescription() {
return description;
}
/**
* @return the capabilities object of the printer.
* @see Capabilities
* */
public final Capabilities getCapabilities() {
return capabilities;
}
/**
* @return default settings for this printer.
* */
public final String getDefault() {
return defaults;
}
/**
* @return timestamp of when the printer was added to the account.
* */
public final String getCreateTimestamp() {
return createTimestamp;
}
/**
* @return current state of the printer.
* */
public final String getState() {
return state;
}
/**
* @return the original response string.
* */
public final String toString() {
return json;
}
}