collections

Unique List<T> in .NET 2

What is a (preferably generic) unique(IComparable/IEquitable) valued collection (à la List<T>; ideally a equivalent to HashSet<T> in .NET 3.5 without ordered items) of objects for .NET 2? ...

Hibernate - query caching/second level cache does not work by value object containing subitems

Hi! I have been struggling with the following problem: I have a value object containing different panels. Each panel has a list of fields. Mapping: <class name="com.aviseurope.core.application.RACountryPanels" table="CTRY" schema="DBDEV1A" where="PEARL_CTRY='Y'" lazy="join"> <cache usage="read-only"/> <id name="ctryCode"> <column name...

How can I create an Array of Controls in C#.NET?

I have a form which contains several standard controls (textbox's, buttons, etc). I want to group certain controls in collections so that I can enable and disable them at any given time without having to explicitly set each one. What is the syntax to do that? Here is some pseudo code to show what I want to do.... Control[] ControlCollec...

SubSonic2.2 Add() not working

I have 2 tables in my DB, Customers, Contacts. CusID is a Foreign Key in Contacts table. I tried the following Dim contact as New Contact(Guid.NewGuid()) contact.FirstName = "Mary" contact.LastName = "Jane" customer.Contacts.Add(contact) customer.Save() Customers and Contacts classes were generated with SubSonic2.2. The contact is no...

How to instantiate a collection of type MyCollection<T> : IList<Alert<T>> ?

I have an Alert <T> object. suppose I want to get all the alerts for type MyObject, I would have a collection of type MyCollection<MyObject> : IList<Alert<MyObject>>. How would I implement methods for that list? ...

Generic Map of Generic key/values with related types

I'm trying to create a generic type that keeps a map of the versions of itself that have been created for later use. Effectively, it's an singleton pattern where there's one instance per type. The code I have so far is: public class FieldBinder<T> { static final Map<Class<? extends Object>,FieldBinder<? extends Object>> instanceMap ...

Render partial in Ruby on rails a collection is multiplying items

I want to display a list of items in a page in Ruby-on-Rails. I use partials in my index.html.erb file I have: <%= @lista = News.find(:all, :order => Document::COL_DATE + ' DESC, id DESC') render :partial => "newsitem", :layout => "list_news", :spacer_template => "spacer", :collection => @lista %> ...

Silverlight: Bind to all items in nested lists

I'm using Silverlight 3 with RIA services. I've got a simple RIA DomainDataSource named "source" with a couple of ListBoxes bound to it. The method that the source queries returns a simple graph of objects: a collection of Parents, where each parent has a collection of Children. My UI has two listboxes. ParentListBox binds ItemsSource ...

What is this &:last Ruby Construct Called?

What are things like survey.map(&:questions).flatten.compact called, so I can find more information about them :). What problems does that &: solve, or what is it doing exactly? Is it used in other languages? ...

How to make Scala's immutable collections hold immutable objects.

I'm evaluating Scala and am having a problem with its immutable collections. I want to make immutable collections, which are completely immutable, right down through all the contained objects, the objects they reference, ad infinitum. Is there a simple way to do this? The code on http://www.finalcog.com/immutable-containers-scala il...

Scala collection type for filter

Assume you have a List(1,"1") it is typed List[Any], which is of course correct and expected. Now if I map the list like this scala> List(1, "1") map { | case x: Int => x | case y: String => y.toInt | } the resulting type is List[Int] which is expected as well. My question is if there is an equivalent to map for fil...

C#: Why doesn't LinkedList have a RemoveAll method that takes a predicate?

I have a LinkedList of nodes each storing a LinkedList of edges. I wanted to do something along the lines of nodes.RemoveAll(n => n.edges.Count == 0) But without RemoveAll there goes that. I don't understand why it doesn't have it, since other collections do. This would have to iterate through all elements too and remove only one at a...

C# WPF Databinding to Unkown Amount of Checkboxes

In my application I generate CheckBoxes for each possible category (retrieved from a database) and the user can check any number that apply. I name the checkboxes "cbCategory[ID]" where ID is the ID of that category in the database. I then need to generate some sort of collection class (as a property of my object class) to store the cat...

Magento: customize Low stock report

Hey folks, I need to add a few, sales-related columns to the Low stock report (e.g. Sales last week, Sales week before last week etc.) How should I do this? I’ve already managed to add some basic columns which already exists in the Collection (e.g. price, status etc.) I’m looking at Mage\Adminhtml\Block\Report\Product\Lowstock\Grid.p...

java - how to flatten a collection of sets, and should I do it in the first place?

hi all, say i have a graph, implemented with two maps (in and out) that map (source, set(edge)) and (target, set(edge)), respectively. until now, i also had allEdges set, which i decided to get rid of. returning edge set is now more difficult, as i have to flatten out the values of one of the maps. what's the best (fastest) way to do it...

Where's google-collection's LazyMap?

One of my favourites from apache commons-collections was the LazyMap which would use a Transformer to instantiate values on the fly when doing map.get(newKey); // Will not return null!. Why doesn't google collections have the same? ...

Need a Syncroot for a LinkedList(of T)

Hi I am using VB.Net and would like to use a LinkedList. Only problem is that it is a multithreaded application. I saw from MSDN that Syncroot is an explicit implementation of the ICollection Interface. I found people wanting to do similar things with List(Of T). It seems that the solution there is to cast the list to the interface. I ...

Prefix matching/trie for Java ?

I'm porting over a C program to Java. I need to do prefix lookups. e.g. given the keys "47" , "4741", "4742 a input of "474578" should yield the value for "47" , "474153" would match the "4741" key. In C I implemented this with a trie holding around 100k keys, I only neeed to care about keys containing the ascii chars [0-9], don't need...

I Use Generics, But Not This Class<T> thing!

I am trying to call this method to concat two arrays using Google Collections public static <T> T[] concat(T[] first, T[] second, Class<T> type) It's returning empty results. I am using ObjectArrays.concat(array1, array2, Blah.class) which is the only thing that compiles. a...

Convert Scala Set into Java (java.util.Set)?

I have a Set in Scala (I can choose any implementation as I am creating the Set. The Java library I am using is expecting a java.util.Set[String]. Is the following the correct way to do this in Scala (using scala.collection.jcl.HashSet#underlying): import com.javalibrary.Animals var classes = new scala.collection.jcl.HashSet[String] c...