forked from matomo-org/matomo-java-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPiwikJsonArray.java
More file actions
69 lines (61 loc) · 1.84 KB
/
PiwikJsonArray.java
File metadata and controls
69 lines (61 loc) · 1.84 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
58
59
60
61
62
63
64
65
66
67
68
69
/*
* Piwik Java Tracker
*
* @link https://github.com/piwik/piwik-java-tracker
* @license https://github.com/piwik/piwik-java-tracker/blob/master/LICENSE BSD-3 Clause
*/
package org.piwik.java.tracking;
import java.util.ArrayList;
import java.util.List;
import javax.json.Json;
import javax.json.JsonArrayBuilder;
import javax.json.JsonValue;
/**
* Object representing a JSON array required by some Piwik query parameters.
*
* @author brettcsorba
*/
public class PiwikJsonArray{
List<JsonValue> list = new ArrayList<>();
/**
* Get the value stored at the specified index.
* @param index the index of the value to return
* @return the value stored at the specified index
*/
public JsonValue get(int index){
return list.get(index);
}
/**
* Add a value to the end of this array.
* @param value value to add to the end of the array
*/
public void add(JsonValue value){
list.add(value);
}
/**
* Set the value at the specified index to the specified value.
* @param index the index of the value to set
* @param value the value to set at the specified index
*/
public void set(int index, JsonValue value){
list.set(index, value);
}
/**
* Returns a JSON encoded array string representing this object.
* @return returns the current array as a JSON encode string
*/
@Override
public String toString(){
JsonArrayBuilder ab = Json.createArrayBuilder();
for (int x = 0; x < list.size(); ++x){
JsonValue value = list.get(x);
if (value instanceof EcommerceItem){
ab.add(((EcommerceItem)value).toJsonArray());
}
else{
ab.add(value);
}
}
return ab.build().toString();
}
}