Michael, Already doing it, and using it in CompoundFileWriter as well to remove the ugly Hashtable and Arraylist as examples of what I mean in my previous emails.
- Nick -----Original Message----- From: Michael Garski [mailto:mgar...@myspace-inc.com] Sent: Tuesday, November 10, 2009 1:01 AM To: lucene-net-dev@incubator.apache.org Subject: RE: [jira] Commented: (LUCENENET-218) Lucene.Net.Util.TestAttributeSource.TestCloneAttributes Nick, That is an exceptional idea! Sure you don't want to just dive in and take it on? ;) Michael -----Original Message----- From: Nicholas Paldino [.NET/C# MVP] [mailto:casper...@caspershouse.com] Sent: Mon 11/9/2009 9:57 PM To: lucene-net-dev@incubator.apache.org Subject: RE: [jira] Commented: (LUCENENET-218) Lucene.Net.Util.TestAttributeSource.TestCloneAttributes Michael, Why not derive a class from KeyedCollection<TKey, TItem> (it is in the System.Collections.ObjectModel namespace in the mscorlib.dll assembly)? I would recommend having a generic class which you can pass an anonymous method (lambda expression in .NET 3.5+) to which the override of GetKeyForItem would call to extract the key for the item. The KeyedCollection returns an IEnumerable<T> (T = TItem) which will return items in the order they are added in, and you can access items by key. This isn't to say that yours wouldn't work, but if the framework is doing most of the work for you, then why do extra work? I'd use something like this: public /* or whatever */ class KeyedCollection<TKey, TItem> : System.Collections.ObjectModel<TKey, TItem> { public KeyedCollection(Converter<TItem, TKey> converter) : base() { // Check to make sure converter is not null. if (converter == null) throw new ArgumentNullException("converter"); // Store the converter. this.converter = converter; } /// <summary>The <see cref="Converter{TInput, TOutput}" /> instance which will convert /// an instance of <typeparamref name="TItem" /> into <typeparamref name="TKey" /> /// which is used by the override of <see cref="GetKeyForItem(TItem)" />.</summary> private readonly Converter<TItem, TKey> converter; protected override TKey GetKeyForItem(TItem item) { // Call the converter. return converter(item); } } Then, you can pass an anonymous delegate, a method (if you have it defined somewhere) or a lambda expression easily to provide the functionality you need for any type, and it gives you the exact functionality of a LinkedHashMap (retrieval of items based on order of insertion and lookup based on key). - Nick -----Original Message----- From: Michael Garski (JIRA) [mailto:j...@apache.org] Sent: Monday, November 09, 2009 11:20 PM To: lucene-net-dev@incubator.apache.org Subject: [jira] Commented: (LUCENENET-218) Lucene.Net.Util.TestAttributeSource.TestCloneAttributes [ https://issues.apache.org/jira/browse/LUCENENET-218?page=com.atlassian.jira. plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12775271#acti on_12775271 ] Michael Garski commented on LUCENENET-218: ------------------------------------------ OK, this one is a bit trickier than I first thought. I've been mucking with different options on how to address this test as well as the implementation in Lucene.Net.Util.AttributeSource. Here's the scoop: Inside AttributeSource are two LinkedHashMaps, which cannot be swapped out with a direct native collection due to the fact that the iterator must enumerate over the items in the way they were added, which rules out any sort of Dictionary collection. The SortedList and other sorted collections sort based on the key value, not insertion order. I tried weaving some hacks in and was not satisfied with it as they were downright ugly. I poked around with using LINQ to achieve the same functionality, but it's not as elegant as using a native LinkedHashMap plus it requires the 3.5 framework and we are sticking with the 2.0 framework for Lucene.Net 2.9. I checked out a few free collection libraries (C5, PowerCollections) and was not able to find a drop-in replacement for LinkedHashMap. What I'm considering now is to create a class that is a composite of native .Net collections that will provide the same functionality. A little more work and a few extra unit tests will be needed for it to ensure it works as it's supposed to, but in the end we will have our own LinkedHashMap class that would reside in Lucene.Net.Util. Any thoughts? > Lucene.Net.Util.TestAttributeSource.TestCloneAttributes > ------------------------------------------------------- > > Key: LUCENENET-218 > URL: https://issues.apache.org/jira/browse/LUCENENET-218 > Project: Lucene.Net > Issue Type: Bug > Reporter: Michael Garski > > The test is failing - I'm working on it :) -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.
smime.p7s
Description: S/MIME cryptographic signature