collections

c# inheriting generic collection and serialization…

Hi Guys with reference to c# inheriting generic collection and serialization… question If you are providing a paged collection it is useful to pass back the total available so the client can set up they paging control. Does anyone know a nice way to achieve? Also why is this "By Design" seems pointless. Cheers. ...

Convert IEnumerable to EntityCollection Entity Framework 4

I have generated the following code with Entity Framework 4 for a navigation property: <XmlIgnoreAttribute()> <SoapIgnoreAttribute()> <DataMemberAttribute()> <EdmRelationshipNavigationPropertyAttribute("Diagnose", "Request_Comments", "Comment")> Public Property Comments() As EntityCollection(Of Comment) Get Return CType(Me,I...

Bind a Java Collection to xQuery sequence from xQuery

declare function Error:toString($this as javaObject) as xs:string external; the previous binds a return String() to xs:string. is it possible to return a collection and bind it to an xQuery Sequence, say the following declare function Error:toList($this as javaObject) as squenceType external; so that it can be run through a flwr? ...

Efficient algorithm for finding spheres farthest apart in large collection

I've got a collection of 10000 - 100000 spheres, and I need to find the ones farthest apart. One simple way to do this is to simply compare all the spheres to each other and store the biggest distance, but this feels like a real resource hog of an algorithm. The Spheres are stored in the following way: Sphere (float x, float y, float...

What is wrong with this design? Overriding or overloading of java.util.HashMap

This question was asked to me in MS interview. I wanna know the exact design issue in this piece of code. Code was already given, needed to find the design issue. I have class MyHashMap which extends java HashMap class. In MyHashMap class I have to keep some information of employees. Key in this map will be firstName+lastName+Address...

How to use opencsv with my collection (list) ?

I need to parse 2 dimensional list, here is my schema list : list (size=12) ->[0] = "export.SampleJ:12432" --> id = 12432 --> dateCreatedSample = "Tue Feb 03 19:04:23 CST 2009" --> ttId = 0 --> chipId = 1012 --> ... ->[1] = "export.SampleJ:12433" --> id = 12433 --> ... ->[2] ... I tried : List<Strin...

Why is Java's AbstractList's removeRange() method protected?

Does anyone have any idea, why removeRange method in AbstractList (and also in ArrayList) is protected? It looks like a quite well-defined and useful operation, but still, to use it, we're forced to subclass the List implementation. Is there some hidden rationale? Seems quite inexplicable to me. ...

How to join two collections by index in LINQ

What could be a LINQ equivalent to the following code? string[] values = { "1", "hello", "true" }; Type[] types = { typeof(int), typeof(string), typeof(bool) }; object[] objects = new object[values.Length]; for (int i = 0; i < values.Length; i++) { objects[i] = Convert.ChangeType(values[i], types[i]); } ...

What structure would you recommend to use to hold a bunch of String-Object associations?

it'll be used to key-map String-Object value. let's say, myObject = struct.get("first"); ordering is not important. parameterized Hashset or anything better? if that doesn't bother you, can you give me an example of static initialization along with the declaration, of a simpler structure, eg (String-String key mapping)? ...

Properties of collection type

When the property have some collection type like public IList<MyItemClass> MyList{ get; } IMHO, it's better to return empty collection instead of null value. There are many ways to implement such functionality. public IList<MyItemClass> MyList{ get; private set; } public MyClass(){ MyList = new List<MyItemClass>(); } This way ...

iterator over nested collections

Hi all, I have two data structures in Java: One is called DebateAssignment and has 5 DebateTeam objects, each associated with a specific enum that includes {JUDGE, PROP1, PROP2, OP1, OP2} In another class I use List<DebateAssignment> and I want to create an iterator that will point to a specific DebateTeam in a specific DebateAssign...

Add value in listbox from list of values without using for loop

I have used a ListBox in my Windows application. I got the variable iplist from a WCF server. After that i addded that list in my ListBox, but it generated an error: "Collections modified, enumuration may not execute". How might I solve this problem? My code is: foreach (ClsPC pc in iclsobj.GetPC()) { if (listBox1.Items.Count == ...

WCF OperationContract - which generic collection type should I expose?

I have a WCF web service that has a method that returns a generic collection. Now, my question is: Should I expose it as ICollection<T>, List<T>, IList<T>, IEnumerable<T> or something else? I suppose that List<T> is out of the question since I want to avoid CA1002 errors, but the underlying type will be a List<T>. I am really interes...

Fill an array with clones of a single object

What is a quick and easy way to fill a Java array with clones of a single object? e.g. after: Rectangle[] rectangles = new Rectangle[N]; fillWithClones(rectangles, new Rectangle(1, 2, 3, 4)); the rectangles array would contain N distinct Rectangle instances, initialised with the same coordinates. I am aware of the flaws of Object.cl...

How to map count of collection to entity with fluent-nhibernate

With employees and subordinates - I want to load an employee with the count of subordinates in one query. public class Employee { public Name {get;set;} public int NumberOfSubordinates {get;set;} } Resulting SQL should look like : select e.name, (select count(*) from subordinate s where s.employee_id = e.id) NumberOfSubordin...

inheritance - how to access a subclass

I am trying to get an author from the BOOK class that extends the Item class. I have 3 classes as follows main() library Item(CD,DVD,Book) inheritance.. in library class i have a function called public Collection booksByAuthor(String author) i also have a hashset in library class that holds information on various books. What i wan...

find item in collection with closest date

if i have a collection of dates and values. I want to get the value that is either: Associated to the date in the collection if it doesn't exist, i want a linear interpolation between two points that are around the point i am looking for ao, here is a simple example. If the collection is: Date Value 1/1/2009 100 1/1/2010 ...

Java Get Multiple Items From Collection

Hello, Do Java collections have a built-in method to return multiple items from that collection? For example, the list below has n elements, some of which are duplicated in the list. How could I get all elements where the value = "one"? I realize it would be very easy to write my own method to achieve such functionality, I just wante...

Java: Implementing "repeat until no change" collection

I'm trying to implement an algorithm that repeatedly applies operations on a Collection (currently a List). In each step Elements can be added, removed and changed (using getters and setters) within the collection. The algorithm is repeated until no changes were made to the collection in the previous step. The order of elements is not ...

How can I concisely initialize a safe collection in C++?

Possible Duplicate: C++: Easiest way to initialize an STL vector with hardcoded elements I'm learning C++ right now, and I'm looking for a way to quickly and easily initialize a "safe" collection (like a vector) with different values for each element. I'm accustomed to Python's concise list/tuple initializations, and I want to...