File path: /jfreechart-1.0.10/src/org/jfree/chart/renderer/RendererUtilities.java | File path: /jfreechart-1.0.10/src/org/jfree/chart/renderer/RendererUtilities.java | |||
Method name: int findLiveItemsLowerBound(XYDataset, int, double, double)
|
Method name: int findLiveItemsUpperBound(XYDataset, int, double, double)
|
|||
Number of AST nodes: 41 | Number of AST nodes: 41 | |||
1 | int itemCount = dataset.getItemCount(series);↵ | 1 | int itemCount = dataset.getItemCount(series);↵ | |
2 | if (itemCount <= 1) {↵ | 2 | if (itemCount <= 1) {↵ | |
3 | return 0;↵ | 3 | return 0;↵ | |
4 | }↵ | 4 | }↵ | |
5 | if (dataset.getDomainOrder() == DomainOrder.ASCENDING) {↵ | 5 | if (dataset.getDomainOrder() == DomainOrder.ASCENDING) {↵ | |
6 | // for data in ascending order by x-value, we are (broadly) looking↵ | |||
7 | // for the index of the highest x-value that is less that xLow↵ | |||
8 | int low = 0;↵ | 6 | int low = 0;↵ | |
9 | int high = itemCount - 1;↵ | 7 | int high = itemCount - 1;↵ | |
10 | int mid = (low + high) / 2;↵ | 8 | int mid = (low + high + 1) / 2;↵ | |
11 | double lowValue = dataset.getXValue(series, low);↵ | 9 | double lowValue = dataset.getXValue(series, low);↵ | |
12 | if (lowValue >= xLow) {↵ | 10 | if (lowValue > xHigh) {↵ | |
13 | // special case where the lowest x-value is >= xLow↵ | |||
14 | return low;↵ | 11 | return low;↵ | |
15 | }↵ | 12 | }↵ | |
16 | double highValue = dataset.getXValue(series, high);↵ | 13 | double highValue = dataset.getXValue(series, high);↵ | |
17 | if (highValue < xLow) {↵ | 14 | if (highValue <= x↵ | |
18 | // special case where the highest x-value is < xLow↵ | 15 | High) {↵ | |
19 | return high;↵ | 16 | return high;↵ | |
20 | }↵ | 17 | }↵ | |
21 | while (high - low > 1) {↵ | 18 | while (high - low > 1) {↵ | |
22 | double midV = dataset.getXValue(series, mid);↵ | 19 | double midV = dataset.getXValue(series, mid);↵ | |
23 | if (midV >= xLow) {↵ | 20 | if (midV <= xHigh) {↵ | |
24 | high = mid;↵ | 21 | low = mid;↵ | |
25 | }↵ | 22 | }↵ | |
26 | else {↵ | 23 | else {↵ | |
27 | low = mid;↵ | 24 | high = mid;↵ | |
28 | }↵ | 25 | }↵ | |
29 | mid = (low + high) / 2;↵ | 26 | mid = (low + high + 1) / 2;↵ | |
30 | }↵ | 27 | }↵ | |
31 | return mid;↵ | 28 | return mid;↵ | |
32 | }↵ | 29 | }↵ | |
33 | else if (dataset.getDomainOrder() == DomainOrder.DESCENDING) {↵ | 30 | else if (dataset.getDomainOrder() == DomainOrder.DESCENDING) {↵ | |
34 | // when the x-values are sorted in descending order, the lower↵ | 31 | // when the x-values are descending↵ | |
35 | // bound is found by calculating relative to the xHigh value↵ | 32 | , the upper bound is found by↵ | |
33 | // comparing against xLow↵ | |||
36 | int low = 0;↵ | 34 | int low = 0;↵ | |
37 | int high = itemCount - 1;↵ | 35 | int high = itemCount - 1;↵ | |
38 | int mid = (low + high) / 2;↵ | 36 | int mid = (low + high) / 2;↵ | |
39 | double lowValue = dataset.getXValue(series, low);↵ | 37 | double lowValue = dataset.getXValue(series, low);↵ | |
40 | if (lowValue <= xHigh) {↵ | 38 | if (lowValue < xLow) {↵ | |
41 | return low;↵ | 39 | return low;↵ | |
42 | }↵ | 40 | }↵ | |
43 | double highValue = dataset.getXValue(series, high);↵ | 41 | double highValue = dataset.getXValue(series, high);↵ | |
44 | if (highValue > xHigh) {↵ | 42 | if (highValue >= xLow) {↵ | |
45 | return high;↵ | 43 | return high;↵ | |
46 | }↵ | 44 | }↵ | |
47 | while (high - low > 1) {↵ | 45 | while (high - low > 1) {↵ | |
48 | double midV = dataset.getXValue(series, mid);↵ | 46 | double midV = dataset.getXValue(series, mid);↵ | |
49 | if (midV > xHigh) {↵ | 47 | if (midV >= xLow) {↵ | |
50 | low = mid;↵ | 48 | low = mid;↵ | |
51 | }↵ | 49 | }↵ | |
52 | else {↵ | 50 | else {↵ | |
53 | high = mid;↵ | 51 | high = mid;↵ | |
54 | }↵ | 52 | }↵ | |
55 | mid = (low + high) / 2;↵ | 53 | mid = (low + high) / 2;↵ | |
56 | }↵ | 54 | }↵ | |
57 | return mid;↵ | 55 | return mid;↵ | |
58 | }↵ | 56 | }↵ | |
59 | else {↵ | 57 | else {↵ | |
60 | // we don't know anything about the ordering of the x-values,↵ | 58 | // we don't know anything about the ordering of the x-values,↵ | |
61 | // but we can still skip any initial values that fall outside the↵ | 59 | // but we can still skip any trailing values that fall outside the↵ | |
62 | // range...↵ | 60 | // range...↵ | |
63 | int index = 0;↵ | 61 | int index = itemCount - 1;↵ | |
64 | // skip any items that don't need including...↵ | 62 | // skip any items that don't need including...↵ | |
65 | while (index < itemCount && dataset.getXValue(series, index) ↵ | 63 | while (index >= 0 && dataset.getXValue(series, index) ↵ | |
66 | < xLow) {↵ | 64 | > xHigh) {↵ | |
67 | index++;↵ | 65 | index--;↵ | |
68 | }↵ | 66 | }↵ | |
69 | return Math.max(0, index - 1);↵ | 67 | return Math.min(itemCount - 1, index + 1);↵ | |
70 | } | 68 |
| |
See real code fragment | See real code fragment |
Number of common nesting structure subtrees | 1 |
Number of refactorable cases | 0 |
Number of non-refactorable cases | 1 |
Time elapsed for finding largest common nesting structure subtrees (ms) | 3.9 |
Clones location | Clones are declared in the same class |
Number of node comparisons | 227 |
Number of mapped statements | 37 |
Number of unmapped statements in the first code fragment | 4 |
Number of unmapped statements in the second code fragment | 4 |
Time elapsed for statement mapping (ms) | 22.0 |
Clone type | Type 3 |
ID | Statement | ID | Statement | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | int itemCount = dataset.getItemCount(series); | 1 | int itemCount = dataset.getItemCount(series); | |||||||||||||
2 | if (itemCount <= 1) | 2 | if (itemCount <= 1) | |||||||||||||
3 | return 0; | 3 | return 0; | |||||||||||||
4 | if (dataset.getDomainOrder() == DomainOrder.ASCENDING) |
| 21 | if (dataset.getDomainOrder() == DomainOrder.DESCENDING) | ||||||||||||
5 | int low = 0; | 22 | int low = 0; | |||||||||||||
6 | int high = itemCount - 1; | 23 | int high = itemCount - 1; | |||||||||||||
7 | int mid = (low + high) / 2; | 24 | int mid = (low + high) / 2; | |||||||||||||
8 | double lowValue = dataset.getXValue(series, low); | 25 | double lowValue = dataset.getXValue(series, low); | |||||||||||||
9 | if (lowValue >= xLow) |
| 26 | if (lowValue < xLow) | ||||||||||||
10 | return low; | 27 | return low; | |||||||||||||
11 | double highValue = dataset.getXValue(series, high); | 28 | double highValue = dataset.getXValue(series, high); | |||||||||||||
12 | if (highValue < xLow) |
| 29 | if (highValue >= xLow) | ||||||||||||
13 | return high; | 30 | return high; | |||||||||||||
14 | while (high - low > 1) | 31 | while (high - low > 1) | |||||||||||||
15 | double midV = dataset.getXValue(series, mid); | 32 | double midV = dataset.getXValue(series, mid); | |||||||||||||
16 | if (midV >= xLow) | 33 | if (midV >= xLow) | |||||||||||||
17 | high = mid; |
| 34 | low = mid; | ||||||||||||
else | else | |||||||||||||||
18 | low = mid; |
| 35 | high = mid; | ||||||||||||
19 | mid = (low + high) / 2; | 36 | mid = (low + high) / 2; | |||||||||||||
20 | return mid; | 37 | return mid; | |||||||||||||
21 | else if (dataset.getDomainOrder() == DomainOrder.DESCENDING) |
| 4 | else if (dataset.getDomainOrder() == DomainOrder.ASCENDING) | ||||||||||||
22 | int low = 0; | 5 | int low = 0; | |||||||||||||
23 | int high = itemCount - 1; | 6 | int high = itemCount - 1; | |||||||||||||
24 | int mid = (low + high) / 2; |
| 7 | int mid = (low + high + 1) / 2; | ||||||||||||
25 | double lowValue = dataset.getXValue(series, low); | 8 | double lowValue = dataset.getXValue(series, low); | |||||||||||||
26 | if (lowValue <= xHigh) |
| 9 | if (lowValue > xHigh) | ||||||||||||
27 | return low; | 10 | return low; | |||||||||||||
28 | double highValue = dataset.getXValue(series, high); | 11 | double highValue = dataset.getXValue(series, high); | |||||||||||||
29 | if (highValue > xHigh) |
| 12 | if (highValue <= xHigh) | ||||||||||||
30 | return high; | 13 | return high; | |||||||||||||
31 | while (high - low > 1) | 14 | while (high - low > 1) | |||||||||||||
32 | double midV = dataset.getXValue(series, mid); | 15 | double midV = dataset.getXValue(series, mid); | |||||||||||||
33 | if (midV > xHigh) |
| 16 | if (midV <= xHigh) | ||||||||||||
34 | low = mid; | 17 | low = mid; | |||||||||||||
else | else | |||||||||||||||
35 | high = mid; | 18 | high = mid; | |||||||||||||
36 | mid = (low + high) / 2; |
| 19 | mid = (low + high + 1) / 2; | ||||||||||||
37 | return mid; | 20 | return mid; | |||||||||||||
else | | |||||||||||||||
|
| 38 | int index = itemCount - 1; | |||||||||||||
38 | int index = 0; | | ||||||||||||||
|
| 39 | while (index >= 0 && dataset.getXValue(series, index) > xHigh) | |||||||||||||
| 40 | index--; | ||||||||||||||
39 | while (index < itemCount && dataset.getXValue(series, index) < xLow) |
| | |||||||||||||
40 | index++; | | ||||||||||||||
|
| 41 | return Math.min(itemCount - 1, index + 1); | |||||||||||||
41 | return Math.max(0, index - 1); |
| |
Row | Violation |
---|---|
1 | Expression lowValue >= xLow cannot be parameterized, because it has dependencies to/from statements that will be extracted |
2 | Expression lowValue < xLow cannot be parameterized, because it has dependencies to/from statements that will be extracted |
3 | Expression highValue < xLow cannot be parameterized, because it has dependencies to/from statements that will be extracted |
4 | Expression highValue >= xLow cannot be parameterized, because it has dependencies to/from statements that will be extracted |
5 | Expression high cannot be parameterized, because it has dependencies to/from statements that will be extracted |
6 | Expression low cannot be parameterized, because it has dependencies to/from statements that will be extracted |
7 | Expression low cannot be parameterized, because it has dependencies to/from statements that will be extracted |
8 | Expression high cannot be parameterized, because it has dependencies to/from statements that will be extracted |
9 | Expression low + high cannot be parameterized, because it has dependencies to/from statements that will be extracted |
10 | Expression low + high + 1 cannot be parameterized, because it has dependencies to/from statements that will be extracted |
11 | Expression lowValue <= xHigh cannot be parameterized, because it has dependencies to/from statements that will be extracted |
12 | Expression lowValue > xHigh cannot be parameterized, because it has dependencies to/from statements that will be extracted |
13 | Expression highValue > xHigh cannot be parameterized, because it has dependencies to/from statements that will be extracted |
14 | Expression highValue <= xHigh cannot be parameterized, because it has dependencies to/from statements that will be extracted |
15 | Expression midV > xHigh cannot be parameterized, because it has dependencies to/from statements that will be extracted |
16 | Expression midV <= xHigh cannot be parameterized, because it has dependencies to/from statements that will be extracted |
17 | Expression low + high cannot be parameterized, because it has dependencies to/from statements that will be extracted |
18 | Expression low + high + 1 cannot be parameterized, because it has dependencies to/from statements that will be extracted |
19 | Unmatched statement int index=itemCount - 1; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
20 | Unmatched statement while(index >= 0 && dataset.getXValue(series,index) > xHigh) cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted |
21 | Unmatched statement while(index >= 0 && dataset.getXValue(series,index) > xHigh) cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted |
22 | Unmatched statement while(index < itemCount && dataset.getXValue(series,index) < xLow) cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
23 | Unmatched statement while(index < itemCount && dataset.getXValue(series,index) < xLow) cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted |
24 | Unmatched statement return Math.min(itemCount - 1,index + 1); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
25 | Unmatched return Math.min(itemCount - 1,index + 1); |
26 | Unmatched return Math.max(0,index - 1); |
27 | Not all possible execution flows end in a return statement |