Passed
Push — master ( 68adbd...94678b )
by Seth
03:18
created

Sprite()   A

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 2
rs 10
1
package org.gannacademy.cdf.graphics.curriculum;
2
3
import org.gannacademy.cdf.graphics.Drawable;
4
5
import java.util.List;
6
import java.util.Vector;
7
8
public class Sprite {
9
    private List<Drawable> components;
10
    
11
    public Sprite() {
12
        components = new Vector<>();
13
    }
14
15
    public void addComponent(Drawable component) {
16
        if (!components.contains(component)) {
17
            components.add(component);
18
        }
19
    }
20
21
    public boolean intersects(Sprite other) {
22
        for(Drawable component : components) {
23
            for (Drawable otherComponent : other.components) {
24
                if (component.intersects(otherComponent.getBounds())) {
25
                    return true;
26
                }
27
            }
28
        }
29
        return false;
30
    }
31
32
    public double getTop() {
33
        double top = Double.MAX_VALUE;
34
        for(Drawable component:components) {
35
            top = Math.min(top, component.getY());
36
        }
37
        if (top == Double.MAX_VALUE) {
38
            return Double.NaN;
39
        }
40
        return top;
41
    }
42
}
43