Exemple #1
0
 // Constructor.
 public EnumerableAdapter(IIterable <T> e)
 {
     if (e == null)
     {
         throw new ArgumentNullException("e");
     }
     this.e = e;
 }
Exemple #2
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public IterableWrapper(IIterable <T> iterable)
 {
     if (iterable == null)
     {
         throw new ArgumentNullException("iterable");
     }
     this.iterable = iterable;
 }
Exemple #3
0
        public static Promise race(IIterable promises)
        {
            if (promises == null)
            {
                return(new Promise(fromException(new JSException(new TypeError("Invalid argruments for Promise.race(...)")))));
            }

            return(new Promise(whenAny(promises.AsEnumerable().Select(convertToTask).ToArray()).ContinueWith(x => x.Result.Result)));
        }
 internal MergeJoinIterable(
     MergeJoinIterator.KeyComparer keyComparer,
     IIterable <byte[], byte[]> left,
     IIterable <byte[], byte[]> right)
 {
     this.keyComparer = keyComparer;
     this.left        = left;
     this.right       = right;
 }
Exemple #5
0
 public void DrawLine(IIterable points, int width = 7, int color = Resource.Color.dark_gray, int zindex = 1)
 {
     _map.AddPolyline(
         new PolylineOptions().AddAll(points)
         .InvokeColor(color)
         .InvokeWidth(width)
         .InvokeColor(color)
         .InvokeZIndex(zindex));
 }
Exemple #6
0
        public static Promise all(IIterable promises)
        {
            if (promises == null)
            {
                return(new Promise(fromException(new JSException(new TypeError("Invalid argruments for Promise.all(...)")))));
            }

            return(new Promise(whenAll(promises.AsEnumerable().Select(convertToTask).ToArray()).ContinueWith(x => new Array(x.Result as IEnumerable) as JSValue)));
        }
Exemple #7
0
        /// <summary>
        /// Enqueues all passed waypoints to this steering group's existing waypoints (if any).
        /// Used in conjunction with portalling and switching over to a new group - the new group needs to have the same waypoints as the old one did.
        /// </summary>
        public void SetWaypoints(IIterable <Vector3> waypoints)
        {
            int count = waypoints.count;

            for (int i = 0; i < count; i++)
            {
                _wayPoints.Enqueue(waypoints[i]);
            }
        }
Exemple #8
0
        public static IEnumerable <T> AsEnumerable <T>(this IIterable <T> list)
        {
            var listE = list as IEnumerable <T>;

            if (listE != null)
            {
                return(listE);
            }
            return(AsEnumerableCore(list));
        }
 static void WriteToFile(string path, IIterable <int> iterator)
 {
     using (StreamWriter file = new StreamWriter(path))
     {
         while (iterator.HasNext())
         {
             file.WriteLine(iterator.Next().ToString());
         }
     }
 }
Exemple #10
0
        public static int CopyTo <T>(this IIterable <T> c, T[] array, int arrayIndex)
        {
            bool ended = false;
            var  it    = c.GetIterator();

            for (T current = it(ref ended); !ended; current = it(ref ended))
            {
                array[arrayIndex++] = current;
            }
            return(arrayIndex);
        }
Exemple #11
0
    public ScriptedDialogueDisplayer(string[] dialogue, Speaker speaker, IIterable conversation)
    {
        this.speaker      = speaker;
        this.conversation = conversation;

        foreach (string sentence in dialogue)
        {
            dialogueQueue.Enqueue(sentence);
        }

        Display();
    }
Exemple #12
0
 public static IIterable <TResult> UpCast <T, TResult>(this IIterable <T> source) where T : class, TResult
 {
                 #if DotNet4
     return(source);
                 #else
     if (source == null)
     {
         return(null);
     }
     return(new UpCastSource <T, TResult>(source));
                 #endif
 }
Exemple #13
0
        public static IEnumerable <KeyValuePair <Tuple <TK1, TK2>, Tuple <TV1, TV2> > > Join <TK1, TV1, TK2, TV2>(
            this IIterable <TK1, TV1> e1,
            IIterable <TK2, TV2> e2,
            Func <TK1, TK2, int> compare)
        {
            using var it1 = e1.GetIterator();
            using var it2 = e2.GetIterator();

            if (!it1.MoveNext() || !it2.MoveNext())
            {
                yield break;
            }

            KeyValuePair <TK1, TV1> kv1 = it1.Current;
            KeyValuePair <TK2, TV2> kv2 = it2.Current;

            while (true)
            {
                int comparison = compare(kv1.Key, kv2.Key);
                if (comparison == 0)
                {
                    // kv1 == kv2
                    yield return(new KeyValuePair <Tuple <TK1, TK2>, Tuple <TV1, TV2> >(
                                     Tuple.Create(kv1.Key, kv2.Key),
                                     Tuple.Create(kv1.Value, kv2.Value)));

                    if (!it2.MoveNext())
                    {
                        yield break;
                    }
                    kv2 = it2.Current;
                }
                else if (comparison < 0)
                {
                    // kv1 < kv2
                    if (!it1.MoveNext())
                    {
                        yield break;
                    }
                    kv1 = it1.Current;
                }
                else if (comparison > 0)
                {
                    // kv1 > kv2
                    if (!it2.MoveNext())
                    {
                        yield break;
                    }
                    kv2 = it2.Current;
                }
            }
        }
Exemple #14
0
        public void Visit(IIterable client)
        {
            int    v = client.Value;
            string s =
                string.Concat(
                    (v % 3 == 0) && (v % 5 != 0) ? "Fizz" : "",
                    (v % 3 != 0) && (v % 5 == 0) ? "Bang" : "",
                    (v % 3 == 0) && (v % 5 == 0) ? "FizzBang" : "",
                    (v % 3 != 0) && (v % 5 != 0) ? v.ToString() : ""
                    );

            Console.WriteLine(s);
        }
Exemple #15
0
        public Set(IIterable iterable)
            : this()
        {
            if (iterable == null)
            {
                return;
            }

            foreach (var value in iterable.AsEnumerable())
            {
                _storage.Add(value.Value);
            }
        }
Exemple #16
0
 public void PushLast(IIterable <T> items)
 {
     for (Iterator <T> it = items.GetIterator();;)
     {
         bool ended = false;
         T    item  = it(ref ended);
         if (ended)
         {
             break;
         }
         PushLast(item);
     }
 }
Exemple #17
0
        private static IEnumerable <T> AsEnumerableCore <T>(IIterable <T> list)
        {
            bool ended = false;

            for (var it = list.GetIterator();;)
            {
                T item = it(ref ended);
                if (ended)
                {
                    yield break;
                }
                yield return(item);
            }
        }
Exemple #18
0
        public static decimal?Sum(this IIterable <decimal?> source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            decimal sum = 0;

            source.ForEach(
                o => sum = sum + o ?? 0
                );

            return(sum);
        }
    public override IDialogueDisplayer Display(IIterable conversation, Speaker speaker)
    {
        int optionsCount = ValidOptions();

        string[]            optionsText = new string[optionsCount];
        UnityAction <int>[] onClicks    = new UnityAction <int> [optionsCount];

        for (int i = 0; i < optionsCount; i++)
        {
            optionsText[i] = options[i].dialogue;
            onClicks[i]    = OptionSelected;
        }

        return(new OptionsDialogueDisplayer(optionsText, onClicks, speaker));
    }
Exemple #20
0
        /// <summary>Determines whether the source contains a specific value.</summary>
        /// <returns>true if an element that equals 'item' was found, false otherwise.</returns>
        /// <remarks>
        /// Contains() was originally a member of the ISource(T) interface, just in
        /// case the source had some kind of fast lookup logic. However, this is
        /// not allowed in C# 4 when T is marked as "out" (covariant), so Contains()
        /// must be an extension method.
        /// </remarks>
        public static bool Contains <T>(this IIterable <T> list, T item)
        {
            EqualityComparer <T> comparer = EqualityComparer <T> .Default;
            bool ended = false;
            var  it    = list.GetIterator();

            for (T current = it(ref ended); !ended; current = it(ref ended))
            {
                if (comparer.Equals(item, current))
                {
                    return(true);
                }
            }
            return(false);
        }
Exemple #21
0
        public static IIterable <decimal?> SumMany(this IIterable <decimal?> source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            var linkIterable = source as ILinkIterable <decimal?>;

            if (linkIterable != null)
            {
                return(linkIterable.Sum());
            }
            return(new LinkIterable <decimal?, decimal?>(source, Iterator.Sum(default(IIteratorLink <decimal?, decimal?>))));
        }
Exemple #22
0
        public static long?Sum(this IIterable <long?> source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            long sum = 0;

            source.ForEach(
                o => sum = checked (sum + o ?? 0)
                );

            return(sum);
        }
Exemple #23
0
        public static double Sum(this IIterable <double> source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            double sum = 0;

            source.ForEach(
                o => sum = sum + o
                );

            return(sum);
        }
Exemple #24
0
        public static int Sum(this IIterable <int> source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            int sum = 0;

            source.ForEach(
                o => sum = checked (sum + o)
                );

            return(sum);
        }
Exemple #25
0
        public void Snapshot()
        {
            using var log = Log();
            using LevelDB.DB <string, string> db = GetTestDb();
            IIterable <string, string> it        = db.GetIterable().Snapshot();

            db.Delete("a").Delete("c").Delete("m").Delete("n");
            Assert.Equal(
                "a=1;b=2;c=3;l=12;m=13;n=14;x=24;y=25;z=26",
                string.Join(";", it.Select(kv => $"{kv.Key}={kv.Value}")));
            it.Snapshot();
            Assert.Equal(
                "b=2;l=12;x=24;y=25;z=26",
                string.Join(";", it.Select(kv => $"{kv.Key}={kv.Value}")));
        }
        public void OnGpsStatusChanged(GpsEvent e)
        {
            GpsStatus gpsStatus = locationManager.GetGpsStatus(null);

            if (gpsStatus != null)
            {
                IIterable satellites  = gpsStatus.Satellites;
                IIterator sat         = satellites.Iterator();
                string    lSatellites = null;
                int       i           = 0;
                while (sat.HasNext)
                {
                    GpsSatellite satellite = sat.Next().JavaCast <GpsSatellite>();
                    Debug.WriteLine(satellite.Prn);
                }
            }
        }
Exemple #27
0
        /// <summary>
        /// Copy ctor
        /// </summary>
        public List(IIterable <T> source)
        {
            var colSource = source as Java.Util.ICollection <T>;

            if (colSource != null)
            {
                list = new ArrayList <T>(colSource);
            }
            else
            {
                list = new ArrayList <T>();
                foreach (var item in source.AsEnumerable())
                {
                    list.Add(item);
                }
            }
        }
Exemple #28
0
        public static IEnumerable <JSValue> AsEnumerable(this IIterable iterableObject)
        {
            var iterator = iterableObject.iterator();

            if (iterator == null)
            {
                yield break;
            }

            var item = iterator.next();

            while (!item.done)
            {
                yield return(item.value);

                item = iterator.next();
            }
        }
Exemple #29
0
        public Map(IIterable iterable)
            : this()
        {
            if (iterable == null)
            {
                return;
            }

            foreach (var item in iterable.AsEnumerable())
            {
                if (item._valueType < JSValueType.Object)
                {
                    ExceptionHelper.ThrowTypeError($"Iterator value {item} is not an entry object");
                }

                var value = item["1"];
                _storage[item["0"].Value] = value.Value as JSValue ?? value;
            }
        }
        public static void BubbleSort(int[] array, IComparer comparator, IIterable iterator)
        {
            bool isSort = true;

            while (isSort)
            {
                isSort = false;
                for (int current = iterator.GetStart(); !iterator.IsEnd(); current = iterator.GetCurrent())
                {
                    int next = iterator.GetNext();
                    if (comparator.Compare(array[current], array[next]) > 0)
                    {
                        Swap(ref array[current], ref array[next]);
                        isSort = true;
                    }
                    iterator.Next();
                }
            }
        }
 /// <summary>
 /// Enqueues all passed waypoints to this steering group's existing waypoints (if any).
 /// Used in conjunction with portalling and switching over to a new group - the new group needs to have the same waypoints as the old one did.
 /// </summary>
 public void SetWaypoints(IIterable<Vector3> waypoints)
 {
     int count = waypoints.count;
     for (int i = 0; i < count; i++)
     {
         _wayPoints.Enqueue(waypoints[i]);
     }
 }
        /// <summary>
        /// Avoids the specified units.
        /// </summary>
        /// <param name="units">The units list.</param>
        /// <param name="unitsLength">Length of the units list.</param>
        /// <param name="currentVelocity">This unit's current velocity.</param>
        /// <returns>An avoid vector, if there are any to avoid, otherwise Vector3.zero.</returns>
        private Vector3 Avoid(IIterable<IUnitFacade> units, int unitsLength, Vector3 currentVelocity)
        {
            Vector3 selfPos = _unitData.position;
            Vector3 normalVelocity = currentVelocity.normalized;
            Vector3 combinedAvoidVector = Vector3.zero;

            // iterate through scanned units list
            for (int i = 0; i < unitsLength; i++)
            {
                var other = units[i];
                if (!other.isAlive)
                {
                    continue;
                }

                if ((_ignoredUnits & other.attributes) > 0)
                {
                    // other unit is found in the ignored attributes, so ignore it
                    continue;
                }

                if (_unitData.transientGroup != null && object.ReferenceEquals(other.transientGroup, _unitData.transientGroup))
                {
                    // ignore units in same transient unit group
                    continue;
                }

                if (other.determination < _unitData.determination)
                {
                    // ignore units with lower determination
                    continue;
                }

                Vector3 otherPos = other.position;
                Vector3 direction = otherPos.DirToXZ(selfPos);
                float distance = direction.magnitude;
                if (distance > _omniAwareRadius && Vector3.Dot(normalVelocity, direction / distance) > _fovReverseAngleCos)
                {
                    // the other unit is behind me and outside my 'omni aware radius', ignore it
                    continue;
                }

                float combinedRadius = _unitData.radius + other.radius + radiusMargin;
                Vector3 otherVelocity = other.velocity;
                Vector3 avoidVector = GetAvoidVector(selfPos, currentVelocity, normalVelocity, _unitData, otherPos, otherVelocity, other, combinedRadius);
                if (accumulateAvoidVectors)
                {
                    // if accumulating, then keep summing avoid vectors up
                    combinedAvoidVector += avoidVector;
                }
                else
                {
                    // if not accumulating, then break after the first avoid vector is found
                    combinedAvoidVector = avoidVector;
                    break;
                }
            }

            return combinedAvoidVector;
        }