collections

how to sort a Collection<T>?

Hi All I have a generic Collection and am trying to work out how I can sort the items contained within it. Ive tried a few things but I cant get any of them working. ...

Does The Clear Method On A Collection Release The Event Subscriptions?

I have a collection private ObservableCollection<Contact> _contacts; In the constructor of my class I create it _contacts = new ObservableCollection<Contact>(); I have methods to add and remove items from my collection. I want to track changes to the entities in my collection which implement the IPropertyChanged interface so I subs...

How to bind WPF TreeView to a List<Drink> programmatically?

So I am very new to WPF and trying to bind or assign a list of Drink values to a wpf treeview, but don't know how to do that, and find it really hard to find anything online that just shows stuff without using xaml. struct Drink { public string Name { get; private set; } public int Popularity { get; private set; } public Dr...

Two collections and a for loop. (Urgent help needed) Checking an object variable against an inputted String value. Nullpointerexception

Hi there, I'm relatively new to java, I'm certain the error is trivial. But can't for the life of me spot it. I have an end of term exam on monday and currently trying to get to grips with past papers! Anyway heregoes, in another method (ALGO_1) I search over elements of and check the value H_NAME equals a value entered in the main. W...

List<> capacity has more items than added.

List <string> ali = new List<string>(); ali.Clear(); ali.Add("apple"); ali.Add("orange"); ali.Add("banana"); ali.Add("cherry"); ali.Add("mango"); ali.Add("plum"); ali.Add("jackfruit"); Console.WriteLine("the List has {0} items in it.",ali.Capacity.ToString()); when I run this the Console displays: ...

Compile Error Using MutableClassToInstanceMap with Generics

I am getting the following compile error "The method putInstance(Class, T) in the type MutableClassToInstanceMap is not applicable for the arguments (Class, Number)" on the putInstance method call. Does anyone know what I am doing wrong?? Thanks! public class TestMutableClassToInstanceMap { public final MutableClassToInstanceMap<Nu...

C# - implementing GetEnumerator() for a collection inherited from List<string>

Hi, I am trying to implement FilePathCollection. Its items would be simple file names (without a path - such as "image.jpg"). Once the collection is used via foreach cycle, it should return the full path created by concatenating with "baseDirectory". How can I do that? public class FilePathCollection : List<string> { string baseDi...

Item's depth in ArrayCollection

Hi, is it somehow possible to get item's depth in ArrayCollection? ...

Special kind of queue

I am looking for something like a Queue that would allow me to put elements at the end of the queue and pop them out in the beginning, like a regular Queue does. The difference would be that I also need to compact the Queue from time to time. This is, let's assume I have the following items on my Queue (each character, including the dot...

How to use java.Set

I'm trying to make it working for quite some time,but just can't seem to get it. I have object Tower built of Block's. I've already made it working using arrays, but I wanted to learn Set's. I'd like to get similar functionality to this: public class Tower { public Tower(){ } public Tower add(Block k1){ //(...) //if block al...

Nhibernate get collection by ICriteria

Hello, colleagues. I've got a problem at getting my entity. MApping: <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Clients.Core" namespace="Clients.Core.Domains"> <class name="Sales, Clients.Core" table='sales'> <id name="Id" unsaved-va...

NHibernate - illegal access to loading collection error

I'm getting the error "Illegal acces to loading collection" when i'm trying to get a list of variants belonging to a certain product. The NHibernate mapping is as below; <list name="Variants" lazy="false" cascade="save-update" inverse="false" table="PluginProduct_ProductVariant"> <key column="ProductId" /> <index column="Ordinal" />...

Is there a fast concat method for linked list in Java?

How can I concat two linked lists in O(1) with Java via jdk1.6, google or apache commons collection or whatever? E.g. in the jdk there is only the addAll method which is O(n). Another feature I miss is to concat two lists where each of them could be in inverse order. To illustrate this assume two lists a->b->c and e->f->g could merged ...

How would I deep copy a vector in J2ME / BlackBerry?

How would I deep copy a vector in J2ME / BlackBerry? ...

How to detect if collection contain instance of specific type?

Suppose I create collection like Collection<IMyType> coll; Then I have many implelentations of IMyTypem like, T1, T2, T3... Then I want know if the collection coll contains a instance of type T1. So I want to write a method like public bool ContainType( <T>){...} here the param should be class type, not class instance. How to wri...

Generic Dictionary and generating a hashcode for multi-part key

I have an object that has a multi-part key and I am struggling to find a suitable way override GetHashCode. An example of what the class looks like is. public class wibble{ public int keypart1 {get; set;} public int keypart2 {get; set;} public int keypart3 {get; set;} public int keypart4 {get; set;} public int keypart5 {g...

Create and populate two-dimensional array in Scala

What's the recommended way of creating a pre-populated two-dimensional array in Scala? I've got the following code: val map = for { x <- (1 to size).toList } yield for { y <- (1 to size).toList } yield (x, y) How do I make an array instead of list? Replacing .toList with .toArray doesn't compile. And is there a more co...

PHPUnit - multiple stubs of same class

I'm building unit tests for class Foo, and I'm fairly new to unit testing. A key component of my class is an instance of BarCollection which contains a number of Bar objects. One method in Foo iterates through the collection and calls a couple methods on each Bar object in the collection. I want to use stub objects to generate a serie...

How to get the capacity of the ArrayList in Java?

Hi, Its known that Java ArrayList is implemented using arrays and initializes with capacity of 10 and increases its size by 50% . How to get the current ArrayList capacity not the Size of the ArrayList. Thx ...

What is the proper way to remove elements from a scala mutable map using a predicate

How to do that without creating any new collections? Is there something better than this? val m = scala.collection.mutable.Map[String, Long]("1" -> 1, "2" -> 2, "3" -> 3, "4" -> 4) m.foreach(t => if (t._2 % 2 == 0) m.remove(t._1)) println(m) P.S. in Scala 2.8 ...