Commit 9a374c6f authored by Matej Kovár's avatar Matej Kovár
Browse files

merged primaryFace and secondaryFaces to just one attribute, models

parent 813aeb3e
Loading
Loading
Loading
Loading
+35 −24
Original line number Diff line number Diff line
@@ -13,14 +13,15 @@ import java.util.List;
 */
public class Project {
    
    private HumanFace primaryFace;
    private List<HumanFace> secondaryFaces = new ArrayList<>();
    //private HumanFace primaryFace;
    private List<HumanFace> models = new ArrayList<>();
    
    
    /**
     * Returns primary face
     * 
     * @return HumanFace primary face 
     */
     
    public HumanFace getPrimaryFace() {
        return primaryFace;
    }
@@ -30,7 +31,7 @@ public class Project {
     * 
     * @param primaryFace which will be new primary face
     * @throws IllegalArgumentException when argument primaryFace is null
     */
     
    public void setPrimaryFace(HumanFace primaryFace) {
        if (primaryFace == null) {
            throw new IllegalArgumentException("Primary face is null");
@@ -40,18 +41,19 @@ public class Project {
    
    /**
     * Removes primary face and sets primaryFace attribute to null
     */
     
    public void removePrimaryFace() {
        this.primaryFace = null;
    }
    }*/


    /**
     * Returns list of HumanFace secondary faces
     * 
     * @return list of secondary faces
     */
    public List<HumanFace> getSecondaryFaces() {
        return Collections.unmodifiableList(secondaryFaces);
    public List<HumanFace> getFaces() {
        return Collections.unmodifiableList(models);
    }

    /**
@@ -61,60 +63,69 @@ public class Project {
     * secondary faces
     * @throws IllegalArgumentException if one of faces from argument is null
     */
    public void setSecondaryFaces(List<HumanFace> secondaryFaces) {
        this.secondaryFaces.clear();
    public void setFaces(List<HumanFace> secondaryFaces) {
        this.models.clear();
        for (int i = 0; i < secondaryFaces.size(); i++) {
            if (secondaryFaces.get(i) == null) {
                throw new IllegalArgumentException("One of faces is null");
            }
        }
        this.secondaryFaces.addAll(secondaryFaces);
        this.models.addAll(secondaryFaces);
    }
    
    /**
     * Adds new face to secondaryFaces
     * Adds new face to models
     * 
     * @param face HumanFace which will be added to list of secondary faces
     * @throws IllegalArgumentException when argument face is null
     */
    public void addSecondaryFace(HumanFace face) {
    public void addFace(HumanFace face) {
        if (face == null) {
            throw new IllegalArgumentException("Face is null");
        }
        this.secondaryFaces.add(face);
        this.models.add(face);
    }
    
    /**
     * Removes HumanFace from secondaryFaces
     * Removes HumanFace from models
     * 
     * @param face HumanFace which will be removed from secondaryFaces
     * @param face HumanFace which will be removed from models
     * @throws IllegalArgumentException when argument face is null
     */
    public void removeSecondaryFace(HumanFace face) {
    public void removeFace(HumanFace face) {
        if (face == null) {
            throw new IllegalArgumentException("Face is null");
        }
        
        for (int i = 0; i < secondaryFaces.size(); i++) {
            if (secondaryFaces.get(i).equals(face)) {
                secondaryFaces.remove(i);
        for (int i = 0; i < models.size(); i++) {
            if (models.get(i).equals(face)) {
                models.remove(i);
            }
        } 
    }
    
    /**
     * Removes faces which are sent to this function by list of HumanFace
     * from secondaryFaces
     * from models
     * 
     * @param faces List of HumanFace faces which should be removed from
     * secondaryFaces
     *   models
     */
    public void removeSelected(List<HumanFace> faces) {
        for (int i = 0; i < faces.size(); i++) {
            this.removeSecondaryFace(faces.get(i));
            this.removeFace(faces.get(i));
        }
    }
    
    public HumanFace getFaceByName(String name) {
        for (HumanFace face : models) {
            if (face.getShortName().equals(name)) {
                return face;
            }
        }
        return null;
    }
    
    /* TODO implement comparable and create comparators for filtering
    secondaryFaces */
    models */
}