collections

NHibernate remove item in collection not working

I'm a newbie in the NHibernate world. Why this code works removing the territory from the collection: Country country; using (IUnitOfWork unit = UnitOfWork.Start()) { country = new Country(); country.Name = "My country"; Territory territory = new Territory(); country.Territories.Add(territory); country.Territories...

How to use Java Collections.shuffle() on a Scala array?

I have an array that I want to permutate randomly. In Java, there is a method Collections.shuffle() that can shuffle the elements of a List randomly. It can be used on an array too: String[] array = new String[]{"a", "b", "c"}; // Shuffle the array; works because the list returned by Arrays.asList() is backed by the array Collections.s...

Scala: how to merge a collection of Maps

I have a List of Map[String, Double], and I'd like to merge their contents into a single Map[String, Double]. How should I do this in an idiomatic way? I imagine that I should be able to do this with a fold. Something like: val newMap = Map[String, Double]() /: listOfMaps { (accumulator, m) => ... } Furthermore, I'd like to handle ...

Java - Collection with LinkedHashMap Attributes

Is there a collection class that has the LinkedHashMap quality of a predictable iteration order, but at the same time being indexable? LinkedHashMap implements a get() method, which returns the value object, but an indexof() method is not available. I'd like both. Thanks. ...

Question regarding return types with collections

Hi, In my BL (will be a public API), I am using ICollection as the return types in my Find methods, like: public static ICollection<Customer> FindCustomers() { Collection<Customer> customers = DAL.GetCustomers(); return customers; } Note the use of ICollection instead of Collection<>. Now in my GUI, I need to cast the results...

Scala immutable SortedSet are not "stable" on deletion

I've to deal with an immutable object in scala 2.7.5, and one of its member is an immutable Sortedset. I've no problem with addition, to synthetise, it gives: class MyClass[A](s:SortedSet[A]) { ... def + (elem:A):MyClass[A] { new MyClass(s + elem) } } And it works, since + operator is overload in trait sortedSet to return a...

Flex sorting of XMLListCollection subelements

In a Flex webapp, is there an easy way to go about applying a sort to the children of an XML element, based on the children's attributes? Example follows below: XMLListCollection: <a anotherProp="ABCDE">   <e prop="AB">1</element>   <e prop="BC">2</element> </a> <a anotherProp="FGEH">   <e prop="HF">3</element> ...

Indirect binding to child collections in XAML

Hi folks, I am currently using a Linq template with SubSonic3 to create my models. I have a simple Member class, which has a collection of Notes. A Note class has a PublishedDate and Title properties. I have a UserControl which has a collection of Members for its DataContext. There are two ListBoxes and a bunch of TextBoxes and other c...

Threadsafe and generic arraylist in c #?

Hello community, I want to have a generic thread safe collection and I saw that the Arraylist can easily be used thread safe by its static Synchronized method but what bugs me is that this ArrayList is not generic so when I want to use my objects I always have to cast them. Is there an easier way to do this? Also other list types would ...

Truncating a list to a given number of elements in java

There is any method to truncate a list in java, for example, to the first 100 elements, discarding the others? (I mean, without iterating and/or copying/deleting elements one by one) ...

C# linq, obtain most frequent item in collection

Hi, i am trying to obtain an item from a collection that occurs most frequently. if i were in SQL i would do something like this.. select top(1) extension from database.table group by extension order by count(extension) desc but im trying to do this using linq. Can someone assist with the translation? so far i have this but its not ...

How to modify, without any loop, a collections values to get a new collection?

How do I, without using any loop, modify the values in a collection to get a new collection with the modified values? For example, I'm having a Collection<String> and want to surround all Strings by parentheses. With a loop I would do this: Iterable<String> collection = getCollection(); ArrayList<String> newCollection = new ArrayList<...

ForeignKey and Django Template

Hey, So here's the problem. Imagine 2 models: Photographer and Photo. Strict rule is that there can be only 1 photographer for image, so in Photo there's a ForeignKey link to Photographer. class Photographer(models.Model): name = models.CharField(max_length = 40) class Photo(models.Model): name = models.CharField(max_length =...

.NET equivalent of Java's List.subList()?

Is there a .NET equivalent of Java's List.subList() that works on IList<T>? ...

When is an ArrayList preferable to an array in Java?

When should I use an ArrayList in Java, and when should I use an array? ...

Is there a bounded non-blocking Collection in Java?

The only one I can find is the BoundedFIFOBuffer, which is deprecated. Any others? ...

Collection with equal elements in .Net configuration section

I am interested, if it is possible to have collection with same elements in .Net configuration. Like this, for example: <RetrySettings> <RetryTurn PeriodBeforeRetry="0:05:00"/> <RetryTurn PeriodBeforeRetry="0:10:00"/> <RetryTurn PeriodBeforeRetry="0:30:00"/> <RetryTurn PeriodBeforeRetry="1:00:00"/> <RetryTurn ...

Add/remove blog post to "My favorites" page

Hi everyone. I am not familiar with js and jQuery, but need to create function to add/remove blog post to "My favorites" page and update counter of saved posts. Is any ready solution - plugin or snippet - to it? There is my html snippet. <h1><a href="http://www.example.com/add-post-to-my-favorites-page.htm" id="post_0064"><span class...

Bidirectional Hibernate collection mapping works in only one direction

My bidirectional collection mapping seems to only work in one direction. One job will have some number of costs. Each cost is associated with one job. The problem is, when I load a job, the costs collection is empty. However, when I load a cost and navigate from it to the job and then check the costs collection, it is properly filled. Ca...

How to accept a collection of a base type in WCF

The Setup I have a WCF service that exposes a base type (e.g. Animal) as well as a few derived types (e.g. Lion, Tiger, and Bear). Another type (e.g. Zoo) includes a property that is a collection of the base type. The base type is concrete, not abstract, so it is perfectly acceptable for the collection to contain instances of the base t...