collections

Setting the i-th value of a SortedDictionary

I need to set the value of an element in my sortedDictionary, accessed by index. I.e. sortedDictionary.Values[index] = value; // compile error Note that the following is incorrect because it's accessed by key, not index. sortedDictionary[index] = value; // incorrect I came up with the following solution, but intuition tells me it'...

Whats the best way to handle finding items in a list that occured after another?

I have a class like this public class HistoryEntry { DateTime Date{ get; protected set; } HistoryType EntryType { get; protected set; } } public enum HistoryType { Cancelled, Cleared, Redeemed, Refunded } I have an unordered list of these History Entries, and I do Exists statements to see if an entry exists in...

Creating Key/Value collections using LINQ To Objects

I'm trying to use LINQ To Objects to create a query that will give me files, indexed by filename with a value mapping to their binary data as byte[]. However I can't find a 'neat' way to do this. I'm hoping to get something like a Dictionary<T,K> output. Here's what I have so far. Example delimFileNames="1.jpg|2.jpg" //Extract filenam...

refactoring Java arrays and primitives (double[][]) to Collections and Generics (List<List<Double>>)

I have been refactoring throwaway code which I wrote some years ago in a FORTRAN-like style. Most of the code is now much more organized and readable. However the heart of the algorithm (which is performance-critical) uses 1- and 2-dimensional Java arrays and is typified by: for (int j = 1; j < len[1]+1; j++) { int jj = (con...

Refactoring List<Foo> to FooList

I have a number of collections of classes which I need to refactor into new classes. I'm using Java with either Eclipse or Netbeans. Currently I create the new class FooList with a delegate List<Foo> and then follow all the places where the code fails to compile. Is there a way to do this without breaking the code (and preferably a singl...

Change the label of a TCollectionItem in the Delphi editor

A component I am working on uses a TCollection to hold links to other components. When the items are edited in the designer their labels look something like this: 0 - TComponentLink 1 - TComponentLink 2 - TComponentLink 3 - TComponentLink How do I add meaningful labels (the name of the linked component perhaps)? e.g. 0 - UserList 1 -...

Mapping a list in hibernate by ordering instead of an index-field

This works: <hibernate-mapping> <class name="Train" table="Trains"> <id column="id" name="id" type="java.lang.String" length="4"> <generator class="assigned" /> </id> <set name="trips" cascade="all"> <key column="trainId"/> <one-to-many class="Trip"/> </set> <...

Blackbery JDE ArrayList?

So. Um. The Blackberry JDE does not include java.util.ArrayList, even though it knows about java.util? What's up with that? Is there an equivalent class for BB? I don't want to use an Array, really, because I have an unknown number of objects I'm dealing with. why does the Blackberry JDE leave so much out? -Jenny ...

Easiest way to convert a List to a Set? - Java

Easiest way to convert a List to a Set? - In Java ...

How to use two numbers as a Map key

I have two numbers and I want to use them together as a key in a Map. Currently, I'm concatenating their string representations. For example, suppose the key numbers are 4 and 12. I use: String key = 4 + "," + 12; The map is declared as Map<String, Object>. I think this is so bad! I like to use something other than a String as the ke...

Find all matches in a Java Collection

Ok. Here is a problem. This is my collection : {2,3,4,2,3,5}. Let's assume that it is a List for now. I would like to search this collection for all matches of '2'. I would like indexes of the same. I know that there are indexOf() and lastIndexOf() methods in List and Arrays.binarySearch(). However, all of them return one element indicat...

How to stop a new form from using namespace System::Collections

If I create a new form called myForm, the top of myForm.h looks like this: #pragma once using namespace System; using namespace System::ComponentModel; using namespace System::Collections; //<<<< THIS ONE using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; None of these are even ...

Which Collection Class to use: Hashtable or Dictionary?

I need to define a class with an internal collection object to hold different types of values(such as string, int, float, DateTime, and bool) by a string key. I could use Hashtable since it is not strongly typed collection class, while the Dictionary is used for strongly typed items (I could use object for Dictionary even though). Here...

When serializing a custom generic collection to Xml how do I add an attribute to the generated collection element.

When serializing a custom generic collection to Xml how do I add an attribute to the generated collection element. Currently I have: <RootObject> <Id>1</Id> <Items> <MyCollectionItem/> <MyCollectionItem/> </Items> </RootObject> What I need is: <RootObject> <Id>1</Id> <Items Name="My collection name"> <MyCollec...

Getting the filepaths of every file in folder X.

I'm making a little file splitter-joiner, and I've already got the splitting process done. Now I need to complete the joiner. I have this method: public static void juntarArchivo(string[] Cortes, string CarpetaDestino) { string Nombre = ExtraerNombre(Cortes[0]); int CantidadDeCortes = Cortes.Length; ...

Collections of collections and Objective-C memory management

I have a pretty simple question. While I am fairly new to Objective-C, I have gotten pretty comfortable with the language and the memory management model. I understand ownership pretty well and the notion of explicit and implicit. I also understand that when you add anything to a collection, it takes ownership of the keys and values a...

Is there an implementation of IList<T> where Contains(T) is an O(1) operation?

I'm wondering if there is an IList<T> implementation that's backed by a hash like HashSet<T> but offers indexed access? To be clear, I'm not concerned on how to implement one, just wondering if anyone knows if it's already available. ...

Apache Commons vs. Google Collections

I was looking for a bidirectional map implementation in Java, and stumbled upon these two libraries: Apache Commons Collections Google Collections Both are free, have the bidirectional map implementation that I was looking for (BidiMap in Apache, BiMap in Google), are amazingly nearly the same size (Apache 493 kB, Google 499 kB) and ...

Does a sorted queue exist in .NET?

I have a need for a fairly specialised collection .NET, and I don't think that the BCL can help me, but I thought I'd throw it out there for if anyone knew of something similar. Basically, my requirements are thus: I have a list of pairs of values, such as: (3, 10), (5, 10), (3, 7), (5, 5) Order is important, ie. (3, 10) != (10, 3) Du...

How to write a function that takes an iterator or collection in a generic way?

I've been a Java programmer almost exclusively for the past 8 years or so, and recently I've been playing with C++ again. Here's an issue that I've come up against with regards to iterators in C++ STL and Java. In Java, you can write a method that takes an iterator like this: void someMethod(Iterator<String> data) { // ... } You ...