collections

HashSet.remove() and Iterator.remove() not working

I'm having problems with Iterator.remove() called on a HashSet. I've a Set of time stamped objects. Before adding a new item to the Set, I loop through the set, identify an old version of that data object and remove it (before adding the new object). the timestamp is included in hashCode and equals(), but not equalsData(). for (Itera...

HashMap default types for K and V

I usually type my map declarations but was doing some maint and found one without typing. This got me thinking (Oh No!). What is the default typing of a Map declaration. Consider the following: Map map = new HashMap(); map.put("one", "1st"); map.put("two", new Integer(2)); map.put("three", "3rd"); for ( Map.Entry entry : map.entrySet...

Creating a constant Dictionary in C#

What is the most efficient way to create a constant (never changes at runtime) mapping of strings to ints? I've tried using a const Dictionary, but that didn't work out. I could implement a immutable wrapper with appropriate semantics, but that still doesn't seem totally right. For those who have asked, I'm implementing IDataError...

Bidirectional 1 to 1 Dictionary in C#

I am looking for a generic, bidirectional 1 to 1 Dictionary class in C# (2), ie. a BiDictionaryOneToOne<T, S> which is guaranteed to only contain one of each value and key (up to RefEquals anyway), and which can be searched using either key or value. Anyone know of one, or should I just implement it myself? I can't believe that I'm the f...

Is there a no-duplicate List implementation out there?

Hey all, I know about SortedSet, but in my case I need something that implements List, and not Set. So is there an implementation out there, in the API or elsewhere? It shouldn't be hard to implement myself, but I figured why not ask people here first? thanks, Yuval =8-) ...

ObservableCollection that also monitors changes on the elements in collection

Is there a collection (BCL or other) that has the following characteristics: Sends event if collection is changed AND sends event if any of the elements in the collection sends a PropertyChanged event. Sort of an ObservableCollection where T: INotifyPropertyChanged and the collection is also monitoring the elements for changes. I could...

What are alternatives to generic collections for COM Interop?

I am attempting to return a collection of departments from a .NET assembly to be consumed by ASP via COM Interop. Using .NET I would just return a generic collection, e.g. List<Department>, but it seems that generics don't work well with COM Interop. So, what are my options? I would like to both iterate over the list and be able to acce...

If I turn a collection of Number into a table, what's the name of the column? 10gR2

If I wanted to replace the * with a column name, what would it be? create type mytable$t as table of number; / declare mytmou mytable$t := myTable$T(); cnt pls_integer ; begin mytmou := myTable$T(1,2,3,4,5,6); SELECT count(*) into cnt From Table (mytmou); dbms_output.put_line(cnt); end; 6 ...

Coming up with a topology for a public facing SharePoint website

I'm currently planning the migration of a Microsoft Content Management Server (MCMS) website to a SharePoint 2007 publishing site. The top-level site is a public facing, anonymously-accessible website. It will contain two areas which need to be protected with forms-based authentication - each of which will have a distinct set of users. ...

How to get a ReadOnlyCollection<T> of the Keys in a Dictionary<T, S>

My class contains a Dictionary<T, S> dict, and I want to expose a ReadOnlyCollection<T> of the keys. How can I do this without copying the Dictionary<T, S>.KeyCollection dict.Keys to an array and then exposing the array as a ReadOnlyCollection? I want the ReadOnlyCollection to be a proper wrapper, ie. to reflect changes in the underl...

Best practice: How to expose a read-only ICollection

I have an ICollection<T> called foos in my class which I want to expose as read-only (see this question). I see that the interface defines a property .IsReadOnly, which seems appropriate... My question is this: how do I make it obvious to the consumer of the class that foos is read-only? I don't want to rely on them remembering to quer...

Best Collection To Use?

Hi There, I am reading log files but not all lines want to be processed straight away. I am using a queue / buffer to store the lines while they wait to be processed. This queue is regularly scanned for particular lines - when they are found, they are removed from the queue (they can be anywhere in it). When there isn't a particular li...

Casting problem in C# generic method

I'm having some trouble with a generic method I'm writing. It has the following signature; public static ThingCollection<T> GetThings<T>(...) where T : Thing There are several classes; ThingA, ThingB and ThingC that inherit from Thing; and I want to be able to have code something like this in the method. var things = new ThingCollec...

How do I overload the square-bracket operator in C#?

DataGridView, for example, lets you do this: DataGridView dgv = ...; DataGridViewCell cell = dgv[1,5]; but for the life of me I can't find the documentation on the index/square-bracket operator. What do they call it? Where is it implemented? Can it throw? How can I do the same thing in my own classes? ETA: Thanks for all the quic...

ASP.NET MVC Editing A Collection Best Practices - Your Opinion

Given the following class, what is your opinion on the best way to handle create/edit where Attributes.Count can be any number. public class Product { public int Id {get;set;} public string Name {get;set;} public IList<Attribute> Attributes {get;set;} } public class Attribute { public string Name {get;set;} public string Val...

Genericized commons collection

Hi, I'm astonished that the Apache Commons Collections project still hasn't got around to making their library generics-aware. I really like the features provided by this library, but the lack of support for generics is a big turn-off. There is a Lavalabs fork of Commons Collections which does support generics, which seems to claim back...

When I sort a List what happens to its iterators?

Let's say I have a List object and an iterator for that list. Now I sort the list with java.util.Collections.sort() What happens to the iterator? Is its behavior still defined and can it still be used? If not, can I prevent destroying the iterators for the list? I know, this problem could be circumvented by changing the program de...

Exposing the indexer / default property via COM Interop

I am attempting to write a component in C# to be consumed by classic ASP that allows me to access the indexer of the component (aka default property). For example: C# component: public class MyCollection { public string this[string key] { get { /* return the value associated with key */ } } public void Add(string k...

ArrayList vs. Vectors in Java if thread safety isn't a concern

Is there really that much of a difference between the performance of Vectors and ArrayLists? Is it good practice to use ArrayLists at all times when thread safety isn't an issue? ...

count vs length vs size in a collection

From using a number of programming languages and libraries I have noticed various terms used for the total number of elements in a collection. The most common seem to be length, count, and size. eg. array.length vector.size() collection.count Is there any preferred term to be used? Does it depend on what type of collection it is? ie...