lucenenet-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nicholas Paldino [.NET/C# MVP]" <>
Subject RE: [jira] Commented: (LUCENENET-218) Lucene.Net.Util.TestAttributeSource.TestCloneAttributes
Date Tue, 10 Nov 2009 06:41:48 GMT

	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 [] 
Sent: Tuesday, November 10, 2009 1:01 AM
Subject: RE: [jira] Commented: (LUCENENET-218)


That is an exceptional idea!  Sure you don't want to just dive in and take
it on?



-----Original Message-----
From: Nicholas Paldino [.NET/C# MVP] []
Sent: Mon 11/9/2009 9:57 PM
Subject: RE: [jira] Commented: (LUCENENET-218)

	Why not derive a class from KeyedCollection<TKey, TItem> (it is in
System.Collections.ObjectModel namespace in the mscorlib.dll assembly)?

	I would recommend having a generic class which you can pass an
method (lambda expression in .NET 3.5+) to which the override of
would call to extract the key for the item.

	The KeyedCollection returns an IEnumerable<T> (T = TItem) which will
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
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

		// Store the converter.
		this.converter = converter;

	/// <summary>The <see cref="Converter{TInput, TOutput}" /> instance
will convert
	/// an instance of <typeparamref name="TItem" /> into <typeparamref 
name="TKey" />
	/// which is used by the override of <see
	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
somewhere) or a lambda expression easily to provide the functionality you
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) []
Sent: Monday, November 09, 2009 11:20 PM
Subject: [jira] Commented: (LUCENENET-218) 

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
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
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
as elegant as using a native LinkedHashMap plus it requires the 3.5
and we are sticking with the 2.0 framework for Lucene.Net 2.9.  I checked
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
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:
>             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.


View raw message