equals

PropertyChangeSupport and equals method

I'll try to explain my problem as clear as possible :). I am using PropertyChangeSupport to notify registered views for changes in the properties. One of the property is an object which properties are changed every view seconds. I don't want to create for this particular object new instance every time it is being updated (for the propert...

Force a class to override the .equals method

I have a bunch of class who implement a common interface : Command. And this bunch of class goes to a Map. To get the Map working correctly, I need to each class who implements Command to override the Object.equals(Object other) method. it's fine. But i whould like to force the overriding of equals. => Have a compilation error when ...

Overriding HashMap equals method in Java

I noticed in the source code for HashMap it lists the equals method as final. Why is it that when I override it I do not get a compile error? public class Test extends HashMap<Object, Object> { @Override public boolean equals(Object o) { return false; } } Java HashMap equals method: public final boolean equals(O...

Correctly synchronizing equals() in Java

I have the following class which contains only one field i. Access to this field is guarded by the lock of the object ("this"). When implementing equals() I need to lock this instance (a) and the other (b). If thread 1 calls a.equals(b) and at the same time thread 2 calls b.equals(a), the locking order is reverse in the two implementatio...

Google App Engine, JDO, and equals/hashCode

I've got an app in Google App Engine that was working fine. I realized that one on of my JDO-enhanced objects that I forgot to implement equals and hashCode (I need to use the object in a set). So I did. I didn't really do anything special in these implementations, in fact I just used Eclipse to generate them. Like so: @PrimaryKey @Pers...

whats the difference between ".equals and =="

i switched lecturers today and he stated using a weird code too me. he says its better. when i asked why, he asnwered "because it is!" so much for that. so heres an example: if (o1.equals(o2)) { System.out.println("Both integer objects are the same"); } instead of what im used too: if (o1 == o2) { System.out.println("Both inte...

Does Dictionary.Equals() have an implementation?

Hi all, I have a Dictionary which I am comparing to another Dictionary (variables typed as IDictionary). Doing d1.Equals(d2) yeilds false. Writing my own code below yields true. Both are System.Collections.Generic.Dictionary. Am I missing something or does Dictionary not have an Equals implementation that compares keys/values? priv...

C#: What's the best way to compare Double and Int?

Hello everybody, The following code in C# doesn't work: int iValue = 0; double dValue = 0.0; bool isEqual = iValue.Equals(dValue); So, the question: what's the best way to compare Double and Int? -- Best Regards, Murat ...

Is this a good/efficient idiom for implementing Equals and equality/inequality operators?

I have had a few problems getting this right, so I wanted to ask if anyone has any feedback on whether this is an efficient way to implement the Equals method and equality/inequality operators for a custom immutable class. These operators are called very frequently by my program, so I want to make sure I get them right. class MyObj { ...

C#: String.Equals vs. ==

I recently was introduced to a large codebase and noticed all string comparisons are done using String.Equals() instead of ==. What's the reason for this, do you think? ...

Java: implementation of notification provider vs. hashCode-driven Map

I have implemented abstract generic provider for notification bunch of generic listeners E, descendants have to override notifyListener(E) with specific notification code. For backing list of listeners I choose WeakHashMap<K,V>. Listeners must be held as weak references: abstract public class NotificationProvider<E> { private Map<E...

toString(), equals(), and hashCode() in an interface...

So, I have an interface with a bunch of methods that need to be implemented, the method names are irrelevant. The objects that implement this interface are often put into collections, and also have a special toString() format that I want them to use. So, I thought it would be convenient to put hashCode(), equals(), and toString() into ...

Most compact way to compare three objects for equality using Java?

What's the most compact code to compare three objects for (semantic) equality using Java? I have a business rule that the objects must be unique i.e. A is different to B, A is different to C and B is different to C. Assume that the objects are all of the same class and have correctly overridden equals and hashCode methods. A slight wrin...

C# - How to override GetHashCode with Lists in object

Hi, I am trying to create a "KeySet" to modify UIElement behaviour. The idea is to create a special function if, eg. the user clicks on an element while holding a. Or ctrl+a. My approach so far, first lets create a container for all possible modifiers. If I would simply allow a single key, it would be no problem. I could use a simple D...

C# overloading operator== versus Equals()

I'm working on a C# project for which, until now, I've used immutable objects and factories to ensure that objects of type Foo can always be compared for equality with ==. Foo objects can't be changed once created, and the factory always returns the same object for a given set of arguments. This works great, and throughout the code base ...

Java: .equals() failing for sets (JGraphT)

I can't figure out what's going wrong here. This test fails: @Test public void testSimpleCase() { assertTrue(JGraphtUtilities.graphEquality(ChooseRootTest.generateSimpleCaseGraph(), ChooseRootTest.generateSimpleCaseGraph())); } public static <V, E> boolean graphEquality(Graph<V, E> g0, Graph<V, E> g1) { boolean result = ...

Why say x = x in Python?

In this file, in the function cross_from_below(x, threshold), there is a line that says threshold = threshold. What's the point of this line? Does this do something differently than if this command weren't there? ...

Confusion with equal method

Whenever I use equals() method with two different StringBuffer objects, I get the result as false, but when I use equals() method with two different String objects, I get the result as true. Why? String s=new String("434"); String s1=new String("434"); System.out.println(s.equals(s1));//true StringBuffer s=new StringBuf...

Best way to write an or is equal statement

Hello $mostamazingforumforfastanswersever. I have a quick silly question; what is the best way to write this : if ($curpageurl == "www.mysite.com/this" || "www.mysite.com/this/") { echo 'this is the this page'; } and if it isn't, then I need to call while (isset($somevariable) { echo '$somevariable'; } and if that variable isn'...

How should I implement this HashMap's equals and hashCode methods to represent an automaton state?

I want to put State objects (which are HashMaps with Character as key and State as Value into an ArrayList named allStates. Should I override the equals and hashCode methods here? Why? How? This code is for the Automaton and State classes I've built so far: class State extends HashMap<Character, State>{ boolean isFinal; boolean isIni...