コード例 #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldPutAndRetrieve()
        internal virtual void ShouldPutAndRetrieve()
        {
            // Given
            UsageData             ms  = new UsageData(mock(typeof(JobScheduler)));
            UsageDataKey <string> key = key("hello");

            // When
            ms.Set(key, "Hello!");

            // Then
            assertEquals("Hello!", ms.Get(key));
            assertNull(ms.Get(key("other")));
        }
コード例 #2
0
        public virtual T Get <T>(UsageDataKey <T> key)
        {
            object o = _store[key];

            if (o == null)
            {
                // When items are missing, if there is a default value, we do a get-or-create style operation
                // This allows outside actors to get-or-create rich objects and know they will get the same object out
                // that other threads would use, which is helpful when we store mutable objects
                T value = key.GenerateDefaultValue();
                if (value == default(T))
                {
                    return(default(T));
                }

                _store.GetOrAdd(key, value);
                return(Get(key));
            }
            return(( T )o);
        }
コード例 #3
0
 public virtual void Set <T>(UsageDataKey <T> key, T value)
 {
     _store[key] = value;
 }