-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathComputer.java
171 lines (153 loc) · 4.25 KB
/
Computer.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
160
161
162
163
164
165
166
167
168
169
170
171
package com.printnode.api;
import com.google.gson.JsonObject;
import java.io.Serializable;
/**
* Object for a computer.
* */
public class Computer implements Serializable {
/**
* The respose body that made this computer.
* */
private String json;
/**
* The id of the computer.
* */
private int id;
/**
* The name of the computer.
* */
private String name = null;
/**
* The inet of the computer.
* */
private String inet = null;
/**
* The inet6 of the computer.
* */
private String inet6 = null;
/**
* The hostname of the computer.
* */
private String hostname = null;
/**
* the version of the client this computer is running.
* */
private String version = null;
/**
* The version of JRE this computer is running.
* */
private String jre = null;
/**
* The date this computer was added to PrintNode.
* */
private String createTimestamp = null;
/**
* The current state of the computer.
* */
private String state = null;
/**
* Parses a JsonObject into Computer.
* 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 Computer(final JsonObject response) {
if (!response.get("id").isJsonNull()) {
id = response.get("id").getAsInt();
}
if (!response.get("name").isJsonNull()) {
name = response.get("name").getAsString();
}
if (!(response.get("inet").isJsonNull())) {
inet = response.get("inet").getAsString();
}
if (!response.get("inet6").isJsonNull()) {
inet6 = response.get("inet6").getAsString();
}
if (!response.get("hostname").isJsonNull()) {
hostname = response.get("hostname").getAsString();
}
if (!response.get("version").isJsonNull()) {
version = response.get("version").getAsString();
}
if (!response.get("jre").isJsonNull()) {
jre = response.get("jre").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 id of the computer.
* */
public final int getId() {
return id;
}
/**
* @return name of the computer.
* */
public final String getName() {
return name;
}
/**
* @return Inet of the computer.
* */
public final String getInet() {
return inet;
}
/**
* @return Inet6 of the computer.
* */
public final String getInet6() {
return inet6;
}
/**
* @return the hostname of the computer.
* */
public final String getHostname() {
return hostname;
}
/**
* @return the client version the computer is running.
* */
public final String getVersion() {
return version;
}
/**
* @return the JRE of the computer.
* */
public final String getJre() {
return jre;
}
/**
* @return the timestamp of when the computer was added to the account.
* */
public final String getCreateTimestamp() {
return createTimestamp;
}
/**
* @return The state of the computer.
* */
public final String getState() {
return state;
}
/**
* @return The original response string.
* */
public final String toString() {
return json;
}
}