|
a/src/net/timbusproject/dpes/alternative/ReasonerClient/common/ResponseData.java |
|
b/src/net/timbusproject/dpes/alternative/ReasonerClient/common/ResponseData.java |
|
... |
|
... |
16 |
* See the License for the specific language governing permissions and limitation under the License.
|
16 |
* See the License for the specific language governing permissions and limitation under the License.
|
17 |
*/
|
17 |
*/
|
18 |
|
18 |
|
19 |
package net.timbusproject.dpes.alternative.ReasonerClient.common;
|
19 |
package net.timbusproject.dpes.alternative.ReasonerClient.common;
|
20 |
|
20 |
|
|
|
21 |
import ch.lambdaj.function.convert.Converter;
|
|
|
22 |
import net.timbusproject.reasoner.Result;
|
|
|
23 |
import net.timbusproject.reasoner.Package;
|
21 |
import org.json.JSONArray;
|
24 |
import org.json.JSONArray;
|
22 |
import org.json.JSONObject;
|
25 |
import org.json.JSONObject;
|
23 |
|
26 |
|
24 |
import java.util.ArrayList;
|
27 |
import java.util.ArrayList;
|
25 |
import java.util.List;
|
28 |
import java.util.List;
|
|
|
29 |
|
|
|
30 |
import static ch.lambdaj.Lambda.convert;
|
26 |
|
31 |
|
27 |
public class ResponseData {
|
32 |
public class ResponseData {
|
28 |
|
33 |
|
29 |
private List<String> packagesToInstall;
|
34 |
private List<String> packagesToInstall;
|
30 |
private List<String> packagesToRemove;
|
35 |
private List<String> packagesToRemove;
|
|
... |
|
... |
38 |
// TODO: check if result actually is an JSONObject
|
43 |
// TODO: check if result actually is an JSONObject
|
39 |
packagesToInstall = toPackageList(data.getJSONObject("result").getJSONArray("installed"));
|
44 |
packagesToInstall = toPackageList(data.getJSONObject("result").getJSONArray("installed"));
|
40 |
packagesToRemove = toPackageList(data.getJSONObject("result").getJSONArray("removed"));
|
45 |
packagesToRemove = toPackageList(data.getJSONObject("result").getJSONArray("removed"));
|
41 |
}
|
46 |
}
|
42 |
|
47 |
|
|
|
48 |
public ResponseData(Result response) {
|
|
|
49 |
packagesToInstall = toStrings(response.getInstalled());
|
|
|
50 |
packagesToRemove = toStrings(response.getRemoved());
|
|
|
51 |
}
|
|
|
52 |
|
43 |
private List<String> toPackageList(JSONArray jsonArray) {
|
53 |
private List<String> toPackageList(JSONArray jsonArray) {
|
44 |
List<String> packages = new ArrayList<>();
|
54 |
List<String> packages = new ArrayList<>();
|
45 |
for (int i = 0; i < jsonArray.length(); ++i) {
|
55 |
for (int i = 0; i < jsonArray.length(); ++i) {
|
46 |
packages.add(jsonArray.getJSONObject(i).getString("name"));
|
56 |
packages.add(jsonArray.getJSONObject(i).getString("name"));
|
47 |
}
|
57 |
}
|
|
... |
|
... |
53 |
}
|
63 |
}
|
54 |
|
64 |
|
55 |
public List<String> getPackagesToRemove() {
|
65 |
public List<String> getPackagesToRemove() {
|
56 |
return packagesToRemove;
|
66 |
return packagesToRemove;
|
57 |
}
|
67 |
}
|
|
|
68 |
|
|
|
69 |
private List<String> toStrings(List<Package> packageList) {
|
|
|
70 |
return convert(packageList, new Converter<Package, String>() {
|
|
|
71 |
@Override
|
|
|
72 |
public String convert(Package aPackage) {
|
|
|
73 |
return aPackage.getName();
|
|
|
74 |
}
|
|
|
75 |
});
|
|
|
76 |
}
|
58 |
}
|
77 |
}
|