All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.deephacks.tools4j.config.examples.family.Marriage Maven / Gradle / Ivy

There is a newer version: 0.15.0
Show newest version
/**
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.deephacks.tools4j.config.examples.family;

import java.util.ArrayList;
import java.util.List;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.deephacks.tools4j.config.Config;
import org.deephacks.tools4j.config.Id;

/**
 * A recursive example of a family tree. 
 * 
 * See the parent-child.png for an illustration of the potential realtionship 
 * between marriage and persons.
 */
@Config(desc = "A marriage between two people.", name = "Marriage")
@MarriageConstraint
@SuppressWarnings("unused")
public class Marriage {
    @Id(desc = "a marriage")
    private String id;

    @Config(desc = "Two married people.")
    @Size(min = 2, max = 2)
    @NotNull
    private List couple = new ArrayList();

    @Config(desc = "Children from this marriage.")
    private List children = new ArrayList();

    public List getCouple() {
        return couple;
    }

    public List getChildren() {
        return children;
    }

    public Person getMale() {
        for (Person p : couple) {
            if (p.gender == Gender.MALE) {
                return p;
            }
        }
        return null;
    }

    public Person getFemale() {
        for (Person p : couple) {
            if (p.gender == Gender.FEMALE) {
                return p;
            }
        }
        return null;
    }

    @Override
    public String toString() {
        if (couple == null) {
            couple = new ArrayList();
        }
        if (children == null) {
            children = new ArrayList();
        }
        return "Marriage between " + couple.get(0) + " and " + couple.get(1) + " with children "
                + children;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy