Esempio n. 1
0
        /// <summary>
        /// Return a snapshot of the mapping from display names to visible
        /// IDs for this service.  This set will not change as factories
        /// are added or removed, but the supported ids will, so there is
        /// no guarantee that all and only the ids in the returned map will
        /// be visible and supported by the service in subsequent calls,
        /// nor is there any guarantee that the current display names match
        /// those in the set.  The display names are sorted based on the
        /// comparer provided.
        /// </summary>
        public virtual IDictionary <string, string> GetDisplayNames(UCultureInfo locale, IComparer <string> com, string matchID)
        {
            IDictionary <string, string> dncache = null;
            LocaleRef reference = dnref;

            if (reference != null)
            {
                dncache = reference.Get(locale, com);
            }

            while (dncache == null)
            {
                lock (syncLock)
                {
                    if (reference == dnref || dnref == null)
                    {
                        dncache = new SortedDictionary <string, string>(com); // sorted

                        foreach (var e in GetVisibleIDMap())
                        {
                            string          id = e.Key;
                            IServiceFactory f  = e.Value;
                            dncache[f.GetDisplayName(id, locale)] = id;
                        }

                        dncache = dncache.AsReadOnly();
                        dnref   = new LocaleRef(dncache, locale, com);
                    }
                    else
                    {
                        reference = dnref;
                        dncache   = reference.Get(locale, com);
                    }
                }
            }

            ICUServiceKey matchKey = CreateKey(matchID);

            if (matchKey == null)
            {
                return(dncache.AsReadOnly());
            }

            // ICU4N: Rather than copying and then removing the items (which isn't allowed with
            // .NET iterators), we reverse the logic and add the items only if they are fallback.
            IDictionary <string, string> result = new SortedDictionary <string, string>(com);

            foreach (var e in dncache)
            {
                if (matchKey.IsFallbackOf(e.Value))
                {
                    result.Add(e.Key, e.Value);
                }
            }
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Return a snapshot of the visible IDs for this service.  This
        /// set will not change as Factories are added or removed, but the
        /// supported ids will, so there is no guarantee that all and only
        /// the ids in the returned set are visible and supported by the
        /// service in subsequent calls.
        /// <para/>
        /// <paramref name="matchID"/> is passed to <see cref="CreateKey(string)"/> to create a key.  If the
        /// key is not null, it is used to filter out ids that don't have
        /// the key as a fallback.
        /// </summary>
        public virtual ICollection <string> GetVisibleIDs(string matchID) // ICU4N specific - changed return type from ISet to ICollection to avoid O(n)
        {
            ICollection <string> result = GetVisibleIDMap().Keys;

            ICUServiceKey fallbackKey = CreateKey(matchID);

            if (fallbackKey != null)
            {
                ISet <string> temp = new HashSet <string>(/*result.Count*/);
                foreach (string id in result)
                {
                    if (fallbackKey.IsFallbackOf(id))
                    {
                        temp.Add(id);
                    }
                }
                result = temp;
            }
            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// Return a snapshot of the visible IDs for this service.  This
        /// set will not change as Factories are added or removed, but the
        /// supported ids will, so there is no guarantee that all and only
        /// the ids in the returned set are visible and supported by the
        /// service in subsequent calls.
        /// <para/>
        /// <paramref name="matchID"/> is passed to <see cref="CreateKey(string)"/> to create a key.  If the
        /// key is not null, it is used to filter out ids that don't have
        /// the key as a fallback.
        /// </summary>
        public virtual ICollection <string> GetVisibleIDs(string matchID) // ICU4N specific - changed return type from ISet to ICollection to avoid O(n)
        {
            ICollection <string> result = GetVisibleIDMap().Keys;

            ICUServiceKey fallbackKey = CreateKey(matchID);

            if (fallbackKey != null)
            {
                // ICU4N: We don't need the overhead of HashSet here, since we are pulling
                // keys from a dictionary.
                var temp = new List <string>(result.Count);
                foreach (string id in result)
                {
                    if (fallbackKey.IsFallbackOf(id))
                    {
                        temp.Add(id);
                    }
                }
                result = temp;
            }
            return(result);
        }