collections

Collection specialized for shared_ptr

Does there exist a collection, that is aware of shared_ptr internals, and avoids regular copying of stored shared_ptr elements in favor of just copying their internal weak pointer? This implicitly means, that no constructor/destructor calls will be done and that there will be no manipulation of shared_ptrs' reference counters. ...

C#: When adding the same object to two List<object> variables, is the object cloned in the process?

I have something similar to this: // Declarations: List<SomeType> list1 = new List<SomeType>(); List<SomeType> list2 = new List<SomeType>(); ... SomeType something = new SomeType("SomeName"); list1.Add(something); list2.Add(something); ... list1[indexOfSomething] = new SomeType("SomeOtherName"); And the object in list2 isn't chang...

Getting subsets from Subsonic Collections

Hey, I'm using Subsonic Collections to pull a list of timesheet entries from our database and then databinding them to ASP.net user controls I've created on a page. Is it possible to break one large collection into multiple subsets based on a certain parameter? For example, each of our timesheet entries contain a job code for the part...

Collection Values Changing in for loop

I've got a bit of code that I've been working on for a friend for the past few days. At a high level it parses a text file and writes to an MDB. To cut a long story short, I've got a nested couple of loops doing some processing on the items. The inner loop only gets called in certain cases, but when it does, it's doing some strange th...

Out of Index Error on a System.Collections.Generic.List.Add(Object)

I'm getting an Out of Index Error when adding an Object to a System.Collections.Generic.List Dim myObj As New MyObject Dim List As New List(Of MyObject) List.Add(myObj) The error message are these (translated from my system language): "Index out of Matrix indexes" "Matrix origin wasn't long enough" "Verify srcIndex, size and inferior ...

How to convert List<Integer> to int[] in Java?

This is similar to this question: http://stackoverflow.com/questions/880581/java-convert-int-to-integer I'm new to Java. How can i convert a List to int[] in Java? I'm confused because List.toArray() actually returns an Object[], which can be cast to nether Integer[] or int[]. Right now I'm using a loop to do so: int[] toIntArray(List...

Java collections brain teasers

Java collections are invaluable tool in exchanging data between database and service layer. We have various cases of a HashMap, ArrayList, a HashMap of arraylists etc. I'm looking for programming samples, that contain a lot of exercise from simple to complex to deal with collections. It need not have answers/sample codes, just a variety...

Asserting in NUnit that a collection is in the same order as an expected collection

I know how to check that a collection is ordered by some property: Assert.That(actual, Is.Ordered.By("Foo")); How can I assert that actual contains the elements (1,2,5,3,4) in this specific order (without writing a custom comparer). ...

NHibernate collection mapping problem

Hello, I'm trying to map a relatively simple parent-children (Invoice-InvoiceEntry) scenario in NHibernate. Here are some parts of my mapping files: from Invoice.hbm.xml <set name="InvoiceEntries" table="InvoiceEntries" inverse="true" cascade="all-delete-orphan" lazy="false"> <key column="InvoiceID" /> <one-to-many class="Jobflow....

Overlay/Join two collections with Linq

I have the following scenario: List 1 has 20 items of type TItem, List 2 has 5 items of the same type. List 1 already contains the items from List 2 but in a different state. I want to overwrite the 5 items in List 1 with the items from List 2. I thought a join might work, but I want to overwrite the items in List 1, not join them toge...

How do I enumerate all items that implement a generic interface?

I have two interfaces, a generic and a non-generic that have an inheritence hierarchy: public interface IGenericRelation<TParent, TChild> : IRelation public interface IRelation The generic one is implemented by several server controls that are loaded dynamically and I wish to enumerate on the collection of controls that implement th...

Which Java blocking queue is most efficient for single-producer single-consumer scenarios

I'm working on a standard Java system with critical timing requirements for my producers (1/100s of ms matters). I have a producer placing stuff in a blocking queue, and a single consumer later picking up that stuff and dumping it to a file. The consumer blocks when data is not available. Obviously, blocking queue is the appropriate...

Is there a type that stores data indexed by a string key, or integer index?

List(Of T) stores data indexed by integer Dictionary(Of String, T) stores data indexed via string Is there a type or generic or specialized something that would let me access an array of T by either an index or name? ...

hibernate query problem, so close and stumped...

The schema: (psuedocode) I have a bean, called BaseEntity... @Entity class BaseEntity { @OneToMany @CascadeType.ALL List [Property] properties; //the use angled braces ommited for the stackoverflow editor to show up properly } Property is another bean... @Entity class Property { @ManyToOne Category category; @OneToO...

Immutable Objects in Java and Accessing Data

I've implemented a class in Java which, internally, stores a List. I want the class to be immutable. However, I need to perform operations on the internal data which don't make sense in the context of the class. Hence, I have another class which defines a set of algorithms. Here is a simplified example: Wrapper.java import java.uti...

MVVM: CollectionView in ViewModel or CollectionViewSource in xaml?

I'm developing a WPF application using the MVVM pattern and I need to display a list of items in a ListView (with filtering), with the fields of the selected item displayed in a Master/Detail view. I'm torn between the following two ways of doing this: Exposing a CollectionView in my ViewModel, and binding to this. Exposing a plain ILi...

Collections in Adobe Flex

Is there any open source collection framework, written in ActionScript that would emulate HashMap, HashSet, LinkedHashMap and LinkedHashSet Java class implementations. ...

Deleting items in foreach

Should you be allowed to delete an item from the collection you are currently iterating in a foreach loop? If so, what should be the correct behavior? ...

How do I get a particular derived object in a List<T>?

Let's say I have a generic list of Fruit (List<Fruit> fruits = new List<Fruit>()). I then add a couple of objects (all derived from Fruit) - Banana, Apple, Orange but with different properties on the derived objects (such as Banana.IsYellow). List<Fruit> fruits = new List<Fruit>(); Banana banana1 = new Banana(); Banana banana2 = new Ban...

Fastest way to copy a KeyedCollection

I'm working on a C# object copy constructor, part of which involves copying the contents of a KeyedCollection into a new KeyedCollection. This is what I have implemented currently: class MyKeyedCollection : KeyedCollection<uint, DataObject> { protected override uint GetKeyForItem( DataObject do ) { return do.Key; } }...