Example #1
0
        public static (IEnumerable <IEnumerable <FlightSegment> > OJ, IEnumerable <FlightSegment> Other) AllOpenJaws(this FlightQuery flightQuery)
        {
            var allOpenJaws = AllOpenJawsInternal(flightQuery);

            var allOpenJawsFlatten = allOpenJaws.SelectMany(x => x);
            IEnumerable <FlightSegment> allSegments = flightQuery.FlightSegments;

            return(allOpenJaws, allSegments.Except(allOpenJawsFlatten));
        }
Example #2
0
        private static IEnumerable <IEnumerable <FlightSegment> > AllOpenJawsInternal(this FlightQuery flightQuery)
        {
            var head = flightQuery.FlightSegments.First();
            var tail = flightQuery.FlightSegments.Skip(1).ToList();

            if (tail.Count() >= 1)
            {
                // Modify this part to change the logic for the OpenJaw
                var openJaw = tail.Where(elem => elem.Destination == head.Origin && elem.Departure > head.Departure).ToList();
                if (openJaw.Any())
                {
                    var theRest = tail.Except(openJaw).ToList();
                    return(new[] { openJaw.Prepend(head) }.Concat(
                               theRest.Any()
                            ? new FlightQuery {
                        FlightSegments = theRest.ToArray()
                    }.AllOpenJawsInternal()
                            : new List <IEnumerable <FlightSegment> >().ToArray()));
                }
                else
                {
                    return(new FlightQuery {
                        FlightSegments = tail.ToArray()
                    }.AllOpenJawsInternal());
                }
            }

            return(new List <IEnumerable <FlightSegment> >().ToArray());
        }