Exemplo n.º 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); }
 }
Exemplo n.º 2
0
 /// <summary>Obtains a scheme by name, if registered.</summary>
 /// <remarks>Obtains a scheme by name, if registered.</remarks>
 /// <param name="name">the name of the scheme to look up (in lowercase)</param>
 /// <returns>
 /// the scheme, or
 /// <code>null</code> if there is none by this name
 /// </returns>
 public Apache.Http.Conn.Scheme.Scheme Get(string name)
 {
     Args.NotNull(name, "Scheme name");
     // leave it to the caller to use the correct name - all lowercase
     //name = name.toLowerCase();
     Apache.Http.Conn.Scheme.Scheme found = registeredSchemes.Get(name);
     return(found);
 }
Exemplo n.º 3
0
 public void TestGet()
 {
     ConcurrentHashMap<Object, Object> map = map5();
     Assert.AreEqual("A", (String)map.Get(one));
     ConcurrentHashMap<Object, Object> empty = new ConcurrentHashMap<Object, Object>();
     Assert.IsNull(map.Get("anything"));
     Assert.IsNull(empty.Get("anything"));
 }
Exemplo n.º 4
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);
 }
Exemplo n.º 5
0
        public static EnumInfo GetEnumInfo(Type enumType)
        {
            var info = enumInfo.Get(enumType);

            if (info == null)
            {
                var infoField = enumType.JavaGetDeclaredField(EnumInfoFieldName);
                info = (EnumInfo)infoField.Get(null);
                enumInfo.Put(enumType, info);
            }

            return(info);
        }
Exemplo n.º 6
0
        internal static EventInfo[] GetEvents(Type definingType, Type declaringType)
        {
            var result = loadedEvents.Get(declaringType);

            if (result != null)
            {
                return(result);
            }

            // Not found, build it
            result = BuildEvents(definingType, declaringType);

            // Store in loaded map
            loadedEvents.Put(declaringType, result);

            return(result);
        }
Exemplo n.º 7
0
Arquivo: XMap.cs Projeto: slagusev/api
        /// <summary>
        /// Try to get an entry from the map.
        /// </summary>
        internal T TryGet(string key)
        {
            var entry = map.Get(key);

            if (entry == null)
            {
                return(default(T));
            }
            var result = entry.Get();

            if (result == null)
            {
                map.Remove(key, entry);
                return(null);
            }
            return(result);
        }
Exemplo n.º 8
0
        private T Get <T>() where T : TranslationBundle
        {
            System.Type       type   = typeof(T);
            TranslationBundle bundle = map.Get(type);

            if (bundle == null)
            {
                bundle = GlobalBundleCache.LookupBundle <T>(locale);
                // There is a small opportunity for a race, which we may
                // lose. Accept defeat and return the winner's instance.
                TranslationBundle old = map.PutIfAbsent(type, bundle);
                if (old != null)
                {
                    bundle = old;
                }
            }
            return((T)bundle);
        }
        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);
            }
        }
Exemplo n.º 10
0
 public void TestGetNullReferenceException()
 {
     try
     {
         ConcurrentHashMap<Object, Object> c = new ConcurrentHashMap<Object, Object>(5);
         c.Get(null);
         ShouldThrow();
     }
     catch(NullReferenceException)
     {
     }
 }