equals

Is there a “not equal” in a linq join

时光怂恿深爱的人放手 提交于 2019-11-27 12:04:37
I am trying accomplish the LINQ query below but I need a "not equal" instead of equal, so that filteredEmployees has all employees from groupA minus groupB. List<Employee> groupA = getEmployeeA(); List<Employee> groupB = getEmployeeB(); var filteredEmployees = from a in groupA join b in groupB on a.Name equals b.Name select a; You don't need a join for that: var filteredEmployees = groupA.Except(groupB); Note that this will be a sequence of unique employees - so if there are any duplicates in groupA , they will only appear once in filteredEmployees . Of course, it also assumes you've got a

How do I test if a variable does not equal either of two values?

痞子三分冷 提交于 2019-11-27 11:07:14
I want to write an if/else statement that tests if the value of a text input does NOT equal either one of two different values. Like this (excuse my pseudo-English code): var test = $("#test").val(); if (test does not equal A or B){ do stuff; } else { do other stuff; } How do I write the condition for the if statement on line 2? Think of ! (negation operator) as "not", || (boolean-or operator) as "or" and && (boolean-and operator) as "and". See Operators and Operator Precedence . Thus: if(!(a || b)) { // means neither a nor b } However, using De Morgan's Law , it could be written as: if(!a &&

Is it a bad idea if equals(null) throws NullPointerException instead?

风格不统一 提交于 2019-11-27 10:38:52
The contract of equals with regards to null , is as follows: For any non-null reference value x , x.equals(null) should return false . This is rather peculiar, because if o1 != null and o2 == null , then we have: o1.equals(o2) // returns false o2.equals(o1) // throws NullPointerException The fact that o2.equals(o1) throws NullPointerException is a good thing, because it alerts us of programmer error. And yet, that error would not be catched if for various reasons we just switched it around to o1.equals(o2) , which would just "silently fail" instead. So the questions are: Why is it a good idea

Is there a complete IEquatable implementation reference?

冷暖自知 提交于 2019-11-27 10:36:49
Many of my questions here on SO concerns IEquatable implementation. I found it being extremely difficult to implement correctly, because there are many hidden bugs in the naïve implementation, and the articles I found about it are quite incomplete. I want to find or write a definitive reference which must include: How to implement IEquatable correctly How to override Equals correctly How to override GetHashCode correctly How to implement the ToString method correctly How to implement the operator == correctly How to implement the operator != correctly Such a complete reference already exists?

Create the perfect JPA entity [closed]

会有一股神秘感。 提交于 2019-11-27 09:55:03
I've been working with JPA (implementation Hibernate) for some time now and each time I need to create entities I find myself struggling with issues as AccessType, immutable properties, equals/hashCode, ... . So I decided to try and find out the general best practice for each issue and write this down for personal use. I would not mind however for anyone to comment on it or to tell me where I'm wrong. Entity Class implement Serializable Reason: The specification says you have to, but some JPA providers do not enforce this. Hibernate as JPA provider does not enforce this, but it can fail

How to implement hashCode and equals method

谁说胖子不能爱 提交于 2019-11-27 08:17:00
How should I implement hashCode() and equals() for the following class in Java? class Emp { int empid ; // unique across all the departments String name; String dept_name ; String code ; // unique for the department } jutky in Eclipse right mouse click-> source -> generate hashCode() and equals() gives this: /* (non-Javadoc) * @see java.lang.Object#hashCode() */ @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + (code == null ? 0 : code.hashCode()); return result; } /* (non-Javadoc) * @see java.lang.Object#equals(java.lang.Object) */ @Override

PHP if single or double equals

ぐ巨炮叔叔 提交于 2019-11-27 08:13:26
问题 For checking if one string matches another i've been using double equals sign up to now. e.g. if ($string1==$string2) this is because most of the strings i've been using are alphanumeric. however now i am trying the same thing with numeric values like this: $string1 = 10; $string2 = 10; questions is, do i do a single equal or a double equal to make sure the two strings match 100% not more not less just exact so do i do: if ($string1==$string2) or if ($string1=$string2) 回答1: Double equals ( ==

Why are these == but not `equals()`?

China☆狼群 提交于 2019-11-27 07:50:59
I'm a bit confused about the way Java treats == and equals() when it comes to int , Integer and other types of numbers. For example: Integer X = 9000; int x = 9000; Short Y = 9000; short y = 9000; List<Boolean> results = new ArrayList<Boolean>(); // results.add(X == Y); DOES NOT COMPILE 1) results.add(Y == 9000); // 2) results.add(X == y); // 3) results.add(X.equals(x)); // 4) results.add(X.equals(Y)); // 5) results.add(X.equals(y)); // 6) System.out.println(results); outputs (maybe you should make your guess first): [true, true, true, false, false] That X == Y does not compile is to be

Is there a way to check if two Collections contain the same elements, independent of order?

China☆狼群 提交于 2019-11-27 07:47:12
I've been looking for a method that operates like Arrays.equals(a1, a2) , but ignoring the element order. I haven't been able to find it in either Google Collections (something like Iterables.elementsEqual() , but that does account for ordering) and JUnit ( assertEquals() obviously just calls equals() on the Collection, which depends on the Collection implementation, and that's not what I want) It would be best if such a method would take Iterable s, but I'm also fine with simply taking Collection s Such a method would of course take into account any duplicate elements in the collection (so it

Groovy different results on using equals() and == on a GStringImpl

我的未来我决定 提交于 2019-11-27 07:44:52
According to the groovy docs , the == is just a 'clever' equals() as it also takes care of avoiding NullPointerException. So, the == and equals() should return the same value if the objects are not null. However, I'm getting unexpected results on executing the following script: println "${'test'}" == 'test' println "${'test'}".equals('test') The output that I'm getting is true false An example of this can be found here . Is this a known bug related to GStringImpl or something that I'm missing? Nice question, the surprising thing about the code above is that println "${'test'}".equals('test')