1 | if (this.autoSort) {↵ | | 1 | if (this.autoSort) {↵
|
2 | int index = Collections.binarySearch(this.data, item);↵ | | 2 | int index = Collections.binarySearch(this.data, item);↵
|
3 | if (index < 0) {↵ | | 3 | if (index < 0) {↵
|
4 | this.data.add(-index - 1, item);↵ | | 4 | this.data.add(-index - 1, item);↵
|
5 | }↵ | | 5 | }↵
|
6 | else {↵ | | 6 | else {↵
|
7 | if (this.allowDuplicateXValues) {↵ | | 7 | if (this.allowDuplicateXValues) {↵
|
8 | // need to make sure we are adding *after* any duplicates↵ | | 8 | // need to make sure we are adding *after* any duplicates↵
|
9 | int size = this.data.size();↵ | | 9 | int size = this.data.size();↵
|
10 | while (index < size ↵ | | 10 | while (index < size↵
|
11 | && item.compareTo(this.data.get(index)) == 0) {↵ | | 11 | && item.compareTo(this.data.get(index)) == 0) {↵
|
12 | index++;↵ | | 12 | index++;↵
|
13 | }↵ | | 13 | }↵
|
14 | if (index < this.data.size()) {↵ | | 14 | if (index < this.data.size()) {↵
|
15 | this.data.add(index, item);↵ | | 15 | this.data.add(index, item);↵
|
16 | }↵ | | 16 | }↵
|
17 | else {↵ | | 17 | else {↵
|
18 | this.data.add(item);↵ | | 18 | this.data.add(item);↵
|
19 | }↵ | | 19 | }↵
|
20 | }↵ | | 20 | }↵
|
21 | else {↵ | | 21 | else {↵
|
22 | throw new SeriesException("X-value already exists.");↵ | | 22 | throw new SeriesException("X-value already exists.");↵
|
23 | }↵ | | 23 | }↵
|
24 | }↵ | | 24 | }↵
|
25 | }↵ | | 25 | }↵
|
26 | else {↵ | | 26 | else {↵
|
27 | if (!this.allowDuplicateXValues) {↵ | | 27 | if (!this.allowDuplicateXValues) {↵
|
28 | // can't allow duplicate values, so we need to check whether↵ | | 28 | // can't allow duplicate values, so we need to check whether↵
|
29 | // there is an item with the given x-value already↵ | | 29 | // there is an item with the given x-value already↵
|
30 | int index = indexOf(item.getComparable());↵ | | 30 | int index = indexOf(item.getX());↵
|
31 | if (index >= 0) {↵ | | 31 | if (index >= 0) {↵
|
32 | throw new SeriesException("X-value already exists."); ↵ | | 32 | throw new SeriesException("X-value already exists.");↵
|
33 | }↵ | | 33 | }↵
|
34 | }↵ | | 34 | }↵
|
35 | this.data.add(item);↵ | | 35 | this.data.add(item);↵
|
36 | } | | 36 | }
|