Example #1
0
 /// <summary>
 /// Gets or sets the value associated with the specified key.
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public TValue this[TKey key]
 {
     get
     {
         if (map.ContainsKey(key))
         {
             return(map.Get(key));
         }
         throw new KeyNotFoundException();
     }
     set { map.Put(key, value); }
 }
Example #2
0
 /// <summary>Is logging enabled for given tag / loglevel combo?</summary>
 /// <param name="tag">
 /// Used to identify the source of a log message.  It usually identifies
 /// the class or activity where the log call occurs.
 /// </param>
 /// <param name="logLevel">
 /// The loglevel to check whether it's enabled.  Will match this loglevel
 /// or a more urgent loglevel.  Eg, if Log.ERROR is enabled and Log.VERBOSE
 /// is passed as a paremeter, it will return true.
 /// </param>
 /// <returns>boolean indicating whether logging is enabled.</returns>
 internal static bool IsLoggingEnabled(string tag, int logLevel)
 {
     // this hashmap lookup might be a little expensive, and so it might make
     // sense to convert this over to a CopyOnWriteArrayList
     if (enabledTags.ContainsKey(tag))
     {
         int logLevelForTag = enabledTags.Get(tag);
         return(logLevel >= logLevelForTag);
     }
     return(false);
 }
        public virtual void AddCookie(Apache.Http.Cookie.Cookie cookie)
        {
            if (omitNonPersistentCookies && !cookie.IsPersistent())
            {
                return;
            }
            string name = cookie.GetName() + cookie.GetDomain();

            // Do we already have this cookie?  If so, don't bother.
            if (cookies.ContainsKey(name) && cookies.Get(name).Equals(cookie))
            {
                return;
            }
            // Save cookie into local store, or remove if expired
            if (!cookie.IsExpired(new DateTime()))
            {
                cookies.Put(name, cookie);
            }
            else
            {
                Sharpen.Collections.Remove(cookies, name);
            }
            string encodedCookie = EncodeCookie(new SerializableCookie(cookie));
            IDictionary <string, object> cookiesDoc = GetDb().GetExistingLocalDocument(CookieLocalDocName
                                                                                       );

            if (cookiesDoc == null)
            {
                cookiesDoc = new Dictionary <string, object>();
            }
            Log.V(Log.TagSync, "Saving cookie: %s w/ encoded value: %s", name, encodedCookie);
            cookiesDoc.Put(name, encodedCookie);
            try
            {
                GetDb().PutLocalDocument(CookieLocalDocName, cookiesDoc);
            }
            catch (CouchbaseLiteException e)
            {
                Log.E(Log.TagSync, "Exception saving local doc", e);
                throw new RuntimeException(e);
            }
        }
 public void TestContainsKey_NullReferenceException()
 {
     try
     {
         ConcurrentHashMap<Object, Object> c = new ConcurrentHashMap<Object, Object>(5);
         c.ContainsKey(null);
         ShouldThrow();
     }
     catch(NullReferenceException)
     {
     }
 }
 public void TestPutAll()
 {
     ConcurrentHashMap<Object, Object> empty = new ConcurrentHashMap<Object, Object>();
     ConcurrentHashMap<Object, Object> map = map5();
     empty.PutAll(map);
     Assert.AreEqual(5, empty.Size());
     Assert.IsTrue(empty.ContainsKey(one));
     Assert.IsTrue(empty.ContainsKey(two));
     Assert.IsTrue(empty.ContainsKey(three));
     Assert.IsTrue(empty.ContainsKey(four));
     Assert.IsTrue(empty.ContainsKey(five));
 }