collections

.Net Collections: Node-Leaf

Is there a built in node-like collection that will allow me to store information within information without building long hard to read generic declarations? C# or VB.Net solutions would be appreciated. For example: dim base as new Dictionary(of String, Dictionary(of String, List(of String))) dim mid as new Dictionary(of String, List(o...

How to add a specific type object to a collection using Dozer?

I wanted to add an Object of a certain type to an ArrayList using Dozer. For ex: public class Source { private String id= null; private String value= null; } public class Destination { private List dest = null; public List getDest(){ return des; } } What I want is - Create an instance of Source and hydrate the attributes (id and value)...

add generic Action<T> delegates to a list

Is it possible to add a generic delegate Action to a List collection? I need some kind of simple messaging system for a Silverlight application. UPDATE The following is what i realy "want" class SomeClass<T> { public T Data { get; set; } // and more .... } class App { List<Action<SomeClass<T>>> _actions = new List<Action<S...

IEnumerator implementation problem

Hi Guys, I have this code: public class Check21CSVRecord { public string TransactionType; public string TransactionCurrency; public string Reference; public string PaymentType; // date of transaction public string TransactionDate; public string Notes; // customer data goes here pu...

linq remove item from object array where property equals value

If i have IEnumberable<Car> list and i want to remove an item from this list based on a property of the car i want something like: list.RemoveWhere(r=>r.Year > 2000) does something like this exist ? i am doing this over and over so i want to avoid copying the list each time to just remove one item ...

What's Wrong with an ArrayList?

Recently I asked a question on SO that had mentioned the possible use of an c# ArrayList for a solution. A comment was made that using an arraylist is bad. I would like to more about this. I have never heard this statement before about arraylists. could sombody bring me up to speed on the possible performance problems with using arrayli...

Interview: Design an iterator for a collection of collections

Design an iterator for a collection of collections in java. The iterator should hide the nesting, allowing you to iterate all of the elements belonging to all of the collections as if you were working with a single collection ...

Is there any elegant way in LINQ to bucket a collection into a set of lists based on a property

i have a collection of cars. I want to bucket this into separate lists by a property of the car . . .lets say brand. So if i have a collection of some Ford, some Chevy, some BMW, etc, i want a seperate list for each of those buckets. something like: IEnumberable<Car> myCarCollection = GetCollection(); List<IEnumerable<Car>> buckets ...

(Java) Store a huge collection of objects with indexed attributes

I need to store about 100 thousands of objects representing users. Those users have a username, age, gender, city and country. The users should be searchable by a range of age and any of the other attributes, but also a combination of attributes (e.g. women between 30 and 35 from Brussels). The results should be found quickly as it is o...

C# object initializers and collections

I'm trying to set up a class so that it's possible to initialize it using an object initializer, but it contains some collections. Ideally I'd like client code to be able to do: MyClass myObj = new MyClass { Name = "Name", Contents = new[] { "Item1", "Item2" } } However, where Contents needs to be a BindingList<string>...

What's a good and functional way to swap collection elements in Scala?

Hi! In a project of mine one common use case keeps coming up. At some point I've got a sorted collection of some kind (List, Seq, etc... doesn't matter) and one element of this collection. What I want to do is to swap the given element with it's following element (if this element exists) or at some times with the preceding element. I'm...

c# sorting a StringDictionary by value, NOT key

What is the 'best' way to sort (or iterate) over a StringDictionary in order of Value (not Key) E.g. Key - Value 1 - X label 2 - A label 3 - Other label would give 2 - A label 3 - Other label 1 - X label EDIT - I meant to say "using .NET 2.0 features". Sorry, me bad... ...

Get Current Index for Removal in String Collection

I have a String Collection that is populated with ID's like so --> 12345 23456 34567 and so on. What I need to do is at the user's request, and when certain parameters are met, go through that list, starting at the top, and perform a method() using that ID. If successful I would remove it from the list and move on. I, embarrassingl...

How to distinguish between live and non-live NodeList collections?

Both document.getElementsByTagName('div') and document.querySelectorAll('div') return NodeList collection. The only difference is that first method returns live-collection and second one - a static one. The question is - is there any opportunity to distinguish one object from another only via inspecting these objects (i.e - not trying t...

How to delete an item from a Set?

final Set<Expression> exps = meng.getExps(); Iterator<Expression> iterator = exps.iterator(); final Expression displayedExp = exps.iterator().next(); exps.remove(displayedExp); This code would return the following run-time exceptions trace: null java.lang.UnsupportedOperationException at java.util.Collections$UnmodifiableColle...

Java best practices, add to collection before or after object has been modified?

Say you are adding x number of objects to a collection, and after or before adding them to a collection you are modifying the objects attributes. When would you add the element to the collection before or after the object has been modified. Option A) public static void addToCollection(List<MyObject> objects) { MyObject newObject = ...

Xslt collection as parameter.

Hello, Could you help me to answer how to put collection of data as parameter in the xslt file, is it possible ? Thanks. ...

Why is Collections.addAll supposed to be faster than c.addAll

The Java API docs say the following about Collections.addAll The behavior of this convenience method is identical to that of c.addAll(Arrays.asList(elements)), but this method is likely to run significantly faster under most implementations. So if I understand correctly, a) is slower than b): a) Collection<Integer> col = new Arra...

Why my equals method won't work?

assertEquals(def.getMengs(), exp.getMengs()); fails, reporting: expected: java.util.HashSet<[...so geht die Legende ... ...legend has it ... ]> but was: java.util.HashSet<[...so geht die Legende ... ...legend has it ... ]> Indeed, through the debugger I see that both sets contain only one Meaning with objId = 1 for both. I expected th...

Binding String Collection to ListView, Windows Forms

I have a StringCollection that I want to One Way Bind to a ListView. As in, the ListView should display the contents of the StringCollection. I will be removing items from the collection programatically so they don't need to interact with it through the ListView. I have a Form with a Property, like so --> public DRIUploadForm() {...