collections

How to test pair wise equality of two collections

How do I test whether two collections are equal as according each pair of elements being equal according to .Equals()? I find myself writing a little function (given below) which seems over the top. I imagine there must be a far simpler way to do this. bool ListsEqual<T>(IList<T> lhs, IList<T> rhs) where T : IEquatable<T> { if (lh...

Java: How to workaround the lack of Equatable interface?

Hello, everyone! As far as I know, things such as SortedMap or SortedSet, use compareTo (rather than equals) on Comparable<?> types for checking equality (contains, containsKey). But what if certain types are equatable by concept, but not comparable? (Hash codes, memory addresses, ...) I have to declare a Comparator<?> and override th...

Ordered List of Keyvaluepairs?

Is there an collection in .net that allows the storing KeyValuePair<string, string> that keeps the order of inserting? OrderedDictionary looked promising, but seems to be rather lacking. Now I'm looking into IOrderedEnumerable>, but I can't seem to find any implementation except for ISortedDictionary, but that's not what I want. No sorti...

Java - HashSet best way to implement iterator that does not support remove()

Hey, I have a class which uses a HashSet and I want the class implement Iterable, I do not, however, want the class iterator to support the remove() method. The default iterator of HashSet is HashSet.KeyIterator which is a private class within the HashSet class, so I cannot simply extend it and override the remove method. Ideally ...

NHibernate: Querying on collection of strings (collection was not an association)

Hello all. I have this class that I want to persist with NHibernate. It has one collection, an IList, aggregating strings, rather than class instances, called DestinationCountryCodes. public class RoutingRule { public virtual long Id { get; set; } public virtual MessageType MessageType { get; set; } public vi...

What options do i have to make this code thread safe?

I have this segment of code , a lot of things skipped for brevity but the scene is this one: public class Billing { private List<PrecalculateValue> Values = new List<PrecalculateValue>(); public int GetValue(DateTime date) { var preCalculated = Values.SingleOrDefault(g => g.date == date).value; ...

Modify Dictionary values

.NET 2 The standard: foreach(KeyValuePair<int,int> entry in MyDic) { entry.Value += i; // does not work :( i++; } Recommendations? ...

push in priorityqueue

I want to push some int to a priorityqueue but i can't! i used the queue.add() code but this code will return the sorted queue,please help,thank you! ...

Collection should return null or empty upon a Db load ending with no records found?

Hi, If you have a method that queries the Db and returns a collection populated with the records found, what should be returned upon no records found? A new collection with .Count == 0 or null Is there any consensus on this? Or returning null and returning an empty collection should have different meanings? Thanks ...

Complex data structure in ViewModel layer of the MVVM

I have large collection of MyFile objects which are linked in all kind of ways between each other like spaghetti. In addition, from this collection I create smaller subcollections of some items that are equal by some criteria. (for example all files with the extension .txt, all files that belong to certain directory etc...) Basically I ...

Is there a C++ equivalent to Java's Collection interface for STL container classes?

I would like to pass arbitrary container as an argument of function and iterate over it (no erasing nor pushing elements). Unfortunately it looks like there is no standard way of doing this. First solution which comes to my mind is an interface (let's call it CollectionInterface) implemented by classes that will wrap STL containers. so...

Java collections design question: why standalone methods in Collections? why not add to the list interface?

For all the methods in Collections that take a List as their first argument, why aren't those methods simply part of the List interface? My intuition is: given a List object, that object itself should "know" how to perform on itself operations such as rotate(), shuffle(), or reverse(). But instead, as a Java programmer, I have to revi...

java Vector : Warning while adding objects

When I am adding a String object into a vector then the following warning occurs.Why? TestCollectionsMain.java:14: warning: [unchecked] unchecked call to add(E) as a member of the raw type java.util.Vector vec.add("M"); ...

which methods of Java Vector class are synchronized?

Hi, Which of the methods of java Vector class is synchronized.Since there is no explicit synchronized in javadoc. ...

Difference between Java's Vector.add() and Vector.addElement()?

Please explain the difference between the Vector.add() method and the Vector.addElement() method, along with a sample code snippet ...

java Arralist size?

Hi, As we know ArrayList increases its size by 50% when elements are added(100% incase of Vector).Where can we find the implementation for this behavior? Thx ...

Map of Maps data structure

Hi, The MultiValueMap class (Apache commons collections) makes it easy to work with a Map whose values are Collections. I'm looking for a a class that makes it easy to work with a Map whose keys are objects and values are Maps. I'm using Java 1.4, so can't use Google Collections or generics. Thanks, Don ...

Swap CSS style of a group of elements on click

I found a thread, http://stackoverflow.com/questions/195951/change-an-elements-css-class-with-javascript, that is along the lines of what I'm going for, but I don't know how to implement it. I have a page with 4 input buttons and two CSS styles: "Selected" and "notSelected". One button will be hard coded initially as "Selected". When ...

push to array vb.net 2008

the message was variable j is used before it have been assigned value.If in php language, it's not a problem at all. Dim j() As String Dim i As Integer If (i = 1) Then j(0) = "x" Else j(0) = "d" End If ...

C# generics and collection

Hi I have two objects MetaItems and Items. MetaItem is template for objects and Items contains actual values. For example "Department" is treated as meta-item and "Sales", "UK Region", "Asia Region" are treated as items. Additionally I want to maintain parent-child relation on these meta-items and items. I have following code for s...