I have a Collection<T>. I have a class TManager implementing an interface UManager which has a method getCollection() that needs to return a Collection<U> where U is an interface, and T is a class that implements U.
Aside from just casting it, e.g. return (Collection<U>)Tcoll;, is there a more correct way to handle this?
I control all ...
Let's say I have a simple class Cat in C#, with a Name property of type string. Now I need a collection class for my cats, so I decide to wrap a Dictionary<string, Cat> in a custom collection class. Basically, this class holds a private dictionary variable and adds or removes collection members as necessary, as well as indexing cats by t...
Hello
Does anyone know of any resources or books I can read to help me understand the various Java collection classes?
For example:When would one use a Collection<T> instead of a List<T>
and when would you use a Map<T, V> instead of aList<V>, where V has a member getId as shown below, allowing you to search the list for the element matc...
Hello,
I'm building a simple financial record-keeping application. The main window view model holds a list of Accounts. The view shows this list (in a ListView) along with a panel showing details about the currently selected Account.
At first, I bound the details panel and ListView's SelectedItem to the same property (of type Account)...
I wrote this handy, generic function for converting a collection of collections into a single set:
public static <T> Set<T> makeSet(Collection<Collection<T>> a_collection) {
Iterator<Collection<T>> it = a_collection.iterator();
Set<T> result = new HashSet<T>();
while (it.hasNext()) {
result.addAll(it.next());
}
return result;
}
...
istead of using Dictionary I want some type of collection class that can use a property of the value as the key, is there something like this?
...
Dear ladies and sirs.
Suppose I wish to inherit PersistentGenericBag, so that the actual type of my collection property is my custom type, which derives from PersistentGenericBag.
I see two possible ways to achieve this:
Introduce a new XML keyword, like mybag and somehow register my collection type with NHibernate to associated it w...
I have a collection
List<Employee> employees;
I use a DataTable, and load all the records (from MDB table) when Form1.Loads, and add these records to the List (Collection) so I work with them in memory.
Now, when I add a new employee to the collection, I should add it also to the mdb table... so I do:
DataRow rowemployee = Program...
I understand that collections like the Hashtable are synchronized, but can someone explain to me how it works, and at what point(s) access is restricted to concurrent calls? For example, let's say I use some iterators like this:
Hashtable<Integer,Integer> map = new Hashtable<Integer,Integer>();
void dosomething1(){
for (Iterator<M...
I'm working on a Flex 3 project, and I'm using a pair of XMLListCollection(s) to manage a combobox and a data grid.
The combobox piece is working perfectly. The XMLListCollection for this is static. The user picks an item, and, on "change", it fires off an addItem() to the second collection. The second collection's datagrid then di...
Framework Design Guidelines gives this advice:
DO NOT provide settable collection properties.
But if I don't, I can't see a way to XML serialize anything with a collection property. The XmlSerializer constructor complains,
"Unable to generate a temporary class
(result=1). error CS0200: Property or
indexer
'ConsoleApplication1...
I have something like this:
public class Foo {
public String id;
}
and
Vector<Foo> foos;
I need to get an object from the collection by id.
In C# I would do like this: foos.Where(o => o.id = 7)
What's the best way to do that in Java ?
...
Hi guys, I have a simple model like this one:
public class Order{
public int Id { get; set; }
... ...
public IList<OrderLine> OrderLines { get; set; }
}
public class OrderLine{
public int Id { get; set; }
public Order ParentOrder { get; set; }
... ...
}
What I do with Automapper is this:
Mapper.CreateMap<Order,...
I have an object that needs to be serialised as XML, which contains the following field:
List<String> tags = new List<String>();
XStream serialises it just fine (after some aliases) like this:
<tags>
<string>tagOne</string>
<string>tagTwo</string>
<string>tagThree</string>
<string>tagFour</string>
</tags>
That's OK as far a...
This is more a question of style and preference but here goes: when should I use scala.Array? I use List all the time and occasionally run into Seq, Map and the like, but I've never used nor seen Array in the wild. Is it just there for Java compatibility? Am I missing a common use-case?
...
I have Item objects which have a collection of attributes defined as a map. Now I want to retrieve all objects which have a specific attribute (by name, locale and value)
An expecert of the Item mapping:
<map table="ITEM_ATTRIBUTES" name="attributes">
<key column="item_id" foreign-key="fk_itmr_attrbts_itmrs"/>
<composite-index clas...
Hello, all!
I just want to know what the actual difference between Java Collection and Collections is.
Thanks in advance!
...
I was wondering what is the recommended way to expose a collection within a class and if it is any different from the way of doing that same thing when working with NHibernate entities.
Let me explain... I never had a specific problem with my classes exposing collection properties like:
IList<SomeObjType> MyProperty { get; set; }
Hav...
Possible Duplicate:
What are the reasons why Map.get(Object key) is not (fully) generic
This is similar to the question here, on java.util.Map. This question is left as a pointer to that question.
The List interface contains several methods which still accept an Object as parameter, after generics were introduced in Java 5. S...
I have a question about simplifying some Collection handling code, when using Google Collections.
I've got a bunch of "Computer" objects, and I want to end up with a Collection of their "resource id"s. This is done like so:
Collection<Computer> matchingComputers = findComputers();
Collection<String> resourceIds =
Lists.newArrayLi...