equals

Two columns must not equal each other in Rails

I'm creating a social network in Rails and I have a model like this: create_table "friendships", :force => true do |t| t.integer "user1_id" t.integer "user2_id" t.boolean "hasaccepted" t.datetime "created_at" t.datetime "updated_at" end The problem is that you cannot add yourself as friend, so I tried this in my...

Bit Array Equality

I need something a little more than the System.Collections.BitArray class in my application. Specifically, I need the bit array: To be immutable To implement equality using value semantics I created my own struct, largely copying the internals of the BitArray implementation. (Thanks, .Net Reflector!) I don't deal everyday with bitwi...

Equality relations in Scala

I just stumbled on one of Tony Morris' blog-posts about Java and a fundamental problem with the language: that of defining a bespoke equality-relation for a collection. This is something that I think is a big deal and wondered whether there was some scala solution. The classic issue manifests itself in thinking about, say, a trade. Let...

What's the best strategy for Equals and GetHashCode?

I'm working with a domain model and was thinking about the various ways that we have to implement this two methods in .NET. What is your preferred strategy? This is my current implementation: public override bool Equals(object obj) { var newObj = obj as MyClass; if (null != newObj) { return ...

Equal Height not working in Safari (jQuery)

$.fn.equalHeight = function () { var height = 0, reset = $.browser.msie ? "1%" : "auto"; return this.css("height", reset).each(function () { height = Math.max(height, this.offsetHeight); }).css("height", height).each(function () { var h = this.offsetHeight; if (h > height) { $(this)...

Equals method of System.Collections.Generic.List<T>...?

I'm creating a class that derives from List... public class MyList : List<MyListItem> {} I've overridden Equals of MyListItem... public override bool Equals(object obj) { MyListItem li = obj as MyListItem; return (ID == li.ID); // ID is a property of MyListItem } I would like to have an Equals method in the MyList objec...

C#/Java: Proper Implementation of CompareTo when Equals tests reference identity

I believe this question applies equally well to C# as to Java, because both require that {c,C}ompareTo be consistent with {e,E}quals: Suppose I want my equals() method to be the same as a reference check, i.e.: public bool equals(Object o) { return this == o; } In that case, how do I implement compareTo(Object o) (or its generic ...

Java: omitting a data member from the equals method.

public class GamePiece { public GamePiece(char cLetter, int nPointValue) { m_cLetter=cLetter; m_nPointValue=nPointValue; m_nTurnPlaced=0; //has not been placed on game board yet. } public char GetLetter() {return m_cLetter;} public int GetPointValue() {return m_nPointValue;} public int GetT...

KeyNotFound Exception in Dictionary(of T)

I'm about ready to bang my head against the wall I have a class called Map which has a dictionary called tiles. class Map { public Dictionary<Location, Tile> tiles = new Dictionary<Location, Tile>(); public Size mapSize; public Map(Size size) { this.mapSize = size; } //etc... I fill this dictionary tem...

Why does `Array(0,1,2) == Array(0,1,2)` not return the expected result?

As far as I understand, Scala's == defines the natural equality of two objects. I expected that Array(0,1,2) == Array(0,1,2) compares the natural equality e. g. checks if all elements of the array return true when compared with the corresponding elements of the other array. People told me that Scala's Array is just a Java [] which only...

FindBugs controversial description

Am I understanding it wrong, or is the description wrong? Equals checks for noncompatible operand (EQ_CHECK_FOR_OPERAND_NOT_COMPATIBLE_WITH_THIS) This equals method is checking to see if the argument is some incompatible type (i.e., a class that is neither a supertype nor subtype of the class that defines the equals ...

Retain, alloc, properties ... Topic to make your Obj-c life easier !

Hey everyone, The more I code, the more I get lost ... so I decided to create a topic entirely dedicated to the memory management for me (and others) not to waste hours understanding obj-c basics ... I'll update it as new questions are asked ! Okay below is some examples : // myArray is property (retain) myArray = otherArray; //myAr...

Java equals and hashmaps problem

So I'm learning Java and I'm trying to understand equals, but I really don't understand it. So my question is: how does equals works? Thanks ...

Generating equals / hashcode / toString using annotation

I believe I read somewhere people generating equals / hashcode / toString methods during compile time (using APT) by identifying which fields should be part of the hash / equality test. I couldn't find anything like that on the web (I might have dreamed it ?) ... That could be done like that : public class Person { @Id @GeneratedValu...

Overriding Equals method in Structs

I've looked for overriding guidelines for structs, but all I can find is for classes. At first I thought I wouldn't have to check to see if the passed object was null, as structs are value types and can't be null. But now that I come to think of it, as equals signature is public bool Equals(object obj) it seems there is nothing preve...

Can't seem to get .Union to work (merging 2 array's together, exclude duplicates)

I want to combine two array's, excluding duplicates. I am using a custom class: public class ArcContact : IEquatable<ArcContact> { public String Text; public Boolean Equals(ArcContact other) { if (Object.ReferenceEquals(other, null)) return false; if (Object.ReferenceEquals(this, other)) return true; ...

IEnumerable when I get a real reference on the objects?

IEnumerable<T> collection; void MyMethod(T toSearch) { foreach (T t in collection) if (t == toSearch) {} } The if clause is never true.. is it because the Enumerator creates all the items instances on demand, so everytime a new Reference ? Edited: Another question. What happens if I one of those collection elements return in T...

How to check if my string is equal to null?

I want to perform some action ONLY IF my string has a meaningful value. So, I tried this. if (!myString.equals("")) { doSomething } and this if (!myString.equals(null)) { doSomething } and this if ( (!myString.equals("")) && (!myString.equals(null))) { doSomething } and this if ( (!myString.equals("")) && (myString!=null)) { do...

How to get element order number

Hello everyone, how can i get order number of some element by javascript/jquery? <ul> <li>Anton</li> <li class="abc">Victor</li> <li class="abc">Simon</li> <li>Adam</li> <li>Peter</li> <li class="abc">Tom</li> </ul> There is 3xli with abc class. Now I need to get order(sequence) number of Simon li. Thanks in advance ...

How to implement IEquatable<T> when mutable fields are part of the equality - Problem with GetHashCode

Hello! I am using Entity Framework in my application. I implemented with the partial class of an entity the IEquatable<T> interface: Partial Class Address : Implements IEquatable(Of Address) 'Other part generated Public Overloads Function Equals(ByVal other As Address) As Boolean _ Implements System.IEquatable(Of Address).Equa...