com.github.jgility.core.project.Product.java Source code

Java tutorial

Introduction

Here is the source code for com.github.jgility.core.project.Product.java

Source

/*
 * 
 * Copyright (c) 2011 by Jgility Development Group
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Karsten Schulz
 *
 */
package com.github.jgility.core.project;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import com.github.jgility.core.planning.Backlog;
import com.github.jgility.core.requirement.IProductRequirement;

/**
 * Klasse, welche das Produkt im Sinne der agilen Softwareentwicklung reprsentiert. Beinhaltet
 * Informationen ber den ProductOwner in Form einer {@link Person}-Referenz. Zustzlich beinhaltet
 * dieser auch den ProductBacklog in Form einer {@link Backlog}-Referenz
 * 
 * @author Karsten Schulz <lennylinux.ks@googlemail.com>
 */
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Product {
    private String name;

    private String description;

    private final Set<Project> projects;

    private Person productOwner;

    private Backlog<IProductRequirement> productBacklog;

    /**
     * Parameterloser Konstruktor um ein leeres {@link Product} zu instanziieren.<br>
     * Initialisierte Standard-Werte fr Name (<code>Default</code>), Beschreibung (
     * <code>Default</code>) und ein Standard-{@link Person}
     * 
     * @see Person#Person()
     */
    public Product() {
        this("Default", "Default", new Person());
    }

    /**
     * Instanziiert ein leeres {@link Product} mit Namen, Beschreibung und ProductOwner
     * 
     * @param name Name des {@link Product}
     * @param description Beschreibung des {@link Product}
     * @param productOwner ProductOwner in Form einer {@link Person}
     * @throws IllegalArgumentException wird geworfen, wenn der Name oder der ProductOwner invalide
     *             Werte beinhaltet
     * @see #setName(String)
     * @see #setProductOwner(Person)
     */
    public Product(String name, String description, Person productOwner) throws IllegalArgumentException {
        super();
        setName(name);
        setDescription(description);
        setProductOwner(productOwner);
        productBacklog = new Backlog<>();
        projects = new HashSet<>();
    }

    /**
     * Gibt den Namen des {@link Product} zurck
     * 
     * @return Name des {@link Product}
     */
    public String getName() {
        return name;
    }

    /**
     * Setzt den Namen des {@link Product}
     * 
     * @param name Name des {@link Product}
     * @throws IllegalArgumentException wird geworfen, wenn der Name leer ist
     */
    public void setName(String name) throws IllegalArgumentException {
        if (StringUtils.isNotBlank(name)) {
            this.name = name;
        } else {
            throw new IllegalArgumentException("empty name for products is not allowed");
        }
    }

    /**
     * Gibt die Beschreibung des {@link Product} zurck
     * 
     * @return die Beschreibung des {@link Product}
     */
    public String getDescription() {
        return description;
    }

    /**
     * Setzt die Beschreibung des {@link Product}
     * 
     * @param description Beschreibung des {@link Product}
     */
    public void setDescription(String description) {
        this.description = description;
    }

    /**
     * Gibt eine nicht modifizierbare {@link List} mit {@link Project}-Referenzen zurck
     * 
     * @return eine {@link List} mit allen {@link Project}
     */
    public List<Project> getProjects() {
        final List<Project> projectList = new ArrayList<>(projects);
        return Collections.unmodifiableList(projectList);
    }

    /**
     * Fgt eine {@link List} von {@link Project} der bestehenden {@link List} hinzu
     * 
     * @param projects {@link List} mit {@link Project} welche hinzugefgt werden sollen
     * @throws IllegalArgumentException wird geworfen, wenn die bergebene {@link List} mit
     *             {@link Project} leer oder <code>null</code>
     */
    public void setProjects(List<Project> projects) throws IllegalArgumentException {
        if (CollectionUtils.isNotEmpty(projects)) {
            this.projects.addAll(projects);
        } else {
            throw new IllegalArgumentException("empty list of projects is not allowed to add");
        }
    }

    /**
     * Fgt ein neues {@link Project} der {@link List} hinzu
     * 
     * @param newProject neues {@link Project} zum Hinzufgen
     * @throws IllegalArgumentException wird geworfen, wenn das {@link Project} den Wert
     *             <code>null</code> beinhaltet
     */
    public void addProject(Project newProject) throws IllegalArgumentException {
        if (ObjectUtils.notEqual(null, newProject)) {
            this.projects.add(newProject);
        } else {
            throw new IllegalArgumentException("null-object as project is not allowed");
        }
    }

    /**
     * Entfernt ein {@link Project} aus der {@link List}
     * 
     * @param removeProject {@link Project} welches entfernt wird
     * @return <code>ture</code> wenn das bergebene {@link Project} aus der {@link List} entfernt
     *         wurde
     */
    public boolean removeProject(Project removeProject) {
        if (ObjectUtils.notEqual(null, removeProject)) {
            return projects.remove(removeProject);
        }
        return false;
    }

    /**
     * Entfernt alle in der {@link List} befindlichen {@link Project}s
     */
    public void clearProject() {
        projects.clear();
    }

    /**
     * Gibt den ProductOwner in Form einer {@link Person}-Referenz zurck
     * 
     * @return the productOwner
     */
    public Person getProductOwner() {
        return productOwner;
    }

    /**
     * Setzt den ProductOwner als {@link Person}
     * 
     * @param productOwner ProductOwner des {@link Product} als {@link Person}
     * @throws IllegalArgumentException wird geworfen, wenn der ProductOwner bereits initialisiert
     *             wurde oder der bergebende ProductOwner den Wert <code>null</code> beinhaltet
     * @see #removeProductOwner()
     */
    public void setProductOwner(Person productOwner) throws IllegalArgumentException {
        if (ObjectUtils.notEqual(null, this.productOwner)) {
            throw new IllegalArgumentException("productowner is already initialize: " + this.productBacklog);
        }
        if (ObjectUtils.notEqual(null, productOwner)) {
            this.productOwner = productOwner;
        } else {
            throw new IllegalArgumentException("null person is not allowed as productowner");
        }
    }

    /**
     * Entfernt den ProductOwner
     */
    public void removeProductOwner() {
        productOwner = null;
    }

    /**
     * Gibt den ProductBacklog in Form einer {@link Backlog}-Referenz zurck
     * 
     * @return der ProductBacklog als {@link Backlog}
     */
    public Backlog<IProductRequirement> getProductBacklog() {
        return productBacklog;
    }

    /**
     * Setzt den ProductBacklog
     * 
     * @param productBacklog zu setzenden {@link Backlog}
     * @throws IllegalArgumentException wird geworfen, wenn der productBacklog bereits initialisiert
     *             wurde oder das bergebende {@link Backlog} <code>null</code> beinhaltet
     * @see #removeProductBacklog()
     */
    public void setProductBacklog(Backlog<IProductRequirement> productBacklog) throws IllegalArgumentException {
        if (ObjectUtils.notEqual(null, this.productBacklog)) {
            throw new IllegalArgumentException("productbacklog is already initialize");
        } else if (ObjectUtils.notEqual(null, productBacklog)) {
            this.productBacklog = productBacklog;
        } else {
            throw new IllegalArgumentException("null backlog is not allowed as productbacklog");
        }
    }

    /**
     * Entfernt den ProductBacklog
     */
    public void removeProductBacklog() {
        productBacklog = null;
    }

    /*
     * (non-Javadoc)
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode() {
        HashCodeBuilder builder = new HashCodeBuilder();
        builder.append(name);
        builder.append(description);
        builder.append(productBacklog);
        builder.append(productOwner);
        builder.append(projects);

        return builder.toHashCode();
    }

    /*
     * (non-Javadoc)
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(Object obj) {
        if (obj instanceof Product) {
            Product product = (Product) obj;
            EqualsBuilder builder = new EqualsBuilder();
            builder.append(description, product.description);
            builder.append(name, product.name);
            builder.append(productBacklog, product.productBacklog);
            builder.append(productOwner, product.productOwner);
            builder.append(projects, product.projects);
            return builder.isEquals();
        }
        return false;
    }

    /*
     * (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        return "Product [name=" + name + ", description=" + description + ", projects=" + projects
                + ", productOwner=" + productOwner + ", productBacklog=" + productBacklog + "]";
    }

}