collections

Flatten array in PowerShell

Assume we have $a = @(1, @(2, @(3))) I whould like to flatten $a to get @(1, 2, 3) I have found a solution @($a | % {$_}).count But may be there is a more elegant way? ...

How to add 2 Dictionary contents without looping in c#

I have 2 dictionaries of type <string,object> in C# How can I copy all the contents of one Dictionary object to the other without applying a loop? ...

LINQ: Remove items from IQueryable

I want to remove an item from the result of a LINQ query before using it to databind. What is the proper way to do this? The foreach in my illustration is the topic of my question. Illustration: var obj = (from a in dc.Activities where a.Referrer != null && a.Referrer.Trim().Length > 12 && a.Session.IP.NumProblems == 0...

Parsing XML and cast elements to a typed collection using LINQ, C#

Hi I have an XML doc: <statuses> <status> </status> <status> </status> </statuses> I have parsed this into an XDocument, and want to use LINQ to select the elements into a strongly typed collection of Status classes (all status elements are simple types, either string or int). Any ideas how I can do this? Thanks! ...

linq question: querying nested collections

I have a Question class that has public List property that can contain several Answers. I have a question repository which is responsible for reading the questions and its answers from an xml file. So I have a collection of Questions (List) with each Question object having a collection of Answers and I'd like to query this collection o...

Scope of .NET's List(Of T).Reverse Method

I've got a simple function that takes a List parameter. While working with it, it copies it and reverses the copy using .NET's List(Of T).Reverse method. Private Function FindThing(ByVal Things As List(Of Thing)) As Thing Dim ReverseOrderThings As List(Of Thing) = Things ReverseOrderThings.Reverse() For Each t As Thing In R...

What to pass to the Arrays instance method toArray(T[] a) method?

If you have an instance of a Collection, say something like: Collection<String> addresses = new ArrayList<String>(); Which were to then be populated with a bunch of values, which is the "best" way, if any, to make use of the toArray() method without requiring a type cast? String[] addressesArray = addresses.toArray(new String[] {}); ...

Preserve listbox item selection

Hi, First the code (sorry if its not 100%) I am no expert and then the question follows. public partial class Window1 : Window { CollectionView cv; public Window1() { InitializeComponent(); List<Person> ppl = new List<Person>(); BitmapImage b = new BitmapImage(new Uri(@"http://i.stackoverfl...

Need Duplicates Allowed In SortedCollection (C#, 2.0)

Hello, I have a project that I'm working on that requires changing a 'BaseSortedCollection' class to allow duplicates. The class currently implements IEnumerable, IDisposable, ICollection, and ISerializable. The 'BaseSortedCollection' stores Items that have an ItemID (Int64), which is used as the key when accessing the collection. I n...

Best practice for incorrect parameters on a remove method

So I have an abstract data type called RegionModel with a series of values (Region), each mapped to an index. It's possible to remove a number of regions by calling: regionModel.removeRegions(index, numberOfRegionsToRemove); My question is what's the best way to handle a call when the index is valid : (between 0 (inclusive) and the ...

nHibernate Mapping Issue - Cannot Delete members of a collection

Ok. So the situation is: Parent Class which has an IDictionary of Child Classes. I wish these child classes to be deleted when the parent class is. This works fine. I also wish to be able to delete members of the child class individually, and this does NOT work. So my Question is; Why can I not delete these child members? The error ...

How deep would you expect the immutability of an immutable list to be?

If you have an immutable list, you expect it to always return a reference to the same object when you ask for, say list.get(0) My question is, would you expect to be able to mutate the object and have the mutation reflected next time you get it from the list? ...

How to store a collection of custom objects to an user.config file?

I would like to store a collection of custom objects in a user.config file and would like to add and remove items from the collection programmatically and then save the modified list back to the configuration file. My items are of the following simple form: class UserInfo { public string FirstName { get; set; } public string La...

Querying Java Data Structures

Is there any way to perform SQL Like Queries or Filtering on Java Data Structures? I want to filter objects in an ArrayList and a HashMap by fields of the objects contained within. ...

How do I sort a set in Java?

In Java, I have a set, and I want to turn it into a sorted list. Is there a method in the collections package that will do this for me? ...

Field Names for Struts2 map entries in a JSP

I want to populate a map property on a Struts2 action from a JSP. What is the format of the data names that I should use? Initially I am interested in populating a Map<String, String> but in the future I would be interesting in populating a Map<String, DomainClass> where the DomainClass has properties of its own. ...

TreeViolationException problem

Hi Im having some trouble when inserting to the right of a node in a binary tree... I just dont see why the exception is happening. This is the method to inset: public void attachRight(BinaryTree<T> tree) { if (right != null) { throw new TreeViolationException(); } if (tree != null) { tree.parent = this; right = tree; } } ...

Filter a wpf collectionviewsource in VB?

Hi, I want to filter a collectionviewsource using a filter I've written, but I'm not sure how I can apply the filter to it? Here is my collection view source: <Grid.Resources> <CollectionViewSource x:Key="myCollectionView" Source="{Binding Path=Query4, Source={x:Static Application.Current}}"> <Colle...

Java collection/map apply method equivalent?

Hi, I would like to apply a function to a Java collection, in this particular case a map. Is there a nice way to do this? I have a map and would like to just run trim() on all the values in the map and have the map reflect the updates. ...

Collections for hierarchies

In the app I am writing, I am trying to find a way to store hierarchies effectively. Here is an example. At the bottom, you can see the nodes to be stored. Should I use multi dimensional lists? That doesn't seem very optimal, right? I was thinking holding references like so: node.Parent node.Children { collection } Anyone has experie...