public class PaintMap implements Cloneable, Serializable { /** For serialization. */ static final long serialVersionUID = -4639833772123069274L; /** Storage for the keys and values. */ private transient Map store; /** * Creates a new (empty) map. */ public PaintMap() { this.store = new HashMap(); } /** * Returns the paint associated with the specified key, or * <code>null</code>. * * @param key the key (<code>null</code> not permitted). * * @return The paint, or <code>null</code>. * * @throws IllegalArgumentException if <code>key</code> is * <code>null</code>. */ public Paint getPaint(Comparable key) { if (key == null) { throw new IllegalArgumentException("Null 'key' argument."); } return (Paint) this.store.get(key); } /** * Returns <code>true</code> if the map contains the specified key, and * <code>false</code> otherwise. * * @param key the key. * * @return <code>true</code> if the map contains the specified key, and * <code>false</code> otherwise. */ public boolean containsKey(Comparable key) { return this.store.containsKey(key); } /** * Adds a mapping between the specified <code>key</code> and * <code>paint</code> values. * * @param key the key (<code>null</code> not permitted). * @param paint the paint. * * @throws IllegalArgumentException if <code>key</code> is * <code>null</code>. */ public void put(Comparable key, Paint paint) { if (key == null) { throw new IllegalArgumentException("Null 'key' argument."); } this.store.put(key, paint); } /** * Resets the map to empty. */ public void clear() { this.store.clear(); } /** * Tests this map for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof PaintMap)) { return false; } PaintMap that = (PaintMap) obj; if (this.store.size() != that.store.size()) { return false; } Set keys = this.store.keySet(); Iterator iterator = keys.iterator(); while (iterator.hasNext()) { Comparable key = (Comparable) iterator.next(); Paint p1 = getPaint(key); Paint p2 = that.getPaint(key); if (!PaintUtilities.equal(p1, p2)) { return false; } } return true; } /** * Returns a clone of this <code>PaintMap</code>. * * @return A clone of this instance. * * @throws CloneNotSupportedException if any key is not cloneable. */ public Object clone() throws CloneNotSupportedException { // TODO: I think we need to make sure the keys are actually cloned, // whereas the paint instances are always immutable so they're OK return super.clone(); } /** * Provides serialization support. * * @param stream the output stream. * * @throws IOException if there is an I/O error. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); stream.writeInt(this.store.size()); Set keys = this.store.keySet(); Iterator iterator = keys.iterator(); while (iterator.hasNext()) { Comparable key = (Comparable) iterator.next(); stream.writeObject(key); Paint paint = getPaint(key); SerialUtilities.writePaint(paint, stream); } } /** * Provides serialization support. * * @param stream the input stream. * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.store = new HashMap(); int keyCount = stream.readInt(); for (int i = 0; i < keyCount; i++) { Comparable key = (Comparable) stream.readObject(); Paint paint = SerialUtilities.readPaint(stream); this.store.put(key, paint)
public class StrokeMap implements Cloneable, Serializable { /** For serialization. */ static final long serialVersionUID = -8148916785963525169L; /** Storage for the keys and values. */ private transient Map store; /** * Creates a new (empty) map. */ public StrokeMap() { this.store = new TreeMap(); } /** * Returns the stroke associated with the specified key, or * <code>null</code>. * * @param key the key (<code>null</code> not permitted). * * @return The stroke, or <code>null</code>. * * @throws IllegalArgumentException if <code>key</code> is * <code>null</code>. */ public Stroke getStroke(Comparable key) { if (key == null) { throw new IllegalArgumentException("Null 'key' argument."); } return (Stroke) this.store.get(key); } /** * Returns <code>true</code> if the map contains the specified key, and * <code>false</code> otherwise. * * @param key the key. * * @return <code>true</code> if the map contains the specified key, and * <code>false</code> otherwise. */ public boolean containsKey(Comparable key) { return this.store.containsKey(key); } /** * Adds a mapping between the specified <code>key</code> and * <code>stroke</code> values. * * @param key the key (<code>null</code> not permitted). * @param stroke the stroke. */ public void put(Comparable key, Stroke stroke) { if (key == null) { throw new IllegalArgumentException("Null 'key' argument."); } this.store.put(key, stroke); } /** * Resets the map to empty. */ public void clear() { this.store.clear(); } /** * Tests this map for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof StrokeMap)) { return false; } StrokeMap that = (StrokeMap) obj; if (this.store.size() != that.store.size()) { return false; } Set keys = this.store.keySet(); Iterator iterator = keys.iterator(); while (iterator.hasNext()) { Comparable key = (Comparable) iterator.next(); Stroke s1 = getStroke(key); Stroke s2 = that.getStroke(key); if (!ObjectUtilities.equal(s1, s2)) { return false; } } return true; } /** * Returns a clone of this <code>StrokeMap</code>. * * @return A clone of this instance. * * @throws CloneNotSupportedException if any key is not cloneable. */ public Object clone() throws CloneNotSupportedException { // TODO: I think we need to make sure the keys are actually cloned, // whereas the stroke instances are always immutable so they're OK return super.clone(); } /** * Provides serialization support. * * @param stream the output stream. * * @throws IOException if there is an I/O error. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); stream.writeInt(this.store.size()); Set keys = this.store.keySet(); Iterator iterator = keys.iterator(); while (iterator.hasNext()) { Comparable key = (Comparable) iterator.next(); stream.writeObject(key); Stroke stroke = getStroke(key); SerialUtilities.writeStroke(stroke, stream); } } /** * Provides serialization support. * * @param stream the input stream. * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.store = new TreeMap(); int keyCount = stream.readInt(); for (int i = 0; i < keyCount; i++) { Comparable key = (Comparable) stream.readObject(); Stroke stroke = SerialUtilities.readStroke(stream); this.store.put(key, stroke)
Clone fragments detected by clone detection tool
File path: /jfreechart-1.0.10/src/org/jfree/chart/PaintMap.java File path: /jfreechart-1.0.10/src/org/jfree/chart/StrokeMap.java
Method name: Method name:
Number of AST nodes: 0 Number of AST nodes: 0
1
public class PaintMap implements Cloneable, Serializable {
1
public class StrokeMap implements Cloneable, Serializable {
2
    /** For serialization. */
2
    /** For serialization. */
3
    static final long serialVersionUID = -4639833772123069274L;
3
    static final long serialVersionUID = -8148916785963525169L;
4
    /** Storage for the keys and values. */
4
    /** Storage for the keys and values. */
5
    private transient Map store;
5
    private transient Map store;
6
    
6
    
7
    /**
7
    /**
8
     * Creates a new (empty) map.
8
     * Creates a new (empty) map.
9
     */
9
     */
10
    public PaintMap() {
10
    public StrokeMap() {
11
        this.store = new HashMap();    
11
        this.store = new TreeMap();    
12
    }
12
    }
13
    
13
    
14
    /**
14
    /**
15
     * Returns the paint associated with the specified key, or 
15
     * Returns the stroke associated with the specified key, or 
16
     * <code>null</code>.
16
     * <code>null</code>.
17
     * 
17
     * 
18
     * @param key  the key (<code>null</code> not permitted).
18
     * @param key  the key (<code>null</code> not permitted).
19
     * 
19
     * 
20
     * @return The paint, or <code>null</code>.
20
     * @return The stroke, or <code>null</code>.
21
     * 
21
     * 
22
     * @throws IllegalArgumentException if <code>key</code> is 
22
     * @throws IllegalArgumentException if <code>key</code> is 
23
     *     <code>null</code>.
23
     *     <code>null</code>.
24
     */
24
     */
25
    public Paint getPaint(Comparable key) {
25
    public Stroke getStroke(Comparable key) {
26
        if (key == null) {
26
        if (key == null) {
27
            throw new IllegalArgumentException("Null 'key' argument.");
27
            throw new IllegalArgumentException("Null 'key' argument.");
28
        }
28
        }
29
        return (Paint) this.store.get(key);
29
        return (Stroke) this.store.get(key);
30
    }
30
    }
31
    
31
    
32
    /**
32
    /**
33
     * Returns <code>true</code> if the map contains the specified key, and
33
     * Returns <code>true</code> if the map contains the specified key, and
34
     * <code>false</code> otherwise.
34
     * <code>false</code> otherwise.
35
     * 
35
     * 
36
     * @param key  the key.
36
     * @param key  the key.
37
     * 
37
     * 
38
     * @return <code>true</code> if the map contains the specified key, and
38
     * @return <code>true</code> if the map contains the specified key, and
39
     * <code>false</code> otherwise.
39
     * <code>false</code> otherwise.
40
     */
40
     */
41
    public boolean containsKey(Comparable key) {
41
    public boolean containsKey(Comparable key) {
42
        return this.store.containsKey(key);
42
        return this.store.containsKey(key);
43
    }
43
    }
44
    
44
    
45
    /**
45
    /**
46
     * Adds a mapping between the specified <code>key</code> and 
46
     * Adds a mapping between the specified <code>key</code> and 
47
     * <code>paint</code> values.
47
     * <code>stroke</code> values.
48
     * 
48
     * 
49
     * @param key  the key (<code>null</code> not permitted).
49
     * @param key  the key (<code>null</code> not permitted).
50
     * @param paint  the paint.
50
     * @param 
51
     * 
52
     * @throws IllegalArgumentException if <code>key</code> is 
53
     *     <code>null</code>.
51
stroke  the stroke.
54
     */
52
     */
55
    public void put(Comparable key, Paint paint) {
53
    public void put(Comparable key, Stroke stroke) {
56
        if (key == null) {
54
        if (key == null) { 
57
            throw new IllegalArgumentException("Null 'key' argument.");
55
            throw new IllegalArgumentException("Null 'key' argument.");
58
        }
56
        }
59
        this.store.put(key, paint);
57
        this.store.put(key, stroke);
60
    }
58
    }
61
    
59
    
62
    /**
60
    /**
63
     * Resets the map to empty.
61
     * Resets the map to empty.
64
     */
62
     */
65
    public void clear() {
63
    public void clear() {
66
        this.store.clear();
64
        this.store.clear();
67
    }
65
    }
68
    
66
    
69
    /**
67
    /**
70
     * Tests this map for equality with an arbitrary object.
68
     * Tests this map for equality with an arbitrary object.
71
     * 
69
     * 
72
     * @param obj  the object (<code>null</code> permitted).
70
     * @param obj  the object (<code>null</code> permitted).
73
     * 
71
     * 
74
     * @return A boolean.
72
     * @return A boolean.
75
     */
73
     */
76
    public boolean equals(Object obj) {
74
    public boolean equals(Object obj) {
77
        if (obj == this) {
75
        if (obj == this) {
78
            return true;
76
            return true;
79
        }
77
        }
80
        if (!(obj instanceof PaintMap)) {
78
        if (!(obj instanceof StrokeMap)) {
81
            return false;
79
            return false;
82
        }
80
        }
83
        PaintMap that = (PaintMap) obj;
81
        StrokeMap that = (StrokeMap) obj;
84
        if (this.store.size() != that.store.size()) {
82
        if (this.store.size() != that.store.size()) {
85
            return false;
83
            return false;
86
        }
84
        }
87
        Set keys = this.store.keySet();
85
        Set keys = this.store.keySet();
88
        Iterator iterator = keys.iterator();
86
        Iterator iterator = keys.iterator();
89
        while (iterator.hasNext()) {
87
        while (iterator.hasNext()) {
90
            Comparable key = (Comparable) iterator.next();
88
            Comparable key = (Comparable) iterator.next();
91
            Paint p1 = getPaint(key);
89
            Stroke s1 = getStroke(key);
92
            Paint p2 = that.getPaint(key);
90
            Stroke s2 = that.getStroke(key);
93
            if (!PaintUtilities.equal(p1, p2)) {
91
            if (!ObjectUtilities.equal(s1, s2)) {
94
                return false;
92
                return false;
95
            }
93
            }
96
        }
94
        }
97
        return true;
95
        return true;
98
    }
96
    }
99
    
97
    
100
    /**
98
    /**
101
     * Returns a clone of this <code>PaintMap</code>.
99
     * Returns a clone of this <code>StrokeMap</code>.
102
     * 
100
     * 
103
     * @return A clone of this instance.
101
     * @return A clone of this instance.
104
     * 
102
     * 
105
     * @throws CloneNotSupportedException if any key is not cloneable.
103
     * @throws CloneNotSupportedException if any key is not cloneable.
106
     */
104
     */
107
    public Object clone() throws CloneNotSupportedException {
105
    public Object clone() throws CloneNotSupportedException {
108
        // TODO: I think we need to make sure the keys are actually cloned,
106
        // TODO: I think we need to make sure the keys are actually cloned,
109
        // whereas the paint instances are always immutable so they're OK
107
        // whereas the stroke instances are always immutable so they're OK
110
        return super.clone();
108
        return super.clone();
111
    }
109
    }
112
    
110
    
113
    /**
111
    /**
114
     * Provides serialization support.
112
     * Provides serialization support.
115
     *
113
     *
116
     * @param stream  the output stream.
114
     * @param stream  the output stream.
117
     *
115
     *
118
     * @throws IOException  if there is an I/O error.
116
     * @throws IOException  if there is an I/O error.
119
     */
117
     */
120
    private void writeObject(ObjectOutputStream stream) throws IOException {
118
    private void writeObject(ObjectOutputStream stream) throws IOException {
121
        stream.defaultWriteObject();
119
        stream.defaultWriteObject();
122
        stream.writeInt(this.store.size());
120
        stream.writeInt(this.store.size());
123
        Set keys = this.store.keySet();
121
        Set keys = this.store.keySet();
124
        Iterator iterator = keys.iterator();
122
        Iterator iterator = keys.iterator();
125
        while (iterator.hasNext()) {
123
        while (iterator.hasNext()) {
126
            Comparable key = (Comparable) iterator.next();
124
            Comparable key = (Comparable) iterator.next();
127
            stream.writeObject(key);
125
            stream.writeObject(key);
128
            Paint paint = getPaint(key);
126
            Stroke stroke = getStroke(key);
129
            SerialUtilities.writePaint(paint, stream);
127
            SerialUtilities.writeStroke(stroke, stream);
130
        }
128
        }
131
    }
129
    }
132
    /**
130
    /**
133
     * Provides serialization support.
131
     * Provides serialization support.
134
     *
132
     *
135
     * @param stream  the input stream.
133
     * @param stream  the input stream.
136
     *
134
     *
137
     * @throws IOException  if there is an I/O error.
135
     * @throws IOException  if there is an I/O error.
138
     * @throws ClassNotFoundException  if there is a classpath problem.
136
     * @throws ClassNotFoundException  if there is a classpath problem.
139
     */
137
     */
140
    private void readObject(ObjectInputStream stream) 
138
    private void readObject(ObjectInputStream stream) 
141
            throws IOException, ClassNotFoundException {
139
            throws IOException, ClassNotFoundException {
142
        stream.defaultReadObject();
140
        stream.defaultReadObject();
143
        this.store = new HashMap();
141
        this.store = new TreeMap();
144
        int keyCount = stream.readInt();
142
        int keyCount = stream.readInt();
145
        for (int i = 0; i < keyCount; i++) {
143
        for (int i = 0; i < keyCount; i++) {
146
            Comparable key = (Comparable) stream.readObject();
144
            Comparable key = (Comparable) stream.readObject();
147
            Paint paint = SerialUtilities.readPaint(stream);
145
            Stroke stroke = SerialUtilities.readStroke(stream);
148
            this.store.put(key, paint)
146
            this.store.put(key, stroke)
Summary
Number of common nesting structure subtrees0
Number of refactorable cases0
Number of non-refactorable cases0
Time elapsed for finding largest common nesting structure subtrees (ms)0.0
Clones location
Number of node comparisons0