- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
public final class Equality {
/**
* @param o an object
* @param a an object to be compared with {@code o} for equality
* @return true if the arguments are equal to each other and false otherwise
*/
public static <O> boolean eq(@Nullable O o, @Nullable O a) {
return Objects.equals(o, a);
}
/**
* @param o an object
* @param a an object to be compared with {@code o} for equality
* @return true if the any arguments are equal to each other and false otherwise
*/
public static <O> boolean eqAny(@Nullable O o, @Nullable O a) {
return eq(o, a);
}
/**
* @param o an object
* @param a an object to be compared with {@code o} for equality
* @param b an object to be compared with {@code o} for equality
* @return true if the any arguments are equal to each other and false otherwise
*/
public static <O> boolean eqAny(@Nullable O o, @Nullable O a, @Nullable O b) {
return eq(o, a) || eq(o, b);
}
/**
* @param o an object
* @param a an object to be compared with {@code o} for equality
* @param b an object to be compared with {@code o} for equality
* @param c an object to be compared with {@code o} for equality
* @return true if the any arguments are equal to each other and false otherwise
*/
public static <O> boolean eqAny(@Nullable O o, @Nullable O a, @Nullable O b, @Nullable O c) {
return eqAny(o, a, b) || eq(o, c);
}
/**
* @param o an object
* @param a an object to be compared with {@code o} for equality
* @param b an object to be compared with {@code o} for equality
* @param c an object to be compared with {@code o} for equality
* @param d an object to be compared with {@code o} for equality
* @return true if the any arguments are equal to each other and false otherwise
*/
public static <O> boolean eqAny(@Nullable O o, @Nullable O a, @Nullable O b, @Nullable O c, @Nullable O d) {
return eqAny(o, a, b, c) || eq(o, d);
}
/**
* @param o an object
* @param a an object to be compared with {@code o} for equality
* @param b an object to be compared with {@code o} for equality
* @param c an object to be compared with {@code o} for equality
* @param d an object to be compared with {@code o} for equality
* @param e an object to be compared with {@code o} for equality
* @return true if the any arguments are equal to each other and false otherwise
*/
public static <O> boolean eqAny(@Nullable O o, @Nullable O a, @Nullable O b, @Nullable O c, @Nullable O d, @Nullable O e) {
return eqAny(o, a, b, c, d) || eq(o, e);
}
/**
* @param o an object
* @param a an array of objects to be compared
* @return true if any the arguments are equal to each other and false otherwise
*/
public static <O> boolean eqAny(@Nullable O o, O... a) {
for(O e: a)
if(eq(o, e))
return true;
return false;
}
}
Мой любимый класс.
Когда на душе становится тяжело, я всегда открываю этот класс, и признаки депрессии улетучиваются.
И да, комментарии врут, и да, там еще столько же методов eqAll(...)
gost 05.03.2015 16:22 # +1
stasmarkin 05.03.2015 16:46 # +4
someone 05.03.2015 16:46 # +3
Dummy00001 05.03.2015 19:44 # +8
Stallman 05.03.2015 22:47 # +4
Эх, вот словно питон запустил.
Dummy00001 06.03.2015 00:29 # +1
gost 05.03.2015 18:02 # +3
Удивление существа с 3 глазами.
kegdan 06.03.2015 03:59 # +3
roman-kashitsyn 05.03.2015 22:09 # +2
В целях борьбы с "критическими" ворнингами sonar, который запрещал собираться по трое писать больше трёх условий в одном выражении. Особенно это напрягало в переопределении equals.
dmli 11.03.2015 01:19 # 0