List ticks = new java.util.ArrayList(); Font tickLabelFont = getTickLabelFont(); g2.setFont(tickLabelFont); double size = getTickUnit().getSize(); int count = calculateVisibleTickCount(); double lowestTickValue = calculateLowestVisibleTickValue(); double previousDrawnTickLabelPos = 0.0; double previousDrawnTickLabelLength = 0.0; if (count <= ValueAxis.MAXIMUM_TICK_COUNT) { for (int i = 0; i < count; i++) { double currentTickValue = lowestTickValue + (i * size); double xx = valueToJava2D(currentTickValue, dataArea, edge); String tickLabel; NumberFormat formatter = getNumberFormatOverride(); if (formatter != null) { tickLabel = formatter.format(currentTickValue); } else { tickLabel = valueToString(currentTickValue); } // avoid to draw overlapping tick labels Rectangle2D bounds = TextUtilities.getTextBounds(tickLabel, g2, g2.getFontMetrics()); double tickLabelLength = isVerticalTickLabels() ? bounds.getHeight() : bounds.getWidth(); boolean tickLabelsOverlapping = false; if (i > 0) { double avgTickLabelLength = (previousDrawnTickLabelLength + tickLabelLength) / 2.0; if (Math.abs(xx - previousDrawnTickLabelPos) < avgTickLabelLength) { tickLabelsOverlapping = true; } } if (tickLabelsOverlapping) { tickLabel = ""; // don't draw this tick label } else { // remember these values for next comparison previousDrawnTickLabelPos = xx; previousDrawnTickLabelLength = tickLabelLength; } TextAnchor anchor = null; TextAnchor rotationAnchor = null; double angle = 0.0; if (isVerticalTickLabels()) { anchor = TextAnchor.CENTER_RIGHT; rotationAnchor = TextAnchor.CENTER_RIGHT; if (edge == RectangleEdge.TOP) { angle = Math.PI / 2.0; } else { angle = -Math.PI / 2.0; } } else { if (edge == RectangleEdge.TOP) { anchor = TextAnchor.BOTTOM_CENTER; rotationAnchor = TextAnchor.BOTTOM_CENTER; } else { anchor = TextAnchor.TOP_CENTER; rotationAnchor = TextAnchor.TOP_CENTER; } } Tick tick = new NumberTick(new Double(currentTickValue), tickLabel, anchor, rotationAnchor, angle); ticks.add(tick); } } return ticks;
List ticks = new java.util.ArrayList(); Font tickLabelFont = getTickLabelFont(); g2.setFont(tickLabelFont); double size = getTickUnit().getSize(); int count = calculateVisibleTickCount(); double lowestTickValue = calculateLowestVisibleTickValue(); double previousDrawnTickLabelPos = 0.0; double previousDrawnTickLabelLength = 0.0; if (count <= ValueAxis.MAXIMUM_TICK_COUNT) { for (int i = 0; i < count; i++) { double currentTickValue = lowestTickValue + (i * size); double yy = valueToJava2D(currentTickValue, dataArea, edge); String tickLabel; NumberFormat formatter = getNumberFormatOverride(); if (formatter != null) { tickLabel = formatter.format(currentTickValue); } else { tickLabel = valueToString(currentTickValue); } // avoid to draw overlapping tick labels Rectangle2D bounds = TextUtilities.getTextBounds(tickLabel, g2, g2.getFontMetrics()); double tickLabelLength = isVerticalTickLabels() ? bounds.getWidth() : bounds.getHeight(); boolean tickLabelsOverlapping = false; if (i > 0) { double avgTickLabelLength = (previousDrawnTickLabelLength + tickLabelLength) / 2.0; if (Math.abs(yy - previousDrawnTickLabelPos) < avgTickLabelLength) { tickLabelsOverlapping = true; } } if (tickLabelsOverlapping) { tickLabel = ""; // don't draw this tick label } else { // remember these values for next comparison previousDrawnTickLabelPos = yy; previousDrawnTickLabelLength = tickLabelLength; } TextAnchor anchor = null; TextAnchor rotationAnchor = null; double angle = 0.0; if (isVerticalTickLabels()) { anchor = TextAnchor.BOTTOM_CENTER; rotationAnchor = TextAnchor.BOTTOM_CENTER; if (edge == RectangleEdge.LEFT) { angle = -Math.PI / 2.0; } else { angle = Math.PI / 2.0; } } else { if (edge == RectangleEdge.LEFT) { anchor = TextAnchor.CENTER_RIGHT; rotationAnchor = TextAnchor.CENTER_RIGHT; } else { anchor = TextAnchor.CENTER_LEFT; rotationAnchor = TextAnchor.CENTER_LEFT; } } Tick tick = new NumberTick(new Double(currentTickValue), tickLabel, anchor, rotationAnchor, angle); ticks.add(tick); } } return ticks;
Clone fragments detected by clone detection tool
File path: /jfreechart-1.0.10/src/org/jfree/chart/axis/SymbolAxis.java File path: /jfreechart-1.0.10/src/org/jfree/chart/axis/SymbolAxis.java
Method name: List refreshTicksHorizontal(Graphics2D, Rectangle2D, RectangleEdge) Method name: List refreshTicksVertical(Graphics2D, Rectangle2D, RectangleEdge)
Number of AST nodes: 45 Number of AST nodes: 45
1
List ticks = new java.util.ArrayList();
1
List ticks = new java.util.ArrayList();
2
        Font tickLabelFont = getTickLabelFont();
2
        Font tickLabelFont = getTickLabelFont();
3
        g2.setFont(tickLabelFont);
3
        g2.setFont(tickLabelFont);
4
        double size = getTickUnit().getSize();
4
        double size = getTickUnit().getSize();
5
        int count = calculateVisibleTickCount();
5
        int count = calculateVisibleTickCount();
6
        double lowestTickValue = calculateLowestVisibleTickValue();
6
        double lowestTickValue = calculateLowestVisibleTickValue();
7
        double previousDrawnTickLabelPos = 0.0;         
7
        double previousDrawnTickLabelPos = 0.0;         
8
        double previousDrawnTickLabelLength = 0.0;              
8
        double previousDrawnTickLabelLength = 0.0;              
9
        if (count <= ValueAxis.MAXIMUM_TICK_COUNT) {
9
        if (count <= ValueAxis.MAXIMUM_TICK_COUNT) {
10
            for (int i = 0; i < count; i++) {
10
            for (int i = 0; i < count; i++) {
11
                double currentTickValue = lowestTickValue + (i * size);
11
                double currentTickValue = lowestTickValue + (i * size);
12
                double xx = valueToJava2D(currentTickValue, dataArea, edge);
12
                double yy = valueToJava2D(currentTickValue, dataArea, edge);
13
                String tickLabel;
13
                String tickLabel;
14
                NumberFormat formatter = getNumberFormatOverride();
14
                NumberFormat formatter = getNumberFormatOverride();
15
                if (formatter != null) {
15
                if (formatter != null) {
16
                    tickLabel = formatter.format(currentTickValue);
16
                    tickLabel = formatter.format(currentTickValue);
17
                }
17
                }
18
                else {
18
                else {
19
                    tickLabel = valueToString(currentTickValue);
19
                    tickLabel = valueToString(currentTickValue);
20
                }
20
                }
21
                
22
                // avoid to draw overlapping tick labels
21
                // avoid to draw overlapping tick labels
23
                Rectangle2D bounds = TextUtilities.getTextBounds(tickLabel, g2, 
22
                Rectangle2D bounds = TextUtilities.getTextBounds(tickLabel, g2,
24
                        g2.getFontMetrics());
23
                        g2.getFontMetrics());
25
                double tickLabelLength = isVerticalTickLabels() 
24
                double tickLabelLength = isVerticalTickLabels() 
26
                        ? bounds.getHeight() : bounds.getWidth();
25
                    ? bounds.getWidth() : bounds.getHeight();
27
                boolean tickLabelsOverlapping = false;
26
                boolean tickLabelsOverlapping = false;
28
                if (i > 0) {
27
                if (i > 0) {
29
                    double avgTickLabelLength = (previousDrawnTickLabelLength 
28
                    double avgTickLabelLength = (previousDrawnTickLabelLength 
30
                            + tickLabelLength) / 2.0;
29
                            + tickLabelLength) / 2.0;
31
                    if (Math.abs(xx - previousDrawnTickLabelPos) 
30
                    if (Math.abs(yy - previousDrawnTickLabelPos) 
32
                            < avgTickLabelLength) {
31
                            < avgTickLabelLength) {
33
                        tickLabelsOverlapping = true;
32
                        tickLabelsOverlapping = true;    
34
                    }
33
                    }
35
                }
34
                }
36
                if (tickLabelsOverlapping) {
35
                if (tickLabelsOverlapping) {
37
                    tickLabel = ""; // don't draw this tick label
36
                    tickLabel = ""; // don't draw this tick label
38
                }
37
                }
39
                else {
38
                else {
40
                    // remember these values for next comparison
39
                    // remember these values for next comparison
41
                    previousDrawnTickLabelPos = xx;
40
                    previousDrawnTickLabelPos = yy;
42
                    previousDrawnTickLabelLength = tickLabelLength;         
41
                    previousDrawnTickLabelLength = tickLabelLength;         
43
                } 
42
                }
44
                
43
                
45
                TextAnchor anchor = null;
44
                TextAnchor anchor = null;
46
                TextAnchor rotationAnchor = null;
45
                TextAnchor rotationAnchor = null;
47
                double angle = 0.0;
46
                double angle = 0.0;
48
                if (isVerticalTickLabels()) {
47
                if (isVerticalTickLabels()) {
49
                    anchor = TextAnchor.CENTER_RIGHT;
48
                    anchor = TextAnchor.BOTTOM_CENTER;
50
                    rotationAnchor = TextAnchor.CENTER_RIGHT;
49
                    rotationAnchor = TextAnchor.BOTTOM_CENTER;
51
                    if (edge == RectangleEdge.TOP) {
50
                    if (edge == RectangleEdge.LEFT) {
52
                        angle = Math.PI / 2.0;
51
                        angle = -Math.PI / 2.0;
53
                    }
52
                    }
54
                    else {
53
                    else {
55
                        angle = -Math.PI / 2.0;
54
                        angle = Math.PI / 2.0;
56
                    }
55
                    }                    
57
                }
56
                }
58
                else {
57
                else {
59
                    if (edge == RectangleEdge.TOP) {
58
                    if (edge == RectangleEdge.LEFT) {
60
                        anchor = TextAnchor.BOTTOM_CENTER;
59
                        anchor = TextAnchor.CENTER_RIGHT;
61
                        rotationAnchor = TextAnchor.BOTTOM_CENTER;
60
                        rotationAnchor = TextAnchor.CENTER_RIGHT;
62
                    }
61
                    }
63
                    else {
62
                    else {
64
                        anchor = TextAnchor.TOP_CENTER;
63
                        anchor = TextAnchor.CENTER_LEFT;
65
                        rotationAnchor = TextAnchor.TOP_CENTER;
64
                        rotationAnchor = TextAnchor.CENTER_LEFT;
66
                    }
65
                    }
67
                }
66
                }
68
                Tick tick = new NumberTick(new Double(currentTickValue), 
67
                Tick tick = new NumberTick(new Double(currentTickValue), 
69
                        tickLabel, anchor, rotationAnchor, angle);
68
                        tickLabel, anchor, rotationAnchor, angle);
70
                ticks.add(tick);
69
                ticks.add(tick);
71
            }
70
            }
72
        }
71
        }
73
        return ticks;
72
        return ticks;
Summary
Number of common nesting structure subtrees1
Number of refactorable cases1
Number of non-refactorable cases0
Time elapsed for finding largest common nesting structure subtrees (ms)2.4
Clones locationClones are declared in the same class
Number of node comparisons348
  1. {Refactorable}
    Mapping Summary
    Number of mapped statements45
    Number of unmapped statements in the first code fragment0
    Number of unmapped statements in the second code fragment0
    Time elapsed for statement mapping (ms)85.4
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    1
    List ticks = new java.util.ArrayList();
    1
    List ticks = new java.util.ArrayList();
    2
    Font tickLabelFont = getTickLabelFont();
    2
    Font tickLabelFont = getTickLabelFont();
    3
    g2.setFont(tickLabelFont);
    3
    g2.setFont(tickLabelFont);
    4
    double size = getTickUnit().getSize();
    4
    double size = getTickUnit().getSize();
    5
    int count = calculateVisibleTickCount();
    5
    int count = calculateVisibleTickCount();
    6
    double lowestTickValue = calculateLowestVisibleTickValue();
    6
    double lowestTickValue = calculateLowestVisibleTickValue();
    7
    double previousDrawnTickLabelPos = 0.0;
    7
    double previousDrawnTickLabelPos = 0.0;
    8
    double previousDrawnTickLabelLength = 0.0;
    8
    double previousDrawnTickLabelLength = 0.0;
    9
    if (count <= ValueAxis.MAXIMUM_TICK_COUNT)
    9
    if (count <= ValueAxis.MAXIMUM_TICK_COUNT)
    10
    for (int i = 0; i < count; i++)
    10
    for (int i = 0; i < count; i++)
    11
    double currentTickValue = lowestTickValue + (i * size);
    11
    double currentTickValue = lowestTickValue + (i * size);
    12
    double xx = valueToJava2D(currentTickValue, dataArea, edge);
    12
    double xx = valueToJava2D(currentTickValue, dataArea, edge);
    12
    double yy = valueToJava2D(currentTickValue, dataArea, edge);
    Differences
    Expression1Expression2Difference
    xxyyVARIABLE_NAME_MISMATCH
    12
    double yy = valueToJava2D(currentTickValue, dataArea, edge);
    13
    String tickLabel;
    13
    String tickLabel;
    14
    NumberFormat formatter = getNumberFormatOverride();
    14
    NumberFormat formatter = getNumberFormatOverride();
    15
    if (formatter != null)
    15
    if (formatter != null)
    16
    tickLabel = formatter.format(currentTickValue);
    16
    tickLabel = formatter.format(currentTickValue);
    else
    else
    17
    tickLabel = valueToString(currentTickValue);
    17
    tickLabel = valueToString(currentTickValue);
    18
    Rectangle2D bounds = TextUtilities.getTextBounds(tickLabel, g2, g2.getFontMetrics());
    18
    Rectangle2D bounds = TextUtilities.getTextBounds(tickLabel, g2, g2.getFontMetrics());
    19
    double tickLabelLength = isVerticalTickLabels() ? bounds.getHeight() : bounds.getWidth();
    19
    double tickLabelLength = isVerticalTickLabels() ? bounds.getHeight() : bounds.getWidth();
    19
    double tickLabelLength = isVerticalTickLabels() ? bounds.getWidth() : bounds.getHeight();
    Differences
    Expression1Expression2Difference
    getHeightgetWidthMETHOD_INVOCATION_NAME_MISMATCH
    getWidthgetHeightMETHOD_INVOCATION_NAME_MISMATCH
    Preondition Violations
    Expression bounds.getHeight() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression bounds.getWidth() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression bounds.getWidth() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression bounds.getHeight() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    19
    double tickLabelLength = isVerticalTickLabels() ? bounds.getWidth() : bounds.getHeight();
    20
    boolean tickLabelsOverlapping = false;
    20
    boolean tickLabelsOverlapping = false;
    21
    if (i > 0)
    21
    if (i > 0)
    22
    double avgTickLabelLength = (previousDrawnTickLabelLength + tickLabelLength) / 2.0;
    22
    double avgTickLabelLength = (previousDrawnTickLabelLength + tickLabelLength) / 2.0;
    23
    if (Math.abs(xx - previousDrawnTickLabelPos) < avgTickLabelLength)
    23
    if (Math.abs(xx - previousDrawnTickLabelPos) < avgTickLabelLength)
    23
    if (Math.abs(yy - previousDrawnTickLabelPos) < avgTickLabelLength)
    Differences
    Expression1Expression2Difference
    xxyyVARIABLE_NAME_MISMATCH
    23
    if (Math.abs(yy - previousDrawnTickLabelPos) < avgTickLabelLength)
    24
    tickLabelsOverlapping = true;
    24
    tickLabelsOverlapping = true;
    25
    if (tickLabelsOverlapping)
    25
    if (tickLabelsOverlapping)
    26
    tickLabel = "";
    26
    tickLabel = "";
    else
    else
    27
    previousDrawnTickLabelPos = xx;
    27
    previousDrawnTickLabelPos = xx;
    27
    previousDrawnTickLabelPos = yy;
    Differences
    Expression1Expression2Difference
    xxyyVARIABLE_NAME_MISMATCH
    27
    previousDrawnTickLabelPos = yy;
    28
    previousDrawnTickLabelLength = tickLabelLength;
    28
    previousDrawnTickLabelLength = tickLabelLength;
    29
    TextAnchor anchor = null;
    29
    TextAnchor anchor = null;
    30
    TextAnchor rotationAnchor = null;
    30
    TextAnchor rotationAnchor = null;
    31
    double angle = 0.0;
    31
    double angle = 0.0;
    32
    if (isVerticalTickLabels())
    32
    if (isVerticalTickLabels())
    33
    anchor = TextAnchor.CENTER_RIGHT;
    33
    anchor = TextAnchor.CENTER_RIGHT;
    33
    anchor = TextAnchor.BOTTOM_CENTER;
    Differences
    Expression1Expression2Difference
    CENTER_RIGHTBOTTOM_CENTERVARIABLE_NAME_MISMATCH
    33
    anchor = TextAnchor.BOTTOM_CENTER;
    34
    rotationAnchor = TextAnchor.CENTER_RIGHT;
    34
    rotationAnchor = TextAnchor.CENTER_RIGHT;
    34
    rotationAnchor = TextAnchor.BOTTOM_CENTER;
    Differences
    Expression1Expression2Difference
    CENTER_RIGHTBOTTOM_CENTERVARIABLE_NAME_MISMATCH
    34
    rotationAnchor = TextAnchor.BOTTOM_CENTER;
    35
    if (edge == RectangleEdge.TOP)
    35
    if (edge == RectangleEdge.TOP)
    35
    if (edge == RectangleEdge.LEFT)
    Differences
    Expression1Expression2Difference
    TOPLEFTVARIABLE_NAME_MISMATCH
    35
    if (edge == RectangleEdge.LEFT)
    36
    angle = Math.PI / 2.0;
    36
    angle = Math.PI / 2.0;
    36
    angle = -Math.PI / 2.0;
    Differences
    Expression1Expression2Difference
    Math.PI-Math.PITYPE_COMPATIBLE_REPLACEMENT
    36
    angle = -Math.PI / 2.0;
    else
    else
    37
    angle = -Math.PI / 2.0;
    37
    angle = -Math.PI / 2.0;
    37
    angle = Math.PI / 2.0;
    Differences
    Expression1Expression2Difference
    -Math.PIMath.PITYPE_COMPATIBLE_REPLACEMENT
    37
    angle = Math.PI / 2.0;
    else
    else
    38
    if (edge == RectangleEdge.TOP)
    38
    if (edge == RectangleEdge.TOP)
    38
    if (edge == RectangleEdge.LEFT)
    Differences
    Expression1Expression2Difference
    TOPLEFTVARIABLE_NAME_MISMATCH
    38
    if (edge == RectangleEdge.LEFT)
    39
    anchor = TextAnchor.BOTTOM_CENTER;
    39
    anchor = TextAnchor.BOTTOM_CENTER;
    39
    anchor = TextAnchor.CENTER_RIGHT;
    Differences
    Expression1Expression2Difference
    BOTTOM_CENTERCENTER_RIGHTVARIABLE_NAME_MISMATCH
    39
    anchor = TextAnchor.CENTER_RIGHT;
    40
    rotationAnchor = TextAnchor.BOTTOM_CENTER;
    40
    rotationAnchor = TextAnchor.BOTTOM_CENTER;
    40
    rotationAnchor = TextAnchor.CENTER_RIGHT;
    Differences
    Expression1Expression2Difference
    BOTTOM_CENTERCENTER_RIGHTVARIABLE_NAME_MISMATCH
    40
    rotationAnchor = TextAnchor.CENTER_RIGHT;
    else
    else
    41
    anchor = TextAnchor.TOP_CENTER;
    41
    anchor = TextAnchor.TOP_CENTER;
    41
    anchor = TextAnchor.CENTER_LEFT;
    Differences
    Expression1Expression2Difference
    TOP_CENTERCENTER_LEFTVARIABLE_NAME_MISMATCH
    41
    anchor = TextAnchor.CENTER_LEFT;
    42
    rotationAnchor = TextAnchor.TOP_CENTER;
    42
    rotationAnchor = TextAnchor.TOP_CENTER;
    42
    rotationAnchor = TextAnchor.CENTER_LEFT;
    Differences
    Expression1Expression2Difference
    TOP_CENTERCENTER_LEFTVARIABLE_NAME_MISMATCH
    42
    rotationAnchor = TextAnchor.CENTER_LEFT;
    43
    Tick tick = new NumberTick(new Double(currentTickValue), tickLabel, anchor, rotationAnchor, angle);
    43
    Tick tick = new NumberTick(new Double(currentTickValue), tickLabel, anchor, rotationAnchor, angle);
    44
    ticks.add(tick);
    44
    ticks.add(tick);
    45
    return ticks;
    45
    return ticks;
    Precondition Violations (4)
    Row Violation
    1Expression bounds.getHeight() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    2Expression bounds.getWidth() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    3Expression bounds.getWidth() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    4Expression bounds.getHeight() cannot be parameterized, because it has dependencies to/from statements that will be extracted