equals

Matching Class arrays

I'm writing a routine to invoke methods, found by a name and an array of parameter Class values Matching the Method by getName works, but when trying to match the given Class[] for parameters, and Method.getParameterTypes(), I'm having trouble. I assumed that this would work: Class[] searchParams = new Class[] { float.class, String.c...

Jointure in linq with a regular expression

I'm actually using a join in linqtosql (via dblinq). I'm trying to include a regular expression in the join part of the linq query. from i in collectiona join j in collectionb on Regex.IsMatch(i.name, j.jokered_name) equals true (...) I agree i can push the RegExp check in the where part of the linq query, but i was wondering if it i...

C# how to calculate hashcode from an object reference.

Folks, here's a thorny problem for you! A part of the TickZoom system must collect instances of every type of object into a Dictionary<> type. It is imperative that their equality and hash code be based on the instance of the object which means reference equality instead of value equality. The challenge is that some of the objects in ...

Java - Is Set.contains() broken on OpenJDK 6?

Hey, I've come across a really strange problem. I have written a simple Deck class which represents a standard 52 card deck of playing cards. The class has a method missingCards() which returns the set of all cards which have been drawn from the deck. If I try and compare two identical sets of missing cards using .equals() I'm told they...

How to set equal width on divs with javascript

I've got five rows that looks like this: It's an ul with lis. I want the first li "text" to be equal on all rows. To do this I need to look for the widest li, then apply the new with to all li's. (ul > li > span & ul) Text > Li 1 | li 2 | Li 3 Textlong > Li 1 | li 2 | Li 3 Short > Li 1 | li 2 | Li 3 Longer13456 > Li 1 | li 2 | Li 3 I...

Help with string equality in Java

The following function accepts 2 strings, the 2nd (not 1st) possibly containing *'s (asterisks). An * is a replacement for a string (empty, 1 char or more), it can appear appear (only in s2) once, twice, more or not at all, it cannot be adjacent to another * (ab**c), no need to check that. public static boolean samePattern(String s1, St...

EasyMock - changing behavior for equals() and other Object methods

The EasyMock documentation is pretty clear that The behavior for the three object methods equals(), hashCode() and toString() cannot be changed for Mock Objects created with EasyMock, even if they are part of the interface for which the Mock Object is created. The code that I'm trying to test uses equals() to compare my mock object...

Overriding equals, hashCode and toString in a Clojure deftype

I'm trying to create a new type in Clojure using deftype to implement a two dimensional (x,y) coordinate, which implements a "Location" protocol. I'd also like to have this implement the standard Java equals, hashCode and toString methods. My initial attempt is: (defprotocol Location (get-x [p]) (get-y [p]) (add [p q...

Entity Framework 4 overwrite Equals and GetHashCode of an own class property

Hi, I’m using Visual Studio 2010 with .NET 4 and Entity Framework 4. I’m working with POCO Classes and not the EF4 Generator. I need to overwrite the Equals() and GetHashCode() Method but that doesn’t really work. Thought it’s something everybody does but I don’t find anything about the problem Online. When I write my own Classes and E...

why we need to override equals and hashcode in java and why cannot we use Object class implementation

guys please let me know, in real world why we need to override equals and hashcode and cant we use Object's equals and hashcode. ...

Overload the equals method in java

Possible Duplicate: Best practices regarding equals: to overload or not to overload? Does anyone overload the equals method in java? The overloaded method will be public boolean equals(final MyClass myClass) This will have the benefit of having the relevant comparison part (guts of the method) in another method. Details ar...

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...

Object reference not set to an instance of an object. ASP.NET (VB)

Hey, I have this problem when trying to read a session in another asp.net page. Object reference not set to an instance of an object. If Session("cne").Equals("") Then Response.Redirect("Default.aspx") End If I'm setting the session in the Default page with this code : Session("cne") = cne.Text Thanks. ...

What is the order precedence of a = b == c in JavaScript?

var clicked = $(event.currentTarget || target); var clickedIsActive = clicked[0] == this.active[0]; I'm fairly new to js, and while attempting to read through some jQuery code, I came across the above section. What is the precedence for the second line? Is it: var clickedIsActive = (clicked[0] == this.active[0]); Or is it someth...

Implementing custom comparison with CustomComparison and CustomEquality in F# tuple

Hello folks! I'm here to ask a specific topic - I really found few info about this on the web. I'm implementing a F# version of Minimax algorithm. The problem I'm having now is that I want to compare Leaf of my tree (data structure below). Searching the erros the VS gave to me I arrived to something like this: The tree type I used to h...

Union-ing two custom classes returns duplicates

I have two custom classes, ChangeRequest and ChangeRequests, where a ChangeRequests can contain many ChangeRequest instances. public class ChangeRequests : IXmlSerializable, ICloneable, IEnumerable<ChangeRequest>, IEquatable<ChangeRequests> { ... } public class ChangeRequest : ICloneable, IXmlSerializable, IEquatable<ChangeRequest>...

How to implement equals() and hashcode() methods in BaseEntity of JPA?

I have BaseEntity class which is a superclass of all JPA entities in my application. @MappedSuperclass public abstract class BaseEntity implements Serializable { private static final long serialVersionUID = -3307436748176180347L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "ID", nullable=false...

GetHashCode with transient/persistent entities

Hiya, I'm implementing a layered supertype that all my entities will be based on. I am currently working on the Equity methods Equals and GetHashCode. I have the following for GetHashCode: public override int GetHashCode() { if (!_hashCode.HasValue) { if (this.Id.Equals(default(T))) { ...

Strange behaviour of the Array type

scala> List(1,2,3) == List(1,2,3) res2: Boolean = true scala> Map(1 -> "Olle") == Map(1 -> "Olle") res3: Boolean = true But when trying to do the same with Array, it does not work the same. Why? scala> Array('a','b') == Array('a','b') res4: Boolean = false I have used 2.8.0.RC7 and 2.8.0.Beta1-prerelease. ...

Compare two object from the same class with tons of fields

I got two objects from the same class and I need to compare them field by field. The problem is that they have close to hundred fields and it would be helluva work to write that by hand. Do you know any way to do that the easier way? Reflections in Java could be a solution, but yet it seems to me like a hack. And I seek a C# solution af...