<commit_before>// Copyright 2004-2007 Castle Project - http://www.castleproject.org/
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Castle.MicroKernel.SubSystems.Naming
{
	using System;
	using System.Collections;
	using System.Collections.Specialized;
	using System.Threading;

	/// <summary>
	/// Default <see cref="INamingSubSystem"/> implementation.
	/// Keeps services map as a simple hash table.
	/// Keeps key map as a list dictionary to maintain order.
	/// Does not support a query string.
	/// </summary>
	[Serializable]
	public class DefaultNamingSubSystem : AbstractSubSystem, INamingSubSystem
	{
		/// <summary>
		/// Map(String, IHandler) to map component keys
		/// to <see cref="IHandler"/>
		/// </summary>
		protected IDictionary key2Handler;

		/// <summary>
		/// Map(Type, IHandler) to map services 
		/// to <see cref="IHandler"/>
		/// </summary>
		protected IDictionary service2Handler;

		private readonly ReaderWriterLock locker = new ReaderWriterLock();

		/// <summary>
		/// Initializes a new instance of the <see cref="DefaultNamingSubSystem"/> class.
		/// </summary>
		public DefaultNamingSubSystem()
		{
			key2Handler = new ListDictionary();
			service2Handler = new ListDictionary();
		}

		#region INamingSubSystem Members

		public virtual void Register(String key, IHandler handler)
		{
			Type service = handler.ComponentModel.Service;

			try
			{
				locker.AcquireWriterLock(Timeout.Infinite);
				if (key2Handler.Contains(key))
				{
					throw new ComponentRegistrationException(
						String.Format("There is a component already registered for the given key {0}", key));
				}<commit_msg>Reverting DefaultNamingSubSystem.service2Handler type back to hashtable.<commit_after>// Copyright 2004-2007 Castle Project - http://www.castleproject.org/
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Castle.MicroKernel.SubSystems.Naming
{
	using System;
	using System.Collections;
	using System.Collections.Specialized;
	using System.Threading;

	/// <summary>
	/// Default <see cref="INamingSubSystem"/> implementation.
	/// Keeps services map as a simple hash table.
	/// Keeps key map as a list dictionary to maintain order.
	/// Does not support a query string.
	/// </summary>
	[Serializable]
	public class DefaultNamingSubSystem : AbstractSubSystem, INamingSubSystem
	{
		/// <summary>
		/// Map(String, IHandler) to map component keys
		/// to <see cref="IHandler"/>
		/// Items in this dictionary are sorted in insertion order.
		/// </summary>
		protected IDictionary key2Handler;

		/// <summary>
		/// Map(Type, IHandler) to map a service
		/// to <see cref="IHandler"/>.
		/// If there is more than a single service of the type, only the first
		/// registered services is stored in this dictionary.
		/// It serve as a fast lookup for the common case of having a single handler for 
		/// a type.
		/// </summary>
		protected IDictionary service2Handler;

		private readonly ReaderWriterLock locker = new ReaderWriterLock();

		/// <summary>
		/// Initializes a new instance of the <see cref="DefaultNamingSubSystem"/> class.
		/// </summary>
		public DefaultNamingSubSystem()
		{
			key2Handler = new ListDictionary();
			service2Handler = new Hashtable();
		}

		#region INamingSubSystem Members

		public virtual void Register(String key, IHandler handler)
		{
			Type service = handler.ComponentModel.Service;

			try
			{
				locker.AcquireWriterLock(Timeout.Infinite);
				if (key2Handler.Contains(key))
				{
					throw new ComponentRegistrationException(
						String.Format("There is a component already registered for the given key {0}", key));
				}
{'fraction_non_alphanumeric': 0.1056247316444826, 'fraction_numerical': 0.00794332331472735, 'mean_word_length': 3.3582787652011223, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3754374', 'n_tokens_mistral': 1387, 'n_tokens_neox': 1239, 'n_words': 482}