collections

Hibernate collections within collections

I have a Hibernate entity named Menu which has a collection of Groups, each group in turn has a collection of MenuItems. So as an example, a menu can be for a restaurant, groups can be Lunch and Dinner and the menuItems within these can be Pasta, Burger, Salad. The problem I'm having is that once i have created the menu and saved it ...

Hibernate Null values for @CollectionOfElements

I'm mapping a set of attributes to my entity using @CollectionOfElements. The goal here is to be able to provide a meta data list that can be used in a query to pull specific entries. I've figured out the mapping and how to run the queries I want. The problem is that hibernate won't persist null values! @CollectionOfElements() ...

How could I group duplicates from a collection?

I'm creating a program that parses a log file for a user's name and its GUID (Global unique identifier) using regular expressions. So far, my program extracts the data properly, and stores it in a two-column DataTable. Outputting its content with this code: foreach (DataRow dr in guids.Select("","guid")) { Console.WriteLine(...

Scala Immutable MultiMap

In Scala I would like to be able to write val petMap = ImmutableMultiMap(Alice->Cat, Bob->Dog, Alice->Hamster) The underlying Map[Owner,Set[Pet]] should have both Map and Set immutable. Here's a first draft for ImmutibleMultiMap with companion object: import collection.{mutable,immutable} class ImmutableMultiMap[K,V] extends immutab...

how can i get two consecutive values from Iterator

Here is my code that i tried to get two consecutive elements of Iterator. public void Test(Iterator<Value> values) { Iterator<Value> tr = values; while (tr.hasNext()) { v = tr.next(); x = v.index1; // u = null; if (tr.hasNext()) { u = tr.next(); y = u.index1; } els...

IEnumerable<T> vs T[]

I just realize that maybe I was mistaken all the time in exposing T[] to my views, instead of IEnumerable<T>. Usually, for this kind of code: foreach (var item in items) {} item should be T[] or IEnumerable<T>? Than, if I need to get the count of the items, would the Array.Count be faster over the IEnumerable<T>.Count()? ...

After join, cannot filter by attribute qty - getting products from inventory that are in stock

Hi, You have been so helpful in the past that I keep coming back searching for help and learning. This time I am trying to get all products that have a quantity greater than 1 and that are in stock (is_in_stock = 1) $products = Mage::getModel('catalog/product')->getCollection(); //$products->addAttributeToSelect('*'); ...

What's missing from this strategy of choosing which C# collection to use?

Here's my strategy for choosing which C# collection type to use: if number of items in collection is fixed, then use an array, e.g.: string[] directions = new string[] { "north", "south", "east", "west" }; otherwise always use List<T> unless of course you need a more specialized collection, e.g. Stack<T>, Queue<T>, or Dictionary<TKey,...

LinkedHashMap signature

Looking at the JDK source code for LinkedHashMap, I noticed that this class is declared as: public class LinkedHashMap<K,V> extends HashMap<K,V> implements Map<K,V> {... why the redundant "implements Map<K,V>" (since HashMap already implements Map) ? I cannot imagine this is a typo... Thanks. ...

Automapper : mapping issue with inheritance and abstract base class on collections with Entity Framework 4 Proxy Pocos

I am having an issue using AutoMapper (which is an excellent technology) to map a business object to a DTO where I have inheritance off of an abstract base class within a collection. Here are my objects: abstract class Payment class CashPayment : Payment class CreditCardPayment : Payment I also have an invoice object which contains a...

Java Performance using Concurrency

How can I improve performance of this chunk of code ? What would be unit test case for the given problem statement ? Code: public class SlowDictionary { private final Map<String,String> dict = new HashMap<String,String>(); public synchronized String translate (String word) throws IllegalArgumentException {...

WPF Binding to Child Collection

Hello, if the parent's datasource has a child property that is a collection (let's say it is called ChildCollection) is there a trick to reference it? So, this code sample is basically what I am attempting to do. But when I use this approach I do not get any data to my child controls. <UserControl> <UserControl.Resources> ...

Convertion of Scala typed collection to Java with an unbounded wildcard, etc. Collection<?>

Problem: Need to implement interface from 3rd party Java library in Scala ... Collection<?> getItemPropertyIds() ... My solution is to use ...<here goes Iterable>.asInstanceOf[java.util.Collection[_]] val props:Map[Object,Property] = ... override def getItemPropertyIds()=props.keys.asInstanceOf[java.util.Collection[_]] Is t...

Is Dictionary<TKey, TValue> faster than LINQ on a List<T>?

I generally use List<T> for collections. But if I need a fast lookup on a collection, then e.g. in the following example I would use a Dictionary so I could look it up quickly by id: Dictionary<int, Customer> But since I can use LINQ to query the List<T> anyway, as below, is there any reason to go through the trouble of using a Dictio...

Unable to return collections or arrays from JAX-WS Web Service

I found that I was unable to return collections from my JAX-WS Web Service. I appreciate that the Java Collections API may not be supported by all clients, so I switched to return an array, but I can't seem to do this either. I've set up my web service as follows: @WebService public class MyClass { public ReturnClass[] getArrayOfStu...

Passing collection via asmx

Hi, I have a list of pairs (CarType(Enum), code(string)). Unfortunately in this collection codes are not unique. Van,C1 Van,C2 Pickup,C1 How to pass this collection via asmx webservice. Now I have KeyValuePair[] as parametr in webMethod [webmethod] public void DestroyCars(KeyValuePair<string, CarType>[] cars) { //implementation. }...

Hibernate Mapping problem with unrelated collection

Welcome, I've some problem with Hibernate mapping. Database structure: TableA -ID_A --PK TableB -ID_B --PK -ID_A -- FK -> TableA TableC -ID_C -- PK -ID_A -- FK -> TableA POJO structure: class TableA extends Pojo { /*Some Fields*/ } class TableB extends Pojo { TableA tableA; /*Some properties*/ } class TableC ex...

Java HashMap detect collision

Is there a way to detect collision in Java Hash-map ? Can any one point out some situation's where lot of collision's can take place. Of-course if you override the hashcode for an object and simply return a constant value collision is sure to occur.I'm not talking about that.I want to know in what all situations other that the previously...

C# Differences between the various System.Collection(.Generic) types

i am quite confused about the differences between the various types in the C# language. specifically IEnumerable IEnumerator ...

Json.NET and generic dictionaries

It seems impossible to (de-)serialize a generic dictionary using Json.NET out of the box. class KeyClass { public KeyClass(string p1, string p2) { prop1 = p1; prop2 = p2;} public string prop1 { get; set; } public string prop2 { get; set; } } class ValueClass { public ValueClass(string pa, string pb) { propA = pa; propB ...