collections

What sort does Java Collections.sort(nodes) use?

I think it is MergeSort, which is O(n log n). However, the following output disagrees: -1,0000000099000391,0000000099000427 1,0000000099000427,0000000099000346 5,0000000099000391,0000000099000346 1,0000000099000427,0000000099000345 5,0000000099000391,0000000099000345 1,0000000099000346,0000000099000345 I am sorting a nodelist of 4 no...

Whats the best way to make this Java program?

This the description of the program brief: Produce a software that keeps track of courses taught by lecturers at College. For each course, a course code and title needs to be recorded, as well as a list of lecturers taking that course needs to be recorded. The system should allow courses and lecturers to be added and removed from the...

Remove from a HashSet failing after iterating over it

I'm writing an agglomerative clustering algorithm in java and having trouble with a remove operation. It seems to always fail when the number of clusters reaches half the initial number. In the sample code below, clusters is a Collection<Collection<Integer>>. while(clusters.size() > K){ // determine smallest distance b...

How to name a collection of an interface?

The situation is as follows. public interface IFoo { } public abstract class FooBase : IFoo { } Now I need a collection of IFoo with some additional methods. public class IFooCollection : List<IFoo> { public void UsefullMethod() { } } The problem is that IFooCollection looks like an interface while it is a class. The options ar...

Java PriorityQueue removal of arbitrary elements performance

Say I have a java PriorityQueue (which java implements as a heap) that I iterate over to remove elements based on some criteria: PriorityQueue q = new PriorityQueue(); ... Iterator it = q.iterator(); while(it.hasNext()){ if( someCriterion(it.next()) ) it.remove(); } How long does each remove() operation take? I'm not sure ...

Is there a good way to handle conversions between arrays and strongly typed collections automatically?

Background: I have a big solution where hundreds of functions take strongly typed collections as inparameters and using them as return values. The solution references a generated proxy wich converts calls to a webservice that always returns collection in the format int[] or Order[] or wathever type it is. The proxy wraps them up as Int...

Which .Net Framework generic collection type will allow/provide this(key) functionality?

I'm wondering which collection-type in System.Collections.Generic will support this scenario, if there is one: Public Class MyCollectionBase(Of ItemType, KeyType) Inherits System.Collection.Generic.??? Default Public Shadows ReadOnly Property Item(ByVal key as KeyType) as ItemType Get .... End G...

Ruby Rails collection select is displaying blank "prompt" value?

I have a collection select like the following: <%= f.collection_select :region_id, Region.find(:all), :id, :name, { :prompt => 'Select a State/Province' }, :style => "width: 200px;" %> Sometimes the prompt from the :prompt option appears, but sometimes it does not. Does anyone know where I could begin to troubleshoot this? Maybe I h...

NHibernate doesn't save object's collection of items

I've got an Order class that contains OrderItems. When I save the Order class, the database is populated with the Order information, but none of the child OrderItems are saved to their respective tables. Here's what the Order mapping looks like: <class name="Order" table="Orders"> <id name="OrderID" column="OrderID" type="Int64" unsav...

Java Collections API Bug?

I've stumbled upon a bug in the Java Collections API, in Collections.java. Here’s the code verbatim from the JDK’s source. Just so you know, the JavaDoc version tag reads "1.106, 04/21/06". The method is located in line 638. public static <T extends Object & Comparable<? super T>> T max(Collection<? extends T> coll) { Iterator<? ex...

Best tutorial for the classes in System.Collections.Generic and System.Collections.Specialized namespaces?

I am looking for a book or article that goes into great level of detail on the generic Collections in .NET comparing performance and providing good advice on when to use the different collections. I am interested both in theoretical and real-life information. To be more concrete, have you seen any benchmarks comparing different collecti...

Nhibernate , collections and compositeid

Hi, banging my head here and thought that some one out there might be able to help. Have Tables below. Bucket( bucketId smallint (PK) name varchar(50) ) BucketUser( UserId varchar(10) (PK) bucketId smallint (PK) ) The composite key is not the problem thats ok I know how to get around this but I want my bucket class to contan...

What Java Data Structure/Solution would best fit these requirements?

I need a java data structure/solution that meets these requirements. What best fits these? 1) Object's insertion order must be kept 2) Object's must be unique (These are database objects that are uniquely identified by a UUID). 3) If a newer object with the same ID is added, the older version of the object should be over-written/r...

Lazily Initialization of a Collection

What's the best way to lazily initialize a collection, I'm specifically looking at Java. I've seen some people decide to do this in modification methods (which seems a bit yucky), as follows: public void addApple(final Apple apple) { if (this.apples == null) { apples = new LinkedList<Apple>(); } this.apples....

Why doesn't java.util.Set have get(int index)?

I'm sure there's a good reason, but could someone please explain why the java.util.Set interface lacks get(int Index), or any similar get() method? It seems that sets are great for putting things into, but I can't find an elegant way of retrieving a single item from it. If I know I want the first item, I can use set.iterator().next(), ...

Merged ObservableCollection

Hello, I have two ObservableCollections and I need to show them in one ListView control together. For this purpose I created MergedCollection which presents these two collections as one ObservableCollection. This way I can set the ListView.ItemsSource to my merged collection and both collections are listed. Adding works fine but when I ...

Use ResourceReader to create a HybridDictionary of resources.

I'm using a ResourceReader to read an embedded resx resource and I want to store it at a class level in a member variable. I'm want to store it as a HybridDictionary but don't see an easy way of doing it. Class member private IEnumerable<DictionaryEntry> dictionary; Class initalize Assembly asm = Assembly.GetExecutingAssembly(); Str...

C++ Initializing a Static Stack

Hello. I have some questions about initializing a static collection. Here is an example I coded that seems to work: #include <stack> #include <iostream> using namespace std; class A { private: static stack<int> numbers; static stack<int> initializeNumbers(); public: A(); }; A::A() { cout << numbers.top() <<...

C# Generics question

I am a bit rusty on generics, trying to do the following, but the compiler complains: protected List<T> PopulateCollection(DataTable dt) where T: BusinessBase { List<T> lst = new List<T>(); foreach (DataRow dr in dt.Rows) { T t = new T(dr); lst.Add(t); } return lst; } So as you can see, i am trying ...

Is there a Java 1.5 equivalent to the Predicate<T> methods in .Net?

Specifically, I'm looking for similarly clean notation to the Collection<T>.TrueForAll / Exists, etc. It feels smelly to have to write a foreach loop to inspect the return of a method on each object, so I'm hoping there's a better Java idiom for it. ...