You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucenenet.apache.org by "Jon Davis (JIRA)" <ji...@apache.org> on 2007/10/16 23:29:50 UTC

[jira] Issue Comment Edited: (LUCENENET-103) Need to implement ICloneable on RAMDirectory

    [ https://issues.apache.org/jira/browse/LUCENENET-103?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12535347 ] 

stimpy77 edited comment on LUCENENET-103 at 10/16/07 2:29 PM:
---------------------------------------------------------------

In my environment I implemented ICloneable already, using the referenced hyperlink.

namespace Lucene.Net.Store
{
 ...	
	public sealed class RAMDirectory : Directory, ICloneable
	{
...

        #region ICloneable Members
        /// <summary>
        /// Creates a clone of the RAMDirectory.
        /// If <paramref name="deep"/> is true, the clone is made 
        /// at the byte level. 
        /// If <paramref name="deep"/> is false, the clone is made
        /// at the buffers' references level.
        /// </summary>
        /// <param name="deep">
        /// If <paramref name="deep"/> is true, the clone is made 
        /// at the byte level. 
        /// If <paramref name="deep"/> is false, the clone is made
        /// at the buffers' references level.
        /// </param>
        /// <returns>A RAMDirectory object.</returns>
        public object Clone(bool deep)
        {
            RAMDirectory clone = new RAMDirectory();
            System.Collections.IDictionaryEnumerator enmr = files.GetEnumerator();
            while (enmr.MoveNext())
            {
                string name = (string)enmr.Key;
                RAMFile rf = (RAMFile)enmr.Value;
                clone.files.Add(name, rf.Clone(deep));
            }
            return clone;
        }

        public object Clone()
        {
            return Clone(false);
        }

        #endregion
    }

	class RAMFile : ICloneable
	{

...

        #region ICloneable Members

        /// <summary>
        /// Creates a clone of the RAMFile.
        /// If <paramref name="deep"/> is true, the clone is made 
        /// at the byte level. 
        /// If <paramref name="deep"/> is false, the clone is made
        /// at the buffers' references level.
        /// </summary>
        /// <param name="deep">
        /// If <paramref name="deep"/> is true, the clone is made 
        /// at the byte level. 
        /// If <paramref name="deep"/> is false, the clone is made
        /// at the buffers' references level.
        /// </param>
        /// <returns>A RAMFile object.</returns>
        public object Clone(bool deep)
        {
            RAMFile clone = new RAMFile();
            if (!deep)
            {
                clone.buffers = (System.Collections.ArrayList) buffers.Clone();
            }
            else
            {
                clone.buffers = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
                for (int i = 0; i < buffers.Count; i++)
                {
                    byte[] buf = (byte[])buffers[i];
                    byte[] cloneBuf = (byte[])buf.Clone();
                    clone.buffers.Add(cloneBuf);
                }
            }
            clone.length = length;
            clone.lastModified = lastModified;
            return clone;
        }
        /// <summary>
        /// Performs a shallow copy of the object.
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            return Clone(false);
        }

        #endregion
    }
}

      was (Author: stimpy77):
    In my environment I implemented ICloneable already, using the referenced hyperlink.

namespace Lucene.Net.Store
{
 ...	
	public sealed class RAMDirectory : Directory, ICloneable
	{
...

        #region ICloneable Members
        /// <summary>
        /// Creates a clone of the RAMDirectory.
        /// If <paramref name="deep"/> is true, the clone is made 
        /// at the byte level. 
        /// If <paramref name="deep"/> is false, the clone is made
        /// at the buffers' references level.
        /// </summary>
        /// <param name="deep">
        /// If <paramref name="deep"/> is true, the clone is made 
        /// at the byte level. 
        /// If <paramref name="deep"/> is false, the clone is made
        /// at the buffers' references level.
        /// </param>
        /// <returns>A RAMDirectory object.</returns>
        public object Clone(bool deep)
        {
            RAMDirectory clone = new RAMDirectory();
            System.Collections.IDictionaryEnumerator enmr = files.GetEnumerator();
            while (enmr.MoveNext())
            {
                string name = (string)enmr.Key;
                RAMFile rf = (RAMFile)enmr.Value;
                clone.files.Add(name, rf.Clone(deep));
            }
            return clone;
        }

        public object Clone()
        {
            return Clone(false);
        }

        #endregion
    }

	class RAMFile : ICloneable
	{

...

        #region ICloneable Members

        /// <summary>
        /// Creates a clone of the RAMFile.
        /// If <paramref name="deep"/> is true, the clone is made 
        /// at the byte level. 
        /// If <paramref name="deep"/> is false, the clone is made
        /// at the buffers' references level.
        /// </summary>
        /// <param name="deep">
        /// If <paramref name="deep"/> is true, the clone is made 
        /// at the byte level. 
        /// If <paramref name="deep"/> is false, the clone is made
        /// at the buffers' references level.
        /// </param>
        /// <returns>A RAMFile object.</returns>
        public object Clone(bool deep)
        {
            RAMFile clone = new RAMFile();
            if (deep)
            {
                clone.buffers = (System.Collections.ArrayList) buffers.Clone();
            }
            else
            {
                clone.buffers = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
                for (int i = 0; i < buffers.Count; i++)
                {
                    byte[] buf = (byte[])buffers[i];
                    byte[] cloneBuf = (byte[])buf.Clone();
                    clone.buffers.Add(cloneBuf);
                }
            }
            clone.length = length;
            clone.lastModified = lastModified;
            return clone;
        }
        /// <summary>
        /// Performs a shallow copy of the object.
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            return Clone(false);
        }

        #endregion
    }
}
  
> Need to implement ICloneable on RAMDirectory
> --------------------------------------------
>
>                 Key: LUCENENET-103
>                 URL: https://issues.apache.org/jira/browse/LUCENENET-103
>             Project: Lucene.Net
>          Issue Type: Improvement
>         Environment: C# 2.0
>            Reporter: Jon Davis
>            Priority: Minor
>
> IClonable needs to be added to Lucene.net's RAMDirectory.
> See Lucene (Java) item resolution at: 
> http://www.mail-archive.com/lucene-dev@jakarta.apache.org/msg03725.html

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.