collections

Reassignment to a val in Scala

Hello, I am doing a training exercise in Scala and getting this val reassignment error. I don't see where I am reassigning a new value to a val class personTest { val alf = Person("Alf", 30, List(EmailAddress("[email protected]"))) val fredrik = Person("Fredrik", 33, List(EmailAddress("[email protected]"), EmailAddress("fvr@...

Check if collection is empty or not

public ActionResult Create(FormCollection collection, FormCollection formValue) { try { Project project = new Project(); TryUpdateModel(project, _updateableFields); var devices = collection["devices"]; string[] arr1 = ((string)devices).Split(','); int[] arr...

Which Delphi data structure can hold a list of unique integers?

When I approach Java problems, I use the collection pattern. However, doing it in Delphi is quite a nightmare since there is no Integer object to handle things. I need a data structure that holds numbers. I want to be able to add numbers, remove numbers, and check the contents of the collection, and each number must be unique. I'm not...

Are the keys in a Dictionary<TKey, TValue> immutable?

I get a Dictionary<string, string> back from an API but depending on certain rules need to modify some of the key names. Before I head down the road of copying to a new Dictionary I just wanted to confirm that the keys in a Dictionary<TKey, TValue> are immutable. ...

Equals() contract for C# Dictionary / IDictionary vs equals() contract for Java Map

Nostalgic for Collections.unmodifiableMap(), I've been implementing a read-only IDictionary wrapper based on this discussion, and my unit test quickly ran into a problem: Assert.AreEqual (backingDictionary, readOnlyDictionary); fails, even though the key-value pairs match. I played around a little more, and it looks like at least (tha...

List implementation that is both a Set a List (sequence)?

I'm in the position of extending LinkedList and implement Set, so that I have a list with no duplicates. I'm wondering if such an implementation doesn't exist already? All I'm planning to do is to override the add(e) method to first look-up the element, and if present don't add it. Something like: add(E){ if(get(E) == null) super.ad...

What Java Collections library do you recommend?

I've inherited a team and a (Java) code base. The code base makes use of a lot of explicit for each loops. I'd like to replace those (edit: in future code) with something like Commons Collections Transformers and Predicates and its collect and transform methods. However, Commons Collection isn't generic. The rest of my code base, whate...

What's differences between every declaration and what's the implications on every one?

List listOne = new LinkedList<Shxx>(); List<Shxx> listTwo = new LinkedList<Shxx>(); List listThree = new LinkedList(); List<Shxx> listFour = new LinkedList(); ...

Java Iterate Over Collection

I have a practice project which I need help with. It's a simple MailServer class. Here's the code: import java.util.ArrayList; import java.util.List; import java.util.Iterator; import java.util.HashMap; import java.util.TreeMap; import java.util.Collection; import java.util.Map; public class MailServer { private HashMap<String, Arr...

Are there drawbacks to creating a class that encapsulates Generic Collection?

A part of my (C# 3.0 .NET 3.5) application requires several lists of strings to be maintained. I declare them, unsurprisingly, as List<string> and everything works, which is nice. The strings in these Lists are actually (and always) Fund IDs. I'm wondering if it might be more intention-revealing to be more explicit, e.g.: public class ...

doubt in collections

what is the difference among list, queue and set? ...

How do I have to add a collection of products in Magento?

Hi guys, I need to add about 100.000 records in my Magento Store. I have already the function that helps me to add a product but I need to improve it using the collections of products. This is my custom function: public function Products($data){ try{ foreach($data as $record){ $product = Mage::getSingleton('c...

Is Google Guava "harder" to use than Apache Collections?

I'm thinking of asking my team, of mixed skill levels, to use Google Guava. Prior to Guava, I'd have used the Apache Collections (or its generified version). Guava, as opposed to Apache Collections, seems to be stronger in some ways, but perhaps less easy to use for less experienced programmers. Here's one area where I think might exemp...

Recipe: copy one collection to another (member remap)

As short as possible, I have: class X { int p1; int p2; int p3; string p4; } class Y { int a1; int a2; string a3; string a4; } list<X> XLIST; list<Y> YLIST; and I want to shorten this: foreach (X x in XLIST) { Y y=new Y(); // arbitrary conversion y.a1=x.p1; y.a2=x.p2-x.p1; ...

Scala: good way to keep pairs of strings

Hey fellas, What is a neat way to hold pairs of strings which are not necessarily key-values (might have duplicate keys), for a small collection? List[List[String]] works obviously but looks dirty. Cheers Parsa ...

Java: collection that allows objects with a custom annotation

I'd like to annotate some classes with a @MyEntity annotation public @interface MyEntity {} @MyEntity public class MyClass { ... } And define a collection where only classes with that annotation are allowed (with no need to define them as public class MyClass implements XXX): List<MyEntity> list = new ArrayList<MyEntity>(); list.add...

How to print a list with a different separator from the comma?

I keep on copy-pasting the following in my programs. I'm wondering if anyone of you uses similar code, perhaps in a library to achieve the same. @Override public String toString() { String ret = prefix; boolean first = true; for (Component child : children) { if (!first) { ret += " " + separator + " "; ...

Speed issues with ReaderWriterLockSlim and Garbage Collection

I have an example piece of code the illustrates issues in my code when GC.Collect is carried out on a class having a ReaderWriterLockSlim member variable. The GC.Collect takes between 2 and 3 seconds to run. I need to carry out GC at regular intervals because my applicaton is extremely memory intensive. namespace WpfApplication12 { ...

Write code list collection to string in c#

HI all I have problem when trying to convert list collection string to one line string. But for each item i must edit with specific format. Example List<string> items = new List<string>(); string result = string.Empty; items.Add("First"); items.Add("Second"); items.Add("Last"); result = string.Join(",", items.ToArray()); Console.Writ...

C#: Generic members in non-generic types?

I have a custom control which contains a list of objects. The control is instantiated by the visual designer and then configured in code. The control is a grid which displays a list of entities. I have an initialise method like this. public void Initialise(ISession session, Type type, ICollection<IPersistentObject> objs) IPersisten...