collections

How do I pass an ArrayList to method that takes a collection as an input

I want to pass some ArrayList<Integer> X into method a(Collection<Integer> someCol) that takes Collection<Integer> as an input. How can I do this? I thought an ArrayList was a Collection and thus I should be able to "just do it" but it seems that Collection is an interface and ArrayList implements this interface. Is there something I ca...

Testing a (big) collection retrieved from a db

I'm currently doing integration testing on a database and I have the following sql statement: var date = DateTime.Parse("01-01-2010 20:30:00"); var result = datacontext.Repository<IObject>().Where(r => r.DateTime > date).First(); Assert.IsFalse(result.Finished); I need to test if the results retrieved from the statement, where the giv...

Use LINQ, to Sort and Filter items in a List<ReturnItem> collection, based on the values within a List<object> property which is part of the ReturnItem class

This is tricky to explain. We have a DataTable that contains a user configurable selection of columns, which are not known at compile time. Every column in the DataTable is of type String. We need to convert this DataTable into a strongly typed Collection of "ReturnItem" objects so that we can then sort and filter using LINQ for use in ...

How to access java collection, just like the table in the database, having indexes and LINQ-like query's

This task occurs from time to time in my projects. I need to handle a collection of some complex elements, having different attributes, such as login, password_hash, role, etc. And, I need to be able to query that collection, just like I query a table in the database, having only partial data. For example: get all users, with role "user"...

ArrayList in java

ArrayList<String> veri1 = new ArrayList<String>(); String[] veri2 = {"Fatih", "Ferhat", "Furkan"}; How can i add "veri2" to "veri1" like one element ? I mean if i call veri.get(0), it returns veri2.. Regards. ...

Queue implementation with blocked 'take()' but with eviction policy

Is there an implementation with a blocking queue for take but bounded by a maximum size. When the size of the queue reaches a given max-size, instead of blocking 'put', it will remove the head element and insert it. So put is not blocked() but take() is. One usage is that if I have a very slow consumer, the system will not crash ( run...

Silverlight: DataContractSerializer cannot handle read only collection properties

Hey Stackoverflowers :) For our Silverlight Project (SL4) I'm using a Model which might contain Lists (IList<AnotherModel>). According to good practice and rule CA2227:CollectionPropertiesShouldBeReadOnly the IList properties don't have a public setter. We serialize the Model using the DataContractSerializer which is working. But when ...

Projections for Collections and Nested Projections

Hi, The first part is HOW TO PROJECT COLLECTIONS? Can We apply projections on collection elements? For e.g class User{ private address List<Address>; } class Address{ private String city; private String state; } Now can I just load the address attribute of User class? Using code like : criteria.setProjection(Proje...

Java Collections.rotate() with an array doesn't work

I have the following Java code: import java.util.Arrays; import java.util.Collections; public class Test { public static void main(String[] args) { int[] test = {1,2,3,4,5}; Collections.rotate(Arrays.asList(test), -1); for(int i = 0; i < test.length; i++) { System.out.println(test[i]); } } } I want th...

How can I display a list of three different Models sortable by the same :attribute in rails?

I have a Campaign model which has_many Calls, Emails, and Letters. For now, these are each a separate Model with different controllers and actions (although I would like to start to think of ways to collapse them once the models and actions stabilize). They do share two attributes at least: :days and :title I would like a way to repre...

Java ArrayList<Double> IndexOutOfBoundsException Problem

I've got a Problem with ArrayList. I need it to store a result. Because I want to start with element n I tried to give the ArrayList a capacity with ensureCapacity(n+1) to use set(n,x) but I get an IndexOutOfBoundsException. I tried to store n add(x) before the use of set and this works. So I'd like to know why it doesn't work on my w...

Java queue and multi-dimension array

First of all, this is my code (just started learning java): Queue<String> qe = new LinkedList<String>(); qe.add("b"); qe.add("a"); qe.add("c"); qe.add("d"); qe.add("e"); My question: Is it possible to add element to the queue with two values, like: qe.add("a","1"); // where 1 is integer So, that I know element "a" have value 1. ...

Sort collection of objects in HashMap based on the object's variable

I have a collection of book objects in a HashMap. The book has book_title, book_author, book_year_published, etc. I want to sort them based on the book_title which is a String, in both ascending and descending order, and display them on the screen. I wish someone can help me - I have been doing this for hours and still havent come up w...

Given a list of IP address, how do you find min, max ?

In Java, i have an arrayList of ip address. how do i find the min and max ? I have used the Collection.min() but it doesnt work given a case like : 192.168.0.1 <--min 192.168.0.250 192.168.0.9 <--max how do i return 192.168.0.1 <--min 192.168.0.250 <--max instead? ArrayList is retrieve from the database. I would need to d...

Order of elimination when using Distinct() on collection

If my collection is ordered by date will Distinct() take the first object in list of adjacent duplicates or is it not certain? I am using IEqualityComparer that does not consider date field but I want to be sure the latest date is always taken. ...

How do I create a collection_select in the View of a model that belongs_to another?

In the _form for creating a new Contact, I want to be able to create a drop-down which allows the User to select the Campaign the Contact will belong to. In the controller, I created a collection called @campaigns. And I tried to use the following but not getting it to work: <p> <%= f.label :campaign_id %><br /> <%= f.collec...

Can't create a Collection of Inherited Classes

Maybe I just don't know what to search for, but I'm going a little bonkers here trying to figure out how to create a collection of inherited classes. The base class, I will never use. Basically, I have 3 components: A base class call ImageFormat Child classes of ImageForm Code in Sub Main() to loop create a collection and loop through...

WPF PropertyGrid - adding support for collections

Hi, I am working on wpf propertygrid(PG) control and I want the PG to support collection type(IList, ObservableCollection etc.) properties. I am bit confused on how to keep track of selected item(of that collection) and pass that to client. Any ideas? If the solution makes use of the Open Source WPF PropertyGrid (http://www.codeplex.c...

Converting mutable to immutable map

private[this]object MMMap extends HashMap[A, Set[B]] with MultiMap[A, B] How convert it to immutable? ...

What are the requirements of a collection type when model binding?

I have been reviewing model binding with collections, specifically going through this article http://weblogs.asp.net/nmarun/archive/2010/03/13/asp-net-mvc-2-model-binding-for-a-collection.aspx However, the model I would like to use in my code does not implement collections using generic lists. Instead it uses its own collection classes...