collections

Wintellect Multi dictionary

Hello All, I am trying to use the Wintellect power collections. But I don't know how to travel thru the MultiDictionary. could you please post any examples about the same. Thank you, Harsha ...

iterating over scala collections in java

How I can iterating over scala collections in java? ...

Why can we change the unmodifiable list if we have the original one?

By looking at the code of Collections class, i got to know that when we are using the method unmodifiableList(List list) or unmodifiableCollection(Collection c) it is not creating a new object but it is returning the reference of the same object and overriding the methods which can modify the List [ add, addall, remove, retainAll ... ...

Building a generic collection class.

Hi all, I am building the following class to manage a dictionary. public class EnumDictionary<TKey, TValue> { private Dictionary<TKey, TValue> _Dict; public EnumDictionary(Dictionary<TKey, TValue> Dict) { this._Dict = Dict; } public TKey GetValue(TValue value) { ...

Easy way to filter elements from a collection in Java?

I want to write a method that removes all elements from a collection that follow a certain pattern. In functional languages, I would use filter() with a lambda expression. However, in Java, it seems I'm stuck with this: public void removeAllBlueCars() { LinkedList<Car> carsToRemove = new LinkedList<Car>(); for (Car c : cars) { ...

Comparison of C++ STL collections and C# collections?

I'm still learning C# and was surprised to find out that a List<T> is much more like a std::vector than a std::list. Can someone describe all the C# collections in terms of the STL (or if STL comparisons are difficult, standard conceptual data types with Wikipedia links? I expect the reference would be widely useful. A minimal list of...

Scala collection filter by type

Hi, im new to scala and ran into the following problem: I want to get a subcollection of an existing collection that only contains elements of a specific type. The following works: class C(val name : String) class D(name : String) extends C(name) { } val collection = Set[C](new C("C1"),new D("D1"),new C("C2"),new D("D2")) collection.c...

NHibernate Custom Collections hack works outside of a transaction, but not inside

Following the technique described here, I was able to populate a domain object that uses custom collections for its children. The relevant property mapping looks like this: <component name="Contacts" class="My.CustomList`1[[Domain.Object, DomainAssembly]], MyAssembly"> <set name="InnerList"> <key column="PARENT_...

Python: Testing if a value is present in a defaultdict list

I want test whether a string is present within any of the list values in a defaultdict. For instance: from collections import defaultdict animals = defaultdict(list) animals['farm']=['cow', 'pig', 'chicken'] animals['house']=['cat', 'rat'] I want to know if 'cow' occurs in any of the lists within animals. 'cow' in animals.valu...

aggregate sql data into business objects- sample code inside -

Do you see a better way to read data from sqlite database into business collections? These are 2 methods of my Repository. I want to get all Schoolclass entites with/without referencing Pupil entities (see Left outer join) Is there anything that I can improve ? Haven`t found any good tips about that scenario in google so I tried mysel...

How to handle nulls when using Java collection sort

Hi, When using Collection.sort in Java what should I return when one of the inner objects is null Example: Collections.sort(list, new Comparator<MyBean>() { public int compare(MyBean o1, MyBean o2) { return o2.getDate().compareTo(o1.getDate()); } }); Lets say o2 is not null but o2.getDate() it is, so should I return...

NHibernate gives me a PersistentGenericList<T> even though I've implemented IUserCollectionType

I am trying to use a custom collection on a business object via a collection factory class that implements IUserCollectionType. The relevant methods on this class are implemented like so: public object Instantiate(int anticipatedSize) { return new MyCustomCollection<T>() } public IPersistentCollection Instantia...

Any way to insert an anonymous array into a collection?

I've found plenty of entries here that say someFunc(new int[]{1,2,3}); works for calling methods and being used in a for/each loop. //====== How about for assignment into a collection? I've tried this: ArrayList<int[]> data = new ArrayList<int[]>(); data.add(new int[]{21, 19629}); and I get "identifier expected" and "illegal st...

How to do map inversion with Guava with non-unique values?

How can we do that with Guava? Notice the presence of List<K> in the return type since many keys can map to the same value in any normal map. public static <K, V> Map<V, List<K>> inverse(Map<K, V> map){ Map<V, List<K>> result = new LinkedHashMap<V, List<K>>(); for (Map.Entry<K, V> entry : map.entrySet()) { if(!result.con...

Why won't this cast?

public interface IMenuCollection<T> : ICollection<T> public class HTMLMenuCollection: IMenuCollection<HTMLMenu> This is my custom collection definition. I am trying to cast to it from another collection IList. IList<HTMLMenu> htmlMenuList = new List<HTMLMenu>(); ... HTMLMenuCollection tempColl = (HTMLMenuCollection)htmlMenuList; I ...

What is the most succinct Scala way to reverse a Map?

What is the most succinct Scala way to reverse a Map? The Map may contain non-unique values. EDIT: The reversal of Map[A, B] should give Map[B, Set[A]] (or a MultiMap, that would be even better). ...

Scala: Why does Seq.contains take an Any argument, instead of an argument of the sequence type?

So for example why does List(1,2,3,4).contains("wtf") even compile? Wouldn't it be nice if the compiler rejected this? ...

Understanding python object membership for sets

If I understand correctly, the __cmp__() function of an object is called in order to evaluate all objects in a collection while determining whether an object is a member, or 'in', the collection. However, this does not seem to be the case for sets: class MyObject(object): def __init__(self, data): self.data = data def _...

Check of two list have colliding element?

Is there a way to check if one list collides with another? ex: bool hit=false; foreach(var s in list2) { if (list1.Contains(s)) { hit = true; break; } } if (!hit) { ...

Where to find an overview of backed Collection methods/classes

I am trying to find an overview of all methods in the java.util package returning backed Collections (and Maps). The only ones easy to find are the synchronizedXX and immutableXX. But there are others like subMap(). Is there a more comfortable way to find out more about all util methods returning backed collections than to actually read ...