collections

Simple database-like collection class in Java.

The problem: Maintain a bidirectional many-to-one relationship among java objects. Something like the Google/Commons Collections bidi maps, but I want to allow duplicate values on the forward side, and have sets of the forward keys as the reverse side values. Used something like this: // maintaining disjoint areas on a gameboard. Locat...

Quaere - Anyone using it yet? (LINQ to Objects for Java)

Hi there I'm a .NET guy originally, working in Java recently, and finding I'm really missing LINQ to Objects, specifically for performing filtering against collections. A few people here on Stack Overflow have answered the "LINQ for Java?" question with a single word : Quaere However, on the site it clearly states "Pre-Beta", an...

Caching when using Query Expressions?

I was reading an article about how query expressions defer executions. Does that mean when we have a collection like: IEnumerable<int> collection = from i in integers where i % 2 == 0 select i; It is gonna be recalculated every time the collection is accessed? If so, what's the general practice to deal with this? To convert into a ne...

Auto-Initializing C# Lists

I am creating a new C# List (List<double>). Is there any way, other than to do a loop over the list, to initialize all the starting values to 0? Thank you. ...

Looping Over Dictionary in C#

I realize that you cannot iterate over a Dictionary in C# and edit the underlying Dictionary as in the following example: Dictionary<Resource, double> totalCost = new Dictionary<Resource, double>(); // Populate the Dictionary in here - (not showing code). foreach (Resource resource in totalCost.Keys) { totalCost[resource] = 5; ...

Cocoa-Touch: Quick way to sum a property in all objects within an NSSet?

I may very well be confusing this with the Cocoa (Mac OS X) side of things so it may not exist in Cocoa-Touch...but I thought there was a way to quickly ask a NSSet to poll its members and return a sum of say an NSInteger property in each of its objects? Closest I can find is objectEnumerator whereby I suppose I could rifle through each...

Expose multiple collections as a single collection

I have run into a problem w/ my model for databinding in WPF. I have an object which has a collection of objects (Variable), and each in turn has yet another collection of objects (VariableCode). What I need to be able to do is somehow expose a single collection from the highest level object - which is a fusing of the lowest level co...

How do I model multi-variable function?

We know that Map interface models function abstraction in math. How should I model multi-variable function? For example, to model f(x, y, z), I have two options: Map<List<Integer>, Integer> f1; or Map<Integer, Map<Integer, Map<Integer, Integer>>> f2; Which one do you think is better? Thanks, ...

Cost of len() function

What is the cost of len() function for Python built-ins? Is it same for all built-ins? (list/tuple/string/dictionary) ...

deleting embeddable object from collection struts java

Hello, I am having issues deleting value-type embeddable objects from a collection in struts2. <display:table name="parent.collection" requestURI=""> <display:column property="entry" /> <display:column property="date" sortable="true" defaultorder="ascending"/> <display:column> </display:table> i am using the above di...

What is the easiest way to foreach through a List<T> removing unwanted objects?

In my application, _collection is a List from which I need to remove all User objects which do not match the criteria. However, the following code gets an invalid operation error in its second iteration since the _collection itself has been changed: foreach (User user in _collection) { if (!user.IsApproved()) { _collect...

Implement a parent-child class hierarchy

I'm finding it difficult to find a decent example on how to implement a parent-child hierarchy class. I have a treeView control that I want to convert into a class hierarchy, adding extra data to each node and be able to easely iterate over each parent's nodes using IEnumerable. public IEnumerable<Node> GetAllChildsFromParent(Node paren...

Creating an array that contains only objects of a given class

Ok, so I have the code below (Objective-C FYI) and I was wondering if I want to create an NSMutableArray of c_data objects, how would I go about doing that? It's sort of like declaring a List<c_data> cData in C#. @interface c_data : NSObject { double value; int label; int ID; } @property double value; @property int label...

What are the differences between the two common implementations of a queue?

In Java, one of the implementations of queue is "circular array" and the other one is "linked list". What are their differences? ...

Rendering a Heterogeneous Collection of View Models in Silverlight 2

I have a hierarchy of view models representing formatted content: public abstract class ContentPartViewModel : ViewModel { } public class TextContentPartViewModel : ContentPartViewModel { public string Text { ... } } public class TitleContentPartViewModel : TextContentPartViewModel { } public class HyperlinkContentPartViewModel :...

collection counter in rails partials

Hi All, I'm rendering a partial in a collection like this : <%= render :partial => 'issues/issue', :collection => @issues %> Inside the partial, I want to render a element unless it's the last in the collection. I could of course, render the partial like this <%= render :partial => 'issues/issue', :collection => @issues, :locals =>...

In C# .NET, is there a reason for no copy constructor for StringDictionary?

I apologize if this is a dumb question, but hear me out: Dictionary<string, string> genericDict = new Dictionary<string, string>; genericDict.Add("blah", "bloop"); // Use the copy constructor to create a copy of this dictionary return new Dictionary<string, string>(genericDict); In the above code sample, I can create a copy of a gener...

Java - Collection Selection

What generics collection class can I use that provides both mapping and array-like functionality. For example, I want to map a String to a Double and I want to reference the value using the key as the index. collection[key] = collection[key] + double Does the Google collections library provide such functionality? Thanks. ...

NHibernate join table mappings

I have an interesting issue, which I can't seem to find a satisfying answer for. It concerns join tables. Basically (I'm sure this has been out here in some form or another, but I cant find it) I have 3 tables. A Person table, Address table, PersonAddress.. Person PersonID Name Age etc.. Address AddressID AddressLine1 AddressLine...

How to make a custom WPF collection?

I'm trying to create a custom set of classes that can be added to a WPF control through XAML. The problem I'm having is adding items to the collection. Here's what I have so far. public class MyControl : Control { static MyControl() { DefaultStyleKeyProperty.OverrideMetadata(typeof(MyControl), new FrameworkPropertyMetad...