コード例 #1
0
        public override Status <IReadOnlyList <ICitizen> > Find(ICitizen citizen)
        {
            var status = IsValid(citizen);

            if (status.IsValid == false)
            {
                return(new Status <IReadOnlyList <ICitizen> >
                {
                    IsValid = false,
                    Message = status.Message
                });
            }

            var cousins = new List <ICitizen>();

            var fathersSiblings = _searchSiblings.Find(citizen.Father);

            if (fathersSiblings.IsValid)
            {
                fathersSiblings.Data.ToList().ForEach(x =>
                {
                    var children = _searchChildren.Find(x);
                    if (children.IsValid)
                    {
                        cousins.AddRange(children.Data);
                    }
                });
            }

            var mothersSiblings = new SearchSiblings().Find(citizen.Mother);

            if (mothersSiblings.IsValid)
            {
                var searchChildren = new SearchChildren();
                mothersSiblings.Data.ToList().ForEach(x =>
                {
                    var children = searchChildren.Find(x);
                    if (children.IsValid)
                    {
                        cousins.AddRange(children.Data);
                    }
                });
            }

            if (cousins.Any())
            {
                return(new Status <IReadOnlyList <ICitizen> >
                {
                    IsValid = true,
                    Data = new ReadOnlyCollection <ICitizen>(cousins)
                });
            }

            return(new Status <IReadOnlyList <ICitizen> >
            {
                IsValid = false,
                Message = "There are no cousins"
            });
        }
コード例 #2
0
 public SearchCousins(SearchSiblings searchSiblings, SearchChildren searchChildren)
 {
     _searchSiblings = searchSiblings;
     _searchChildren = searchChildren;
 }