Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
*
* objectMapper.readValue(jsonString, CJTSD.class).toList()
*
* @see https://github.com/james-hu/cjtsd-js/wiki/Compact-JSON-Time-Series-Data
* @author James Hu (Zhengmao Hu)
*
*/
@com.fasterxml.jackson.annotation.JsonIgnoreProperties(ignoreUnknown = true)
@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)
public class CJTSD extends PlainCJTSD{
public CJTSD(){
super();
}
/**
* Shallow copy constructor
* @param other another instance from which the properties will be copied
*/
public CJTSD(PlainCJTSD other){
super(other);
}
/**
* Convert into list form
* @return the list containing entries of data points
*/
public List toList(){
if (t == null || t.size() == 0){
return Collections.emptyList();
}
List result = new ArrayList<>(t.size());
int lastDuration = 0;
for (int i = 0; i < t.size(); i ++){
long timestamp = t.get(i);
int duration = -1;
if (i < d.size()){
duration = d.get(i);
}
if (duration == -1){
duration = lastDuration;
}
lastDuration = duration;
LocalDateTime timestampObj;
Duration durationObj;
if (u == null || u.equals("m")){
timestampObj = LocalDateTime.ofEpochSecond(timestamp * 60, 0, ZoneOffset.UTC);
durationObj = Duration.ofMinutes(duration);
}else if (u.equals("s")){
timestampObj = LocalDateTime.ofEpochSecond(timestamp, 0, ZoneOffset.UTC);
durationObj = Duration.ofSeconds(duration);
}else if (u.equals("S")){
long seconds = timestamp / 1000;
int nano = (int)(timestamp % 1000) * 1_000_000;
timestampObj = LocalDateTime.ofEpochSecond(seconds, nano, ZoneOffset.UTC);
durationObj = Duration.ofMillis(duration);
}else{
throw new IllegalArgumentException("Unit not supported: " + u);
}
result.add(new Entry(timestampObj, durationObj,
c == null || i >= c.size() ? null : c.get(i),
s == null || i >= s.size() ? null : s.get(i),
a == null || i >= a.size() ? null : a.get(i),
m == null || i >= m.size() ? null : m.get(i),
x == null || i >= x.size() ? null : x.get(i),
n == null || i >= n.size() ? null : n.get(i),
o == null || i >= o.size() ? null : o.get(i)
));
}
return result;
}
/**
* Create a builder for generating CJTSD object.
* The expected number of data points is 50.
* If the actual number of data points exceeds the expected, the builder will just grow.
* @return the builder
*/
static public Builder builder(){
return new Builder();
}
/**
* Create a builder for generating CJTSD object.
* The expected number of data points is specified as argument to this method.
* If the actual number of data points exceeds the expected, the builder will just grow.
* @param expectedSize the expected number of data points
* @return the builder
*/
static public Builder builder(int expectedSize){
return new Builder(expectedSize);
}
/**
* Builder that keeps intermediate data structure for creating
* CJTSD object.
* @author James Hu (Zhengmao Hu)
*
*/
static public class Builder{
private int expectedSize;
private ChronoUnit unit = ChronoUnit.MINUTES;
private LongList timestamps;
private IntList durations;
private List counts;
private List sums;
private List avgs;
private List mins;
private List maxs;
private List numbers;
private List