collections

Java: Set<E> collection, where items are identified by its class

I need Set collection, where its items will be identified by items class. Something like ReferenceIdentityMap from Appache Collections, but on class scope i.e. two different instances of same class must be identified as same in this collection. You know, it is a violation of equals()/hashCode() identity principle but in occasional use ...

Why does sorted list have to have a key value pair?

If I just want a sorted list of just dates, integers, or doubles is it really necessary to have to define a SortedList(of Integer, Integer)? Seems intriguing to me, but may just be trival. I'd prefer just to use a SortedList(of Integer). (This question is in relation to the .Net generic collections) ...

Inheritance of TCollectionItem

I'm planning to have collection of items stored in a TCollection. Each item will derive from TBaseItem which in turn derives from TCollectionItem, With this in mind the Collection will return TBaseItem when an item is requested. Now each TBaseItem will have a Calculate function, in the the TBaseItem this will just return an internal v...

C++ stl collections or linked lists

I'm developing a OpenGL based simulation in C++. I'm optmizing my code now and i see throughout the code the frequently use of std:list and std:vector. What is the more performatic: to continue using C++ stl data structs or a pointer based linked list? The main operation that involve std::list and std::vector is open a iterator and loop ...

Java: jaxb Generircs

How can I get jaxb to bind to my Vector? I cannot seem to get it to bind a Vector that contains generics as it complains that it cannot recognize my class "shape" or any of its subtypes.. "[javax.xml.bind.JAXBException: class shape.shape nor any of its super class is known to this context.]"? import java.util.Vector; import javax.xml.bi...

How do I get product category information using collections in Magento

Hi guys - I am trying to output all the products from our Magento shop - the following code works however I also need to grab the category id & the parent category name too. Can anyone suggest how I can do this? Thanks in advance $product = Mage::getModel('catalog/product'); $productCollection = $product->getCollection() ->addAttrib...

Java - problems iterating through an ArrayList

Ok so I have an ArrayList (arrBok), which is full of book objects (the code is in Norwegian, so pay no attention to that please). I want to make a public method which iterates through all the objects in the arraylist. When I execute the code, it just seems to run in an infinite loop, not producing any return values. Here is the relevan...

Why is TreeSet<T> an internal type in .NET?

So, I was just digging around Reflector trying to find the implementation details of HashSet (out of sheer curiosity based on the answer to another question here) and noticed the following: internal class TreeSet<T> : ICollection<T>, IEnumerable<T>, ICollection, IEnumerable, ISerializable, IDeserializationCallback Without looking ...

Sorting and Re-arranging List of HashMaps

I have a List> which is straight forward representation of a database table. I am trying to sort and apply some magic after the data is loaded into List of HashMaps. In my case this is the only hard and fast way of doing it becoz I have a rules engine that actually updates the values in the HashMap after several computations. Here is a ...

Scala version of Rubys' each_slice?

Does Scala have a version of Rubys' each_slice from the Array class? ...

O(1) conversion from mutable.Map to immutable.Map?

Is there a way to convert (wrap) a mutable Map to immutable in O(1) time (that is, not by copying the values, but similar to what is done in JavaConversions) ...

Complicated collection changed to class - best way of handling it

In my project I use quite complicated (and nested) collection: List<Pair<List<Pair<double>>, double>> myCollection As I use it in whe same way in several places in my project, I would like to convert it to new class. But I have some doubts... What is the best way to handle this sort of collections, create an inner field and pass as p...

Rewrite arrays using collections

I have a task, which I was able to do with the use of simplest methods - arrays. Now I'd like to go further and redo it using some more complicated java features like collections, but I've never used anything more complicated than 2d matrix. What should I look at and how to start with it. Should Tower become a Collection ? And here's the...

How can I dynamically access user control attributes?

Im trying to create a "user control menu" where links to a page's usercontrols are placed at the top of the page. This will allow me to put several usercontrols on a page and allow the user to jump to that section of the page without scrolling so much. In order to do this, I put each usercontrol in a folder (usercontrols) and gave each...

best scala idiom for find & return

This is something I encounter frequently, but I don't know the elegant way of doing. I have a collection of Foo objects. Foo has a method bar() that may return null or a Bar object. I want to scan the collection, calling each object's bar() method and stop on the first one returning an actual reference and return that reference from the ...

Java List with Objects - find and replace (delete) entry if Object with certain attribute already exists

Hi there I've been working all day and I somehow can't get this probably easy task figured out - probably a lack of coffee... I have a synchronizedList where some Objects are being stored. Those objects have a field which is something like an ID. These objects carry information about a user and his current state (simplified). The point...

Convert Collection to List

Hello, I want to say how to convert a Collection to a List in Java ...

ASP.NET handling button click event before OnPreInit

Hello, I have a data access layer, a business logic layer and a presentation layer (ie. the pages themselves). I handle the OnPreInit event and populate collections required for the page. All the data comes from an SQL server database and I do not use caching. I handle a button click event to grab values from a form and insert a new o...

NHibernate. Initiate save collection at saving parent

Hello, colleagues. I've got a problem at saving 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-value="0"> ...

cast a List to a Collection

Hello, i have some pb. I want to cast a List to Collection in java Collection<T> collection = new Collection<T>(mylList); but i have this error Can not instantiate the type Collection ...