OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 19 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
13 ilm 1
package org.jopenchart;
2
 
3
import java.util.ArrayList;
4
import java.util.List;
5
 
6
public class DataModel1D extends DataModel {
156 ilm 7
    private final List<Number> l = new ArrayList<>();
13 ilm 8
 
9
    public DataModel1D() {
10
 
11
    }
12
 
13
    public DataModel1D(Number[] data) {
14
        for (int i = 0; i < data.length; i++) {
156 ilm 15
            l.add(data[i]);
13 ilm 16
        }
17
    }
18
 
19
    public DataModel1D(List<Number> list) {
20
        this.addAll(list);
21
    }
22
 
156 ilm 23
    public synchronized void addAll(List<Number> data) {
13 ilm 24
        l.addAll(data);
25
    }
26
 
156 ilm 27
    public synchronized int getSize() {
13 ilm 28
        return l.size();
29
    }
30
 
156 ilm 31
    public synchronized void setValueAt(int index, Number value) {
13 ilm 32
        ensureCapacity(index);
33
        l.set(index, value);
34
    }
35
 
36
    private void ensureCapacity(int index) {
37
        for (int i = l.size(); i <= index; i++) {
38
            l.add(null);
39
        }
40
    }
41
 
156 ilm 42
    public synchronized Number getValueAt(int index) {
13 ilm 43
        ensureCapacity(index);
44
        return l.get(index);
45
    }
46
 
156 ilm 47
    public synchronized Number getMaxValue() {
13 ilm 48
        Number max = 0;
49
        for (Number b : this.l) {
156 ilm 50
            if (b != null && b.doubleValue() > max.doubleValue()) {
13 ilm 51
                max = b;
52
            }
53
        }
54
        return max;
55
    }
56
 
156 ilm 57
    public synchronized Number getMinValue() {
13 ilm 58
        Number min = 0;
59
        for (Number b : this.l) {
156 ilm 60
            if (b != null && b.doubleValue() < min.doubleValue()) {
13 ilm 61
                min = b;
62
            }
63
        }
64
        return min;
65
    }
66
 
156 ilm 67
    public synchronized void clear() {
68
        final int size = l.size();
69
        for (int i = 0; i < size; i++) {
13 ilm 70
            this.setValueAt(i, null);
71
        }
72
    }
73
}