<commit_before>using System;
using System.Collections;
using System.Data;

using NHibernate.Engine;
using NHibernate.Type;

namespace NHibernate.Collection
{
	/// <summary>
	/// Summary description for Bag.
	/// </summary>
	public class Bag : ODMGCollection, IList
	{
		private IList bag;
		// used to hold the Identifiers of the Elements that will later
		// be moved to the bag field.
		private IList bagIdentifiers;

		public Bag(ISessionImplementor session) : base(session)
		{
		}

		public Bag(ISessionImplementor session, ICollection coll) : base(session) 
		{
			bag = coll as IList;
			
			if(bag == null) 
			{
				bag = new ArrayList();
				((ArrayList)bag).AddRange(coll);
			}

			initialized = true;
			directlyAccessible = true;
		}

		public Bag(ISessionImplementor session, CollectionPersister persister, object disassembled, object owner) : base(session)
		{
			BeforeInitialize(persister);
			object[] array = (object[])disassembled;
			for(int i=0; i<array.Length; i++) 
			{
				bag.Add(persister.ElementType.Assemble(array[i], session, owner));
			}
			initialized = true;
		}

		public override ICollection Elements()
		{
			return bag;
		}

		public override bool Empty
		{
			get{ return bag.Count==0;}
		}

		public override ICollection Entries()
		{
			return bag;
		}

		public override void EndRead(CollectionPersister persister, object owner)
		{
			for(int i = 0 ;i < bagIdentifiers.Count; i++) 
			{
				object element = persister.ElementType.ResolveIdentifier(bagIdentifiers[i], session, owner);
				bag[i] = element;
			}
		}

		public override object ReadFrom(IDataReader reader, CollectionPersister persister, object owner)
		{
			object elementIdentifier = persister.ReadElementIdentifier(reader, owner, session);
			int index = (int) persister.ReadIndex(reader, session);
			for (int i=bag.Count; i<=index; i++) 
			{
				bag.Insert(i, null);
				bagIdentifiers.Insert(i , null);
			}
			bagIdentifiers[index] = elementIdentifier;
			return elementIdentifier;
		}

		[Obsolete("See PersistentCollection.ReadEntries for reason")]
		public override void ReadEntries(ICollection entries) 
		{
			foreach(object obj in entries) 
			{
				bag.Add(obj);
			}
		}

		public override void WriteTo(IDbCommand st, CollectionPersister persister, object entry, int i, bool writeOrder)<commit_msg>Fixed problem initializing the Bag.<commit_after>using System;
using System.Collections;
using System.Data;

using NHibernate.Engine;
using NHibernate.Type;

namespace NHibernate.Collection
{
	/// <summary>
	/// Summary description for Bag.
	/// </summary>
	public class Bag : ODMGCollection, IList
	{
		private IList bag;
		// used to hold the Identifiers of the Elements that will later
		// be moved to the bag field.
		private IList bagIdentifiers;

		public Bag(ISessionImplementor session) : base(session)
		{
		}

		public Bag(ISessionImplementor session, ICollection coll) : base(session) 
		{
			bag = coll as IList;
			
			if(bag == null) 
			{
				bag = new ArrayList();
				((ArrayList)bag).AddRange(coll);
			}

			initialized = true;
			directlyAccessible = true;
		}

		public Bag(ISessionImplementor session, CollectionPersister persister, object disassembled, object owner) : base(session)
		{
			BeforeInitialize(persister);
			object[] array = (object[])disassembled;
			for(int i=0; i<array.Length; i++) 
			{
				bag.Add(persister.ElementType.Assemble(array[i], session, owner));
			}
			initialized = true;
		}

		public override ICollection Elements()
		{
			return bag;
		}

		public override bool Empty
		{
			get{ return bag.Count==0;}
		}

		public override ICollection Entries()
		{
			return bag;
		}

		public override void EndRead(CollectionPersister persister, object owner)
		{
			for(int i = 0 ;i < bagIdentifiers.Count; i++) 
			{
				object element = persister.ElementType.ResolveIdentifier(bagIdentifiers[i], session, owner);
				bag[i] = element;
			}
		}

		public override object ReadFrom(IDataReader reader, CollectionPersister persister, object owner)
		{
			object elementIdentifier = persister.ReadElementIdentifier(reader, owner, session);
			int index = bag.Add(null);
			bagIdentifiers.Insert(index, elementIdentifier);
			
			return elementIdentifier;
		}

		[Obsolete("See PersistentCollection.ReadEntries for reason")]
		public override void ReadEntries(ICollection entries) 
		{
			foreach(object obj in entries) 
			{
				bag.Add(obj);
			}
		}

		public override void WriteTo(IDbCommand st, CollectionPersister persister, object entry, int i, bool writeOrder)
{'fraction_non_alphanumeric': 0.10299955888839876, 'fraction_numerical': 0.0013233348037053375, 'mean_word_length': 3.7288842544316996, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5194933', 'n_tokens_mistral': 1626, 'n_tokens_neox': 1367, 'n_words': 374}