コード例 #1
0
        public void AddsAndGets()
        {
            map.Add(1, "1");
            map.Add(2, "2");

            AssertGets(1, "1");
            AssertGets(2, "2");
        }
コード例 #2
0
        public void Test4()
        {
            var d = new BidirectionalMap <int, int>();

            d.Add(new Tuple <int, int>(1, 5));
            d.Add(new Tuple <int, int>(2, 6));
            d.Add(new Tuple <int, int>(3, 7));

            Assert.ThrowsException <ItemsNotOneToOneException>(() =>
            {
                d.Add(new Tuple <int, int>(4, 7));
            });
        }
コード例 #3
0
        public void Test3()
        {
            var d = new BidirectionalMap <string, int>();

            d.Add(new Tuple <string, int>("Col1", 1));
            d.Add(new Tuple <string, int>("Col2", 2));
            d.Add(new Tuple <string, int>("Col3", 3));

            Assert.ThrowsException <ItemsNotOneToOneException>(() =>
            {
                d.Add(new Tuple <string, int>("Col3", 1));
            });
        }
コード例 #4
0
 public TimerTypes()
 {
     map.Add(RuntimeTypeId.Meditation, typeof(MeditationTimer));
     map.Add(RuntimeTypeId.MeditPath, typeof(MeditPathTimer));
     map.Add(RuntimeTypeId.Prayer, typeof(PrayerTimer));
     map.Add(RuntimeTypeId.Sermon, typeof(SermonTimer));
     map.Add(RuntimeTypeId.Alignment, typeof(AlignmentTimer));
     map.Add(RuntimeTypeId.JunkSale, typeof(JunkSaleTimer));
     map.Add(RuntimeTypeId.LegacyCustom, typeof(CustomTimer));
 }
コード例 #5
0
ファイル: IntVocabulary.cs プロジェクト: yazici/dpu-utils
 public int Get(T obj, bool addIfNotPresent = false)
 {
     if (!_dictionary.TryGetKey(obj, out int key))
     {
         if (!addIfNotPresent)
         {
             throw new Exception("Object not in vocabulary");
         }
         key = _nextId;
         _dictionary.Add(key, obj);
         _nextId++;
     }
     return(key);
 }
コード例 #6
0
    void UpdateRenderables <T>(
        List <T> renderables,
        GameObject newObject,
        List <GameObject> objectPool,
        BidirectionalMap <T, GameObject> renderableObjectMap,
        Transform uiContainer,
        System.Action <GameObject> onCreateCallback = null)
        where T : IRenderable
    {
        // Put all GameObjects in a set, and remove the objects that are still in used
        HashSet <GameObject> unusedObjects = new HashSet <GameObject>(renderableObjectMap.Values);

        foreach (T renderable in renderables)
        {
            GameObject uiObject;
            // Spawn new UI person
            if (!renderableObjectMap.ContainsKey(renderable))
            {
                if (objectPool.Count > 0)
                {
                    uiObject = objectPool[objectPool.Count - 1];
                    objectPool.RemoveAt(objectPool.Count - 1);
                    uiObject.SetActive(true);
                }
                else
                {
                    uiObject = Instantiate(newObject);
                }
                uiObject.transform.SetParent(uiContainer, false);
                renderableObjectMap.Add(renderable, uiObject);
                if (onCreateCallback != null)
                {
                    onCreateCallback(uiObject);
                }
            }
            else
            {
                uiObject = renderableObjectMap.GetValue(renderable);
                unusedObjects.Remove(uiObject);
            }
            renderable.RenderTo(uiObject);
        }
        foreach (GameObject uiObject in unusedObjects)
        {
            renderableObjectMap.RemoveValue(uiObject);
            objectPool.Add(uiObject);
            uiObject.SetActive(false);
            uiObject.transform.SetParent(null, false);
        }
    }
コード例 #7
0
        public void Test5()
        {
            var d = new BidirectionalMap <int, int>();

            d.Add(new Tuple <int, int>(1, 5));
            d.Add(new Tuple <int, int>(2, 6));
            d.Add(new Tuple <int, int>(3, 7));

            Assert.AreEqual(d.Count, 3);

            Assert.AreEqual(d.GetLeft(7), 3);
            Assert.AreEqual(d.GetRight(3), 7);

            Assert.ThrowsException <Exception>(() =>
            {
                var e = d.GetLeft(11);
            });

            Assert.ThrowsException <Exception>(() =>
            {
                var e = d.GetRight(11);
            });
        }
コード例 #8
0
        public void Test6()
        {
            var d = new BidirectionalMap <string, int>(new Dictionary <string, int>()
            {
                { "Col1", 1 },
                { "Col2", 2 },
                { "Col3", 3 }
            });

            Assert.AreEqual(d.Count, 3);

            Assert.AreEqual(d.GetLeft(1), "Col1");
            Assert.AreEqual(d.GetRight("Col3"), 3);

            Assert.ThrowsException <ItemsNotOneToOneException>(() =>
            {
                d.Add(new Tuple <string, int>("Col1", 3));
            });
        }