DefaultKeyedValues data = new DefaultKeyedValues(); data.addValue("C", new Double(1.0)); data.addValue("B", null); data.addValue("D", new Double(3.0)); data.addValue("A", new Double(2.0)); data.sortByValues(SortOrder.ASCENDING); // check key order assertEquals(data.getKey(0), "C"); assertEquals(data.getKey(1), "A"); assertEquals(data.getKey(2), "D"); assertEquals(data.getKey(3), "B"); // check retrieve value by key assertEquals(data.getValue("A"), new Double(2.0)); assertEquals(data.getValue("B"), null); assertEquals(data.getValue("C"), new Double(1.0)); assertEquals(data.getValue("D"), new Double(3.0)); // check retrieve value by index assertEquals(data.getValue(0), new Double(1.0)); assertEquals(data.getValue(1), new Double(2.0)); assertEquals(data.getValue(2), new Double(3.0)); assertEquals(data.getValue(3), null);
DefaultKeyedValues data = new DefaultKeyedValues(); data.addValue("C", new Double(1.0)); data.addValue("B", null); data.addValue("D", new Double(3.0)); data.addValue("A", new Double(2.0)); data.sortByValues(SortOrder.DESCENDING); // check key order assertEquals(data.getKey(0), "D"); assertEquals(data.getKey(1), "A"); assertEquals(data.getKey(2), "C"); assertEquals(data.getKey(3), "B"); // check retrieve value by key assertEquals(data.getValue("A"), new Double(2.0)); assertEquals(data.getValue("B"), null); assertEquals(data.getValue("C"), new Double(1.0)); assertEquals(data.getValue("D"), new Double(3.0)); // check retrieve value by index assertEquals(data.getValue(0), new Double(3.0)); assertEquals(data.getValue(1), new Double(2.0)); assertEquals(data.getValue(2), new Double(1.0)); assertEquals(data.getValue(3), null);
Clone fragments detected by clone detection tool
File path: /jfreechart-1.0.10/tests/org/jfree/data/junit/DefaultKeyedValuesTests.java File path: /jfreechart-1.0.10/tests/org/jfree/data/junit/DefaultKeyedValuesTests.java
Method name: void testSortByValueAscending() Method name: void testSortByValueDescending()
Number of AST nodes: 18 Number of AST nodes: 18
1
DefaultKeyedValues data = new DefaultKeyedValues();
1
DefaultKeyedValues data = new DefaultKeyedValues();
2
        data.addValue("C", new Double(1.0));
2
        data.addValue("C", new Double(1.0));
3
        data.addValue("B", null);
3
        data.addValue("B", null);
4
        data.addValue("D", new Double(3.0));
4
        data.addValue("D", new Double(3.0));
5
        data.addValue("A", new Double(2.0));
5
        data.addValue("A", new Double(2.0));
6
        data.sortByValues(SortOrder.ASCENDING);
6
        data.sortByValues(SortOrder.DESCENDING);
7
        // check key order
7
        // check key order
8
        assertEquals(data.getKey(0), "C");
8
        assertEquals(data.getKey(0), "D");
9
        assertEquals(data.getKey(1), "A");
9
        assertEquals(data.getKey(1), "A");
10
        assertEquals(data.getKey(2), "D");
10
        assertEquals(data.getKey(2), "C");
11
        assertEquals(data.getKey(3), "B");
11
        assertEquals(data.getKey(3), "B");
12
        // check retrieve value by key
12
        // check retrieve value by key
13
        assertEquals(data.getValue("A"), new Double(2.0));
13
        assertEquals(data.getValue("A"), new Double(2.0));
14
        assertEquals(data.getValue("B"), null);
14
        assertEquals(data.getValue("B"), null);
15
        assertEquals(data.getValue("C"), new Double(1.0));
15
        assertEquals(data.getValue("C"), new Double(1.0));
16
        assertEquals(data.getValue("D"), new Double(3.0));
16
        assertEquals(data.getValue("D"), new Double(3.0));
17
        // check retrieve value by index
17
        // check retrieve value by index
18
        assertEquals(data.getValue(0), new Double(1.0));
18
        assertEquals(data.getValue(0), new Double(3.0));
19
        assertEquals(data.getValue(1), new Double(2.0));
19
        assertEquals(data.getValue(1), new Double(2.0));
20
        assertEquals(data.getValue(2), new Double(3.0));
20
        assertEquals(data.getValue(2), new Double(1.0));
21
        assertEquals(data.getValue(3), null);
21
        assertEquals(data.getValue(3), null);
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)0.0
Clones locationClones are declared in the same class
Number of node comparisons180
  1. {Refactorable}
    Mapping Summary
    Number of mapped statements18
    Number of unmapped statements in the first code fragment0
    Number of unmapped statements in the second code fragment0
    Time elapsed for statement mapping (ms)0.0
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    1
    DefaultKeyedValues data = new DefaultKeyedValues();
    1
    DefaultKeyedValues data = new DefaultKeyedValues();
    2
    data.addValue("C", new Double(1.0));
    2
    data.addValue("C", new Double(1.0));
    3
    data.addValue("B", null);
    3
    data.addValue("B", null);
    4
    data.addValue("D", new Double(3.0));
    4
    data.addValue("D", new Double(3.0));
    5
    data.addValue("A", new Double(2.0));
    5
    data.addValue("A", new Double(2.0));
    6
    data.sortByValues(SortOrder.ASCENDING);
    6
    data.sortByValues(SortOrder.ASCENDING);
    6
    data.sortByValues(SortOrder.DESCENDING);
    Differences
    Expression1Expression2Difference
    ASCENDINGDESCENDINGVARIABLE_NAME_MISMATCH
    6
    data.sortByValues(SortOrder.DESCENDING);
    7
    assertEquals(data.getKey(0), "C");
    7
    assertEquals(data.getKey(0), "C");
    9
    assertEquals(data.getKey(2), "C");
    Differences
    Expression1Expression2Difference
    02LITERAL_VALUE_MISMATCH
    9
    assertEquals(data.getKey(2), "C");
    8
    assertEquals(data.getKey(1), "A");
    8
    assertEquals(data.getKey(1), "A");
    9
    assertEquals(data.getKey(2), "D");
    9
    assertEquals(data.getKey(2), "D");
    7
    assertEquals(data.getKey(0), "D");
    Differences
    Expression1Expression2Difference
    20LITERAL_VALUE_MISMATCH
    7
    assertEquals(data.getKey(0), "D");
    10
    assertEquals(data.getKey(3), "B");
    10
    assertEquals(data.getKey(3), "B");
    11
    assertEquals(data.getValue("A"), new Double(2.0));
    11
    assertEquals(data.getValue("A"), new Double(2.0));
    12
    assertEquals(data.getValue("B"), null);
    12
    assertEquals(data.getValue("B"), null);
    13
    assertEquals(data.getValue("C"), new Double(1.0));
    13
    assertEquals(data.getValue("C"), new Double(1.0));
    14
    assertEquals(data.getValue("D"), new Double(3.0));
    14
    assertEquals(data.getValue("D"), new Double(3.0));
    15
    assertEquals(data.getValue(0), new Double(1.0));
    15
    assertEquals(data.getValue(0), new Double(1.0));
    17
    assertEquals(data.getValue(2), new Double(1.0));
    Differences
    Expression1Expression2Difference
    02LITERAL_VALUE_MISMATCH
    17
    assertEquals(data.getValue(2), new Double(1.0));
    16
    assertEquals(data.getValue(1), new Double(2.0));
    16
    assertEquals(data.getValue(1), new Double(2.0));
    17
    assertEquals(data.getValue(2), new Double(3.0));
    17
    assertEquals(data.getValue(2), new Double(3.0));
    15
    assertEquals(data.getValue(0), new Double(3.0));
    Differences
    Expression1Expression2Difference
    20LITERAL_VALUE_MISMATCH
    15
    assertEquals(data.getValue(0), new Double(3.0));
    18
    assertEquals(data.getValue(3), null);
    18
    assertEquals(data.getValue(3), null);
    Precondition Violations (0)
    Row Violation