collections

Comparing two List<string> for equality

Other than stepping through the elements one by one, how do I compare two lists of strings for equality (in .NET 3.0): This fails: // Expected result. List<string> expected = new List<string>(); expected.Add( "a" ); expected.Add( "b" ); expected.Add( "c" ); // Actual result a...

Several unusual errors when attempting to convert a string[] to a Dictionary<short, string>

I have the following code that splits a string on newlines and converts it to a Dictionary for further processing: string[] splitProgram = program.Split(Environment.NewLine.ToCharArray()); short i = 0; Dictionary<short, string> programDictionary = splitProgram.ToDictionary<short, string>((value) => i++); What's...

What is the meant by 'thread safe' object?

I have used generic queue in C# collection and everyone says that it is better to use the object of System.Collection.Generic.Queue because of thread safety. Please advise on the right decision to use Queue object, and how it is thread safe? ...

Problem with synchronized collections of Java when doing equals() in the reverse order from multiple threads

Example scenario: Create two SynchronizedSets (s1 and s2) Pass them to two threads (T1 and T2) Start the threads T1's run() : while (forever) s1.equals(s2) T2's run() : while (forever) s2.equals(s1) What happens? - SynchronizedSet's equals acquires lock on itself It computes the length of the param that's passed in an...

Using NHibernate Collection Filters with DDD collections

I am trying to map a domain model in NHibernate. The domain model is implemented with what I think is DDD style. The mapping works mostly but then when I try to use a collection filter on an a collection I get an exception which says: The collection was unreferenced. I know the problem comes from how I've implemented the collection. My ...

checking if list<MyObject> is already in the collection

normally with a hashtable I do: if(!myHash.Contains(someId)) { // insert to hash } If I have a List, how can I check using contains? Right now I am just creating a hashtable of user id's, and checking that, but is there a way just using just the List? ...

Modfying a collection (Generics) in a persistent object leads to exceptions or loss of data

What I have? An object that is saved in a static variable and called whenever needed This object interfaces with another application. I have two collections (Generic Lists) in this object Logs And "Data That Is PreFeteched" to be used later Problem is when more than one person is trying to use this object (the object interfaces with...

What is a good example of an __eq__ method for a collection class?

I'm working on a collection class that I want to create an __eq__ method for. It's turning out to be more nuanced than I thought it would be and I've noticed several intricacies as far as how the built-in collection classes work. What would really help me the most is a good example. Are there any pure Python implementations of an __eq...

Subsonic 2.2 where are the Datagridview colunms

Hi there, I'm was going to update are windows VB.net project to use Subsonic 2.2.1 from 2.0.3.0 I was testing 2.2.1 to make sure everything would update with no problems and guess What  I have most for the data grid views bind to the subsonic generated collection and I can change the columns header text, I found with the test that I c...

Is there a way to check if two Collections contain the same elements, independent of order?

I've been looking for a method that operates like Arrays.equals(a1, a2), but ignoring the element order. I haven't been able to find it in either Google Collections (something like Iterables.elementsEqual(), but that does account for ordering) and JUnit (assertEquals() obviously just calls equals() on the Collection, which depends on the...

Union two ObservableCollection Lists

Hi folks, I have two ObservableCollection lists, that i want to unite. My naive approach was to use the Union - Method: ObservableCollection<Point> unitedPoints = observableCollection1.Union(observableCollection2); ObservableCollection1/2 are of type ObservableCollection too. But the Compiler throws the following error for this line:...

Most succinct way to convert ListBox.items to a generic list

I am using C# and targeting the .NET Framework 3.5. I'm looking for a small, succinct and efficient piece of code to copy all of the items in a ListBox to a List<String> (Generic List). At the moment I have something similar to the below code: List<String> myOtherList = new List<String>(); // Populate our colCriteria ...

Select distinct values in all nested collections using LINQ to objects?

Given the following code setup: public class Foo { List<string> MyStrings { get; set; } } List<Foo> foos = GetListOfFoosFromSomewhere(); How do I get a list of all of the distinct strings in MyStrings across all of the Foo instances using LINQ? I feel like this should be easy, but can't quite figure it out. string[] distinctMyStrin...

How would I know if a property is a generic collection

I need to know if the type of a property in a class is a generic collection (List, ObservableCollection) using the PropertyInfo class. enter code here foreach (PropertyInfo p in (o.GetType()).GetProperties()) { if(p is Collection<T> ????? ) } ...

Iteration through GroupCollection in C#

Hi, I'm currently trying to implement the use of regular expressions: Regex reg_gameinfo = new Regex(@"PokerStars Game #(?<HID>[0-9]+):\s+(?:HORSE)? \(?(?<GAME>Hold'em|Razz|7 Card Stud|Omaha|Omaha Hi/Lo|Badugi) (?<LIMIT>No Limit|Limit|Pot Limit),? \(?(?<CURRENCYSIGN>\$|)?(?<SB>[.0-9]+)/\$?(?<BB>[.0-9]+) (?<CURRENCY>.*)\) - (...

Search/Queries in Collections (Java)

I've created many Geodata objects (name,postalCode,lat,lon). Now I want to put them into a collection to search for different entries later. Everything should happen objectOriented/in-memory, so there shouln't be a need for a relational database. Such a Query looks like: Find lat and lon by name or plz Find objects between LAT1,L...

Is it possible to get an IEnumerator<T> from a T[]?

Let's say I want to create a collection class that is thread-safe by default. Internally, the class has a protected List<T> property called Values. For starters, it makes sense to have the class implement ICollection<T>. Some of this interface's members are quite easy to implement; for example, Count returns this.Values.Count. But imp...

Where do you put collection classes?

I am not sure if there is already a nomenclature for this, but for the sake of this question lets define two terms: peer implementation or nested implementation to illustrate how you implement collection classes in a data model that contains many parent/child entity relationships. I use the term peer to describe the scenario where you i...

NHibernate is turning my collection readonly. How can I stop it?

Hi guys, I'm having a bit of an issue with Nhibernate / Fluent NHibernate I have a class that has a collection and a backing field, and methods for manipulating the collection like so: Edit: I've added the virtual modifier to Children since I forgot to stick it in the example code below (it was 2 am) public class MyClass { private...

In a java web applications, does clearing any collections used lead to better memory management?

I have a list element which is populated via a query, this is then run through a for loop which sends this list to the front end, a jsp and prints them. Wanted to know if by calling the list.clear() outside the for loop, it will clear the list object, so will this lead to better memory management? or should one use the weakhashmap for ...