178-1-2

RectangleInsets tickLabelInsets = getTickLabelInsets(); double result = tickLabelInsets.getLeft() + tickLabelInsets.getRight(); Font tickLabelFont = getTickLabelFont(); FontRenderContext frc = g2.getFontRenderContext(); LineMetrics lm = tickLabelFont.getLineMetrics("ABCxyz", frc); if (isVerticalTickLabels()) { // all tick labels have the same width (equal to the height of // the font)... result += lm.getHeight(); } else { // look at lower and upper bounds... DateRange range = (DateRange) getRange(); Date lower = range.getLowerDate(); Date upper = range.getUpperDate(); String lowerStr = null; String upperStr = null; DateFormat formatter = getDateFormatOverride(); if (formatter != null) { lowerStr = formatter.format(lower); upperStr = formatter.format(upper); } else { lowerStr = unit.dateToString(lower); upperStr = unit.dateToString(upper); } FontMetrics fm = g2.getFontMetrics(tickLabelFont); double w1 = fm.stringWidth(lowerStr); double w2 = fm.stringWidth(upperStr); result += Math.max(w1, w2); } return result;
RectangleInsets tickLabelInsets = getTickLabelInsets(); double result = tickLabelInsets.getTop() + tickLabelInsets.getBottom(); Font tickLabelFont = getTickLabelFont(); FontRenderContext frc = g2.getFontRenderContext(); LineMetrics lm = tickLabelFont.getLineMetrics("ABCxyz", frc); if (!isVerticalTickLabels()) { // all tick labels have the same width (equal to the height of // the font)... result += lm.getHeight(); } else { // look at lower and upper bounds... DateRange range = (DateRange) getRange(); Date lower = range.getLowerDate(); Date upper = range.getUpperDate(); String lowerStr = null; String upperStr = null; DateFormat formatter = getDateFormatOverride(); if (formatter != null) { lowerStr = formatter.format(lower); upperStr = formatter.format(upper); } else { lowerStr = unit.dateToString(lower); upperStr = unit.dateToString(upper); } FontMetrics fm = g2.getFontMetrics(tickLabelFont); double w1 = fm.stringWidth(lowerStr); double w2 = fm.stringWidth(upperStr); result += Math.max(w1, w2); } return result;

Clone fragments detected by clone detection tool
File path: /jfreechart-1.0.10/src/org/jfree/chart/axis/DateAxis.java |  | File path: /jfreechart-1.0.10/src/org/jfree/chart/axis/DateAxis.java
Method name: `double estimateMaximumTickLabelWidth(Graphics2D, DateTickUnit)` |  | Method name: `double estimateMaximumTickLabelHeight(Graphics2D, DateTickUnit)`
Number of AST nodes: 23 |  | Number of AST nodes: 23

1

    RectangleInsets tickLabelInsets = getTickLabelInsets();↵

1

    RectangleInsets tickLabelInsets = getTickLabelInsets();↵

2

            double result = tickLabelInsets.getLeft() + tickLabelInsets.getRight();↵

2

            double result = tickLabelInsets.getTop() + tickLabelInsets.getBottom();↵

3

            Font tickLabelFont = getTickLabelFont();↵

3

            Font tickLabelFont = getTickLabelFont();↵

4

            FontRenderContext frc = g2.getFontRenderContext();↵

4

            FontRenderContext frc = g2.getFontRenderContext();↵

5

            LineMetrics lm = tickLabelFont.getLineMetrics("ABCxyz", frc);↵

5

            LineMetrics lm = tickLabelFont.getLineMetrics("ABCxyz", frc);↵

6

            if (isVerticalTickLabels()) {↵

6

            if (!isVerticalTickLabels()) {↵

7

                // all tick labels have the same width (equal to the height of↵

7

                // all tick labels have the same width (equal to the height of↵

8

                // the font)...↵

8

                // the font)...↵

9

                result += lm.getHeight();↵

9

                result += lm.getHeight();↵

10

            }↵

10

            }↵

11

            else {↵

11

            else {↵

12

                // look at lower and upper bounds...↵

12

                // look at lower and upper bounds...↵

13

                DateRange range = (DateRange) getRange();↵

13

                DateRange range = (DateRange) getRange();↵

14

                Date lower = range.getLowerDate();↵

14

                Date lower = range.getLowerDate();↵

15

                Date upper = range.getUpperDate();↵

15

                Date upper = range.getUpperDate();↵

16

                String lowerStr = null;↵

16

                String lowerStr = null;↵

17

                String upperStr = null;↵

17

                String upperStr = null;↵

18

                DateFormat formatter = getDateFormatOverride();↵

18

                DateFormat formatter = getDateFormatOverride();↵

19

                if (formatter != null) {↵

19

                if (formatter != null) {↵

20

                    lowerStr = formatter.format(lower);↵

20

                    lowerStr = formatter.format(lower);↵

21

                    upperStr = formatter.format(upper);↵

21

                    upperStr = formatter.format(upper);↵

22

                }↵

22

                }↵

23

                else {↵

23

                else {↵

24

                    lowerStr = unit.dateToString(lower);↵

24

                    lowerStr = unit.dateToString(lower);↵

25

                    upperStr = unit.dateToString(upper);↵

25

                    upperStr = unit.dateToString(upper);↵

26

                }↵

26

                }↵

27

                FontMetrics fm = g2.getFontMetrics(tickLabelFont);↵

27

                FontMetrics fm = g2.getFontMetrics(tickLabelFont);↵

28

                double w1 = fm.stringWidth(lowerStr);↵

28

                double w1 = fm.stringWidth(lowerStr);↵

29

                double w2 = fm.stringWidth(upperStr);↵

29

                double w2 = fm.stringWidth(upperStr);↵

30

                result += Math.max(w1, w2);↵

30

                result += Math.max(w1, w2);↵

31

            }↵

31

            }↵

32

            return result;

32

            return result;

See real code fragment |  | See real code fragment

Summary
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) | 0.3
Clones location | Clones are declared in the same class
Number of node comparisons | 189

1. {Non-refactorable}

   Mapping Summary
   Number of mapped statements | 23
   Number of unmapped statements in the first code fragment | 0
   Number of unmapped statements in the second code fragment | 0
   Time elapsed for statement mapping (ms) | 6.2
   Clone type | Type 2

   Mapped Statements
   ID | Statement |  | ID | Statement
   --- | --- | --- | --- | ---

   1

       RectangleInsets tickLabelInsets = getTickLabelInsets();

   1

       RectangleInsets tickLabelInsets = getTickLabelInsets();

   2

       double result = tickLabelInsets.getLeft() + tickLabelInsets.getRight();

   2 | double result = tickLabelInsets.getLeft() + tickLabelInsets.getRight();
   2 | double result = tickLabelInsets.getTop() + tickLabelInsets.getBottom();

   Differences
   Expression1 | Expression2 | Difference
   --- | --- | ---
   getLeft | getTop | METHOD_INVOCATION_NAME_MISMATCH
   getRight | getBottom | METHOD_INVOCATION_NAME_MISMATCH

   Preondition Violations
   Expression tickLabelInsets.getLeft() cannot be parameterized, because it has dependencies to/from statements that will be extracted
   Expression tickLabelInsets.getTop() cannot be parameterized, because it has dependencies to/from statements that will be extracted
   Expression tickLabelInsets.getRight() cannot be parameterized, because it has dependencies to/from statements that will be extracted
   Expression tickLabelInsets.getBottom() cannot be parameterized, because it has dependencies to/from statements that will be extracted

   2

       double result = tickLabelInsets.getTop() + tickLabelInsets.getBottom();

   3

       Font tickLabelFont = getTickLabelFont();

   3

       Font tickLabelFont = getTickLabelFont();

   4

       FontRenderContext frc = g2.getFontRenderContext();

   4

       FontRenderContext frc = g2.getFontRenderContext();

   5

       LineMetrics lm = tickLabelFont.getLineMetrics("ABCxyz", frc);

   5

       LineMetrics lm = tickLabelFont.getLineMetrics("ABCxyz", frc);

   6

       if (isVerticalTickLabels())

   6 | if (isVerticalTickLabels())
   6 | if (! isVerticalTickLabels())

   Differences
   Expression1 | Expression2 | Difference
   --- | --- | ---
   isVerticalTickLabels() | !isVerticalTickLabels() | TYPE_COMPATIBLE_REPLACEMENT

   6

       if (!isVerticalTickLabels())

   7

       result += lm.getHeight();

   7

       result += lm.getHeight();

       else

       else

   8

       DateRange range = (DateRange)getRange();

   8

       DateRange range = (DateRange)getRange();

   9

       Date lower = range.getLowerDate();

   9

       Date lower = range.getLowerDate();

   10

       Date upper = range.getUpperDate();

   10

       Date upper = range.getUpperDate();

   11

       String lowerStr = null;

   11

       String lowerStr = null;

   12

       String upperStr = null;

   12

       String upperStr = null;

   13

       DateFormat formatter = getDateFormatOverride();

   13

       DateFormat formatter = getDateFormatOverride();

   14

       if (formatter != null)

   14

       if (formatter != null)

   15

       lowerStr = formatter.format(lower);

   15

       lowerStr = formatter.format(lower);

   16

       upperStr = formatter.format(upper);

   16

       upperStr = formatter.format(upper);

       else

       else

   17

       lowerStr = unit.dateToString(lower);

   17

       lowerStr = unit.dateToString(lower);

   18

       upperStr = unit.dateToString(upper);

   18

       upperStr = unit.dateToString(upper);

   19

       FontMetrics fm = g2.getFontMetrics(tickLabelFont);

   19

       FontMetrics fm = g2.getFontMetrics(tickLabelFont);

   20

       double w1 = fm.stringWidth(lowerStr);

   20

       double w1 = fm.stringWidth(lowerStr);

   21

       double w2 = fm.stringWidth(upperStr);

   21

       double w2 = fm.stringWidth(upperStr);

   22

       result += Math.max(w1, w2);

   22

       result += Math.max(w1, w2);

   23

       return result;

   23

       return result;

   Precondition Violations (4)
   Row | Violation
   --- | ---
   1 | Expression tickLabelInsets.getLeft() cannot be parameterized, because it has dependencies to/from statements that will be extracted
   2 | Expression tickLabelInsets.getTop() cannot be parameterized, because it has dependencies to/from statements that will be extracted
   3 | Expression tickLabelInsets.getRight() cannot be parameterized, because it has dependencies to/from statements that will be extracted
   4 | Expression tickLabelInsets.getBottom() cannot be parameterized, because it has dependencies to/from statements that will be extracted