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...
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...
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...
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 ...
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...
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;
...
.NET 2
The standard:
foreach(KeyValuePair<int,int> entry in MyDic)
{
entry.Value += i; // does not work :(
i++;
}
Recommendations?
...
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!
...
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
...
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 ...
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...
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...
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");
...
Hi,
Which of the methods of java Vector class is synchronized.Since there is no explicit synchronized in javadoc.
...
Please explain the difference between the Vector.add() method and the Vector.addElement() method, along with a sample code snippet
...
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
...
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
...
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 ...
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
...
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...