How to use isEquals method of org.mockito.internal.matchers.apachecommons.EqualsBuilder class

Best Mockito code snippet using org.mockito.internal.matchers.apachecommons.EqualsBuilder.isEquals

Source:EqualsBuilderTest.java Github

copy

Full Screen

...236 }237 @Test public void testSuper() {238 TestObject o1 = new TestObject(4);239 TestObject o2 = new TestObject(5);240 assertEquals(true, new EqualsBuilder().appendSuper(true).append(o1, o1).isEquals());241 assertEquals(false, new EqualsBuilder().appendSuper(false).append(o1, o1).isEquals());242 assertEquals(false, new EqualsBuilder().appendSuper(true).append(o1, o2).isEquals());243 assertEquals(false, new EqualsBuilder().appendSuper(false).append(o1, o2).isEquals());244 }245 @Test public void testObject() {246 TestObject o1 = new TestObject(4);247 TestObject o2 = new TestObject(5);248 assertTrue(new EqualsBuilder().append(o1, o1).isEquals());249 assertTrue(!new EqualsBuilder().append(o1, o2).isEquals());250 o2.setA(4);251 assertTrue(new EqualsBuilder().append(o1, o2).isEquals());252 assertTrue(!new EqualsBuilder().append(o1, this).isEquals());253 assertTrue(!new EqualsBuilder().append(o1, null).isEquals());254 assertTrue(!new EqualsBuilder().append(null, o2).isEquals());255 assertTrue(new EqualsBuilder().append((Object) null, (Object) null).isEquals());256 }257 @Test public void testLong() {258 long o1 = 1L;259 long o2 = 2L;260 assertTrue(new EqualsBuilder().append(o1, o1).isEquals());261 assertTrue(!new EqualsBuilder().append(o1, o2).isEquals());262 }263 @Test public void testInt() {264 int o1 = 1;265 int o2 = 2;266 assertTrue(new EqualsBuilder().append(o1, o1).isEquals());267 assertTrue(!new EqualsBuilder().append(o1, o2).isEquals());268 }269 @Test public void testShort() {270 short o1 = 1;271 short o2 = 2;272 assertTrue(new EqualsBuilder().append(o1, o1).isEquals());273 assertTrue(!new EqualsBuilder().append(o1, o2).isEquals());274 }275 @Test public void testChar() {276 char o1 = 1;277 char o2 = 2;278 assertTrue(new EqualsBuilder().append(o1, o1).isEquals());279 assertTrue(!new EqualsBuilder().append(o1, o2).isEquals());280 }281 @Test public void testByte() {282 byte o1 = 1;283 byte o2 = 2;284 assertTrue(new EqualsBuilder().append(o1, o1).isEquals());285 assertTrue(!new EqualsBuilder().append(o1, o2).isEquals());286 }287 @Test public void testDouble() {288 double o1 = 1;289 double o2 = 2;290 assertTrue(new EqualsBuilder().append(o1, o1).isEquals());291 assertTrue(!new EqualsBuilder().append(o1, o2).isEquals());292 assertTrue(!new EqualsBuilder().append(o1, Double.NaN).isEquals());293 assertTrue(new EqualsBuilder().append(Double.NaN, Double.NaN).isEquals());294 assertTrue(new EqualsBuilder().append(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY).isEquals());295 }296 @Test public void testFloat() {297 float o1 = 1;298 float o2 = 2;299 assertTrue(new EqualsBuilder().append(o1, o1).isEquals());300 assertTrue(!new EqualsBuilder().append(o1, o2).isEquals());301 assertTrue(!new EqualsBuilder().append(o1, Float.NaN).isEquals());302 assertTrue(new EqualsBuilder().append(Float.NaN, Float.NaN).isEquals());303 assertTrue(new EqualsBuilder().append(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY).isEquals());304 }305 // https://issues.apache.org/jira/browse/LANG-393306 @Test public void testBigDecimal() {307 BigDecimal o1 = new BigDecimal("2.0");308 BigDecimal o2 = new BigDecimal("2.00");309 assertTrue(new EqualsBuilder().append(o1, o1).isEquals());310 assertTrue(new EqualsBuilder().append(o1, o2).isEquals());311 }312 @Test public void testAccessors() {313 EqualsBuilder equalsBuilder = new EqualsBuilder();314 assertTrue(equalsBuilder.isEquals());315 equalsBuilder.setEquals(true);316 assertTrue(equalsBuilder.isEquals());317 equalsBuilder.setEquals(false);318 assertFalse(equalsBuilder.isEquals());319 }320 @Test public void testBoolean() {321 boolean o1 = true;322 boolean o2 = false;323 assertTrue(new EqualsBuilder().append(o1, o1).isEquals());324 assertTrue(!new EqualsBuilder().append(o1, o2).isEquals());325 }326 @Test public void testObjectArray() {327 TestObject[] obj1 = new TestObject[3];328 obj1[0] = new TestObject(4);329 obj1[1] = new TestObject(5);330 obj1[2] = null;331 TestObject[] obj2 = new TestObject[3];332 obj2[0] = new TestObject(4);333 obj2[1] = new TestObject(5);334 obj2[2] = null;335 assertTrue(new EqualsBuilder().append(obj1, obj1).isEquals());336 assertTrue(new EqualsBuilder().append(obj2, obj2).isEquals());337 assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());338 obj1[1].setA(6);339 assertTrue(!new EqualsBuilder().append(obj1, obj2).isEquals());340 obj1[1].setA(5);341 assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());342 obj1[2] = obj1[1];343 assertTrue(!new EqualsBuilder().append(obj1, obj2).isEquals());344 obj1[2] = null;345 assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());346 obj2 = null;347 assertTrue(!new EqualsBuilder().append(obj1, obj2).isEquals());348 obj1 = null;349 assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());350 }351 @Test public void testLongArray() {352 long[] obj1 = new long[2];353 obj1[0] = 5L;354 obj1[1] = 6L;355 long[] obj2 = new long[2];356 obj2[0] = 5L;357 obj2[1] = 6L;358 assertTrue(new EqualsBuilder().append(obj1, obj1).isEquals());359 assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());360 obj1[1] = 7;361 assertTrue(!new EqualsBuilder().append(obj1, obj2).isEquals());362 obj2 = null;363 assertTrue(!new EqualsBuilder().append(obj1, obj2).isEquals());364 obj1 = null;365 assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());366 }367 @Test public void testIntArray() {368 int[] obj1 = new int[2];369 obj1[0] = 5;370 obj1[1] = 6;371 int[] obj2 = new int[2];372 obj2[0] = 5;373 obj2[1] = 6;374 assertTrue(new EqualsBuilder().append(obj1, obj1).isEquals());375 assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());376 obj1[1] = 7;377 assertTrue(!new EqualsBuilder().append(obj1, obj2).isEquals());378 obj2 = null;379 assertTrue(!new EqualsBuilder().append(obj1, obj2).isEquals());380 obj1 = null;381 assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());382 }383 @Test public void testShortArray() {384 short[] obj1 = new short[2];385 obj1[0] = 5;386 obj1[1] = 6;387 short[] obj2 = new short[2];388 obj2[0] = 5;389 obj2[1] = 6;390 assertTrue(new EqualsBuilder().append(obj1, obj1).isEquals());391 assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());392 obj1[1] = 7;393 assertTrue(!new EqualsBuilder().append(obj1, obj2).isEquals());394 obj2 = null;395 assertTrue(!new EqualsBuilder().append(obj1, obj2).isEquals());396 obj1 = null;397 assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());398 }399 @Test public void testCharArray() {400 char[] obj1 = new char[2];401 obj1[0] = 5;402 obj1[1] = 6;403 char[] obj2 = new char[2];404 obj2[0] = 5;405 obj2[1] = 6;406 assertTrue(new EqualsBuilder().append(obj1, obj1).isEquals());407 assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());408 obj1[1] = 7;409 assertTrue(!new EqualsBuilder().append(obj1, obj2).isEquals());410 obj2 = null;411 assertTrue(!new EqualsBuilder().append(obj1, obj2).isEquals());412 obj1 = null;413 assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());414 }415 @Test public void testByteArray() {416 byte[] obj1 = new byte[2];417 obj1[0] = 5;418 obj1[1] = 6;419 byte[] obj2 = new byte[2];420 obj2[0] = 5;421 obj2[1] = 6;422 assertTrue(new EqualsBuilder().append(obj1, obj1).isEquals());423 assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());424 obj1[1] = 7;425 assertTrue(!new EqualsBuilder().append(obj1, obj2).isEquals());426 obj2 = null;427 assertTrue(!new EqualsBuilder().append(obj1, obj2).isEquals());428 obj1 = null;429 assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());430 }431 @Test public void testDoubleArray() {432 double[] obj1 = new double[2];433 obj1[0] = 5;434 obj1[1] = 6;435 double[] obj2 = new double[2];436 obj2[0] = 5;437 obj2[1] = 6;438 assertTrue(new EqualsBuilder().append(obj1, obj1).isEquals());439 assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());440 obj1[1] = 7;441 assertTrue(!new EqualsBuilder().append(obj1, obj2).isEquals());442 obj2 = null;443 assertTrue(!new EqualsBuilder().append(obj1, obj2).isEquals());444 obj1 = null;445 assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());446 }447 @Test public void testFloatArray() {448 float[] obj1 = new float[2];449 obj1[0] = 5;450 obj1[1] = 6;451 float[] obj2 = new float[2];452 obj2[0] = 5;453 obj2[1] = 6;454 assertTrue(new EqualsBuilder().append(obj1, obj1).isEquals());455 assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());456 obj1[1] = 7;457 assertTrue(!new EqualsBuilder().append(obj1, obj2).isEquals());458 obj2 = null;459 assertTrue(!new EqualsBuilder().append(obj1, obj2).isEquals());460 obj1 = null;461 assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());462 }463 @Test public void testBooleanArray() {464 boolean[] obj1 = new boolean[2];465 obj1[0] = true;466 obj1[1] = false;467 boolean[] obj2 = new boolean[2];468 obj2[0] = true;469 obj2[1] = false;470 assertTrue(new EqualsBuilder().append(obj1, obj1).isEquals());471 assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());472 obj1[1] = true;473 assertTrue(!new EqualsBuilder().append(obj1, obj2).isEquals());474 obj2 = null;475 assertTrue(!new EqualsBuilder().append(obj1, obj2).isEquals());476 obj1 = null;477 assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());478 }479 @Test public void testMultiLongArray() {480 long[][] array1 = new long[2][2];481 long[][] array2 = new long[2][2];482 for (int i = 0; i < array1.length; ++i) {483 for (int j = 0; j < array1[0].length; j++) {484 array1[i][j] = (i + 1) * (j + 1);485 array2[i][j] = (i + 1) * (j + 1);486 }487 }488 assertTrue(new EqualsBuilder().append(array1, array1).isEquals());489 assertTrue(new EqualsBuilder().append(array1, array2).isEquals());490 array1[1][1] = 0;491 assertTrue(!new EqualsBuilder().append(array1, array2).isEquals());492 }493 @Test public void testMultiIntArray() {494 int[][] array1 = new int[2][2];495 int[][] array2 = new int[2][2];496 for (int i = 0; i < array1.length; ++i) {497 for (int j = 0; j < array1[0].length; j++) {498 array1[i][j] = (i + 1) * (j + 1);499 array2[i][j] = (i + 1) * (j + 1);500 }501 }502 assertTrue(new EqualsBuilder().append(array1, array1).isEquals());503 assertTrue(new EqualsBuilder().append(array1, array2).isEquals());504 array1[1][1] = 0;505 assertTrue(!new EqualsBuilder().append(array1, array2).isEquals());506 }507 @Test public void testMultiShortArray() {508 short[][] array1 = new short[2][2];509 short[][] array2 = new short[2][2];510 for (short i = 0; i < array1.length; ++i) {511 for (short j = 0; j < array1[0].length; j++) {512 array1[i][j] = i;513 array2[i][j] = i;514 }515 }516 assertTrue(new EqualsBuilder().append(array1, array1).isEquals());517 assertTrue(new EqualsBuilder().append(array1, array2).isEquals());518 array1[1][1] = 0;519 assertTrue(!new EqualsBuilder().append(array1, array2).isEquals());520 }521 @Test public void testMultiCharArray() {522 char[][] array1 = new char[2][2];523 char[][] array2 = new char[2][2];524 for (char i = 0; i < array1.length; ++i) {525 for (char j = 0; j < array1[0].length; j++) {526 array1[i][j] = i;527 array2[i][j] = i;528 }529 }530 assertTrue(new EqualsBuilder().append(array1, array1).isEquals());531 assertTrue(new EqualsBuilder().append(array1, array2).isEquals());532 array1[1][1] = 0;533 assertTrue(!new EqualsBuilder().append(array1, array2).isEquals());534 }535 @Test public void testMultiByteArray() {536 byte[][] array1 = new byte[2][2];537 byte[][] array2 = new byte[2][2];538 for (byte i = 0; i < array1.length; ++i) {539 for (byte j = 0; j < array1[0].length; j++) {540 array1[i][j] = i;541 array2[i][j] = i;542 }543 }544 assertTrue(new EqualsBuilder().append(array1, array1).isEquals());545 assertTrue(new EqualsBuilder().append(array1, array2).isEquals());546 array1[1][1] = 0;547 assertTrue(!new EqualsBuilder().append(array1, array2).isEquals());548 }549 @Test public void testMultiFloatArray() {550 float[][] array1 = new float[2][2];551 float[][] array2 = new float[2][2];552 for (int i = 0; i < array1.length; ++i) {553 for (int j = 0; j < array1[0].length; j++) {554 array1[i][j] = (i + 1) * (j + 1);555 array2[i][j] = (i + 1) * (j + 1);556 }557 }558 assertTrue(new EqualsBuilder().append(array1, array1).isEquals());559 assertTrue(new EqualsBuilder().append(array1, array2).isEquals());560 array1[1][1] = 0;561 assertTrue(!new EqualsBuilder().append(array1, array2).isEquals());562 }563 @Test public void testMultiDoubleArray() {564 double[][] array1 = new double[2][2];565 double[][] array2 = new double[2][2];566 for (int i = 0; i < array1.length; ++i) {567 for (int j = 0; j < array1[0].length; j++) {568 array1[i][j] = (i + 1) * (j + 1);569 array2[i][j] = (i + 1) * (j + 1);570 }571 }572 assertTrue(new EqualsBuilder().append(array1, array1).isEquals());573 assertTrue(new EqualsBuilder().append(array1, array2).isEquals());574 array1[1][1] = 0;575 assertTrue(!new EqualsBuilder().append(array1, array2).isEquals());576 }577 @Test public void testMultiBooleanArray() {578 boolean[][] array1 = new boolean[2][2];579 boolean[][] array2 = new boolean[2][2];580 for (int i = 0; i < array1.length; ++i) {581 for (int j = 0; j < array1[0].length; j++) {582 array1[i][j] = (i == 1) || (j == 1);583 array2[i][j] = (i == 1) || (j == 1);584 }585 }586 assertTrue(new EqualsBuilder().append(array1, array1).isEquals());587 assertTrue(new EqualsBuilder().append(array1, array2).isEquals());588 array1[1][1] = false;589 assertTrue(!new EqualsBuilder().append(array1, array2).isEquals());590 // compare 1 dim to 2.591 boolean[] array3 = new boolean[]{true, true};592 assertFalse(new EqualsBuilder().append(array1, array3).isEquals());593 assertFalse(new EqualsBuilder().append(array3, array1).isEquals());594 assertFalse(new EqualsBuilder().append(array2, array3).isEquals());595 assertFalse(new EqualsBuilder().append(array3, array2).isEquals());596 }597 @Test public void testRaggedArray() {598 long[][] array1 = new long[2][];599 long[][] array2 = new long[2][];600 for (int i = 0; i < array1.length; ++i) {601 array1[i] = new long[2];602 array2[i] = new long[2];603 for (int j = 0; j < array1[i].length; ++j) {604 array1[i][j] = (i + 1) * (j + 1);605 array2[i][j] = (i + 1) * (j + 1);606 }607 }608 assertTrue(new EqualsBuilder().append(array1, array1).isEquals());609 assertTrue(new EqualsBuilder().append(array1, array2).isEquals());610 array1[1][1] = 0;611 assertTrue(!new EqualsBuilder().append(array1, array2).isEquals());612 }613 @Test public void testMixedArray() {614 Object[] array1 = new Object[2];615 Object[] array2 = new Object[2];616 for (int i = 0; i < array1.length; ++i) {617 array1[i] = new long[2];618 array2[i] = new long[2];619 for (int j = 0; j < 2; ++j) {620 ((long[]) array1[i])[j] = (i + 1) * (j + 1);621 ((long[]) array2[i])[j] = (i + 1) * (j + 1);622 }623 }624 assertTrue(new EqualsBuilder().append(array1, array1).isEquals());625 assertTrue(new EqualsBuilder().append(array1, array2).isEquals());626 ((long[]) array1[1])[1] = 0;627 assertTrue(!new EqualsBuilder().append(array1, array2).isEquals());628 }629 @Test public void testObjectArrayHiddenByObject() {630 TestObject[] array1 = new TestObject[2];631 array1[0] = new TestObject(4);632 array1[1] = new TestObject(5);633 TestObject[] array2 = new TestObject[2];634 array2[0] = new TestObject(4);635 array2[1] = new TestObject(5);636 Object obj1 = array1;637 Object obj2 = array2;638 assertTrue(new EqualsBuilder().append(obj1, obj1).isEquals());639 assertTrue(new EqualsBuilder().append(obj1, array1).isEquals());640 assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());641 assertTrue(new EqualsBuilder().append(obj1, array2).isEquals());642 array1[1].setA(6);643 assertTrue(!new EqualsBuilder().append(obj1, obj2).isEquals());644 }645 @Test public void testLongArrayHiddenByObject() {646 long[] array1 = new long[2];647 array1[0] = 5L;648 array1[1] = 6L;649 long[] array2 = new long[2];650 array2[0] = 5L;651 array2[1] = 6L;652 Object obj1 = array1;653 Object obj2 = array2;654 assertTrue(new EqualsBuilder().append(obj1, obj1).isEquals());655 assertTrue(new EqualsBuilder().append(obj1, array1).isEquals());656 assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());657 assertTrue(new EqualsBuilder().append(obj1, array2).isEquals());658 array1[1] = 7;659 assertTrue(!new EqualsBuilder().append(obj1, obj2).isEquals());660 }661 @Test public void testIntArrayHiddenByObject() {662 int[] array1 = new int[2];663 array1[0] = 5;664 array1[1] = 6;665 int[] array2 = new int[2];666 array2[0] = 5;667 array2[1] = 6;668 Object obj1 = array1;669 Object obj2 = array2;670 assertTrue(new EqualsBuilder().append(obj1, obj1).isEquals());671 assertTrue(new EqualsBuilder().append(obj1, array1).isEquals());672 assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());673 assertTrue(new EqualsBuilder().append(obj1, array2).isEquals());674 array1[1] = 7;675 assertTrue(!new EqualsBuilder().append(obj1, obj2).isEquals());676 }677 @Test public void testShortArrayHiddenByObject() {678 short[] array1 = new short[2];679 array1[0] = 5;680 array1[1] = 6;681 short[] array2 = new short[2];682 array2[0] = 5;683 array2[1] = 6;684 Object obj1 = array1;685 Object obj2 = array2;686 assertTrue(new EqualsBuilder().append(obj1, obj1).isEquals());687 assertTrue(new EqualsBuilder().append(obj1, array1).isEquals());688 assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());689 assertTrue(new EqualsBuilder().append(obj1, array2).isEquals());690 array1[1] = 7;691 assertTrue(!new EqualsBuilder().append(obj1, obj2).isEquals());692 }693 @Test public void testCharArrayHiddenByObject() {694 char[] array1 = new char[2];695 array1[0] = 5;696 array1[1] = 6;697 char[] array2 = new char[2];698 array2[0] = 5;699 array2[1] = 6;700 Object obj1 = array1;701 Object obj2 = array2;702 assertTrue(new EqualsBuilder().append(obj1, obj1).isEquals());703 assertTrue(new EqualsBuilder().append(obj1, array1).isEquals());704 assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());705 assertTrue(new EqualsBuilder().append(obj1, array2).isEquals());706 array1[1] = 7;707 assertTrue(!new EqualsBuilder().append(obj1, obj2).isEquals());708 }709 @Test public void testByteArrayHiddenByObject() {710 byte[] array1 = new byte[2];711 array1[0] = 5;712 array1[1] = 6;713 byte[] array2 = new byte[2];714 array2[0] = 5;715 array2[1] = 6;716 Object obj1 = array1;717 Object obj2 = array2;718 assertTrue(new EqualsBuilder().append(obj1, obj1).isEquals());719 assertTrue(new EqualsBuilder().append(obj1, array1).isEquals());720 assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());721 assertTrue(new EqualsBuilder().append(obj1, array2).isEquals());722 array1[1] = 7;723 assertTrue(!new EqualsBuilder().append(obj1, obj2).isEquals());724 }725 @Test public void testDoubleArrayHiddenByObject() {726 double[] array1 = new double[2];727 array1[0] = 5;728 array1[1] = 6;729 double[] array2 = new double[2];730 array2[0] = 5;731 array2[1] = 6;732 Object obj1 = array1;733 Object obj2 = array2;734 assertTrue(new EqualsBuilder().append(obj1, obj1).isEquals());735 assertTrue(new EqualsBuilder().append(obj1, array1).isEquals());736 assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());737 assertTrue(new EqualsBuilder().append(obj1, array2).isEquals());738 array1[1] = 7;739 assertTrue(!new EqualsBuilder().append(obj1, obj2).isEquals());740 }741 @Test public void testFloatArrayHiddenByObject() {742 float[] array1 = new float[2];743 array1[0] = 5;744 array1[1] = 6;745 float[] array2 = new float[2];746 array2[0] = 5;747 array2[1] = 6;748 Object obj1 = array1;749 Object obj2 = array2;750 assertTrue(new EqualsBuilder().append(obj1, obj1).isEquals());751 assertTrue(new EqualsBuilder().append(obj1, array1).isEquals());752 assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());753 assertTrue(new EqualsBuilder().append(obj1, array2).isEquals());754 array1[1] = 7;755 assertTrue(!new EqualsBuilder().append(obj1, obj2).isEquals());756 }757 @Test public void testBooleanArrayHiddenByObject() {758 boolean[] array1 = new boolean[2];759 array1[0] = true;760 array1[1] = false;761 boolean[] array2 = new boolean[2];762 array2[0] = true;763 array2[1] = false;764 Object obj1 = array1;765 Object obj2 = array2;766 assertTrue(new EqualsBuilder().append(obj1, obj1).isEquals());767 assertTrue(new EqualsBuilder().append(obj1, array1).isEquals());768 assertTrue(new EqualsBuilder().append(obj1, obj2).isEquals());769 assertTrue(new EqualsBuilder().append(obj1, array2).isEquals());770 array1[1] = true;771 assertTrue(!new EqualsBuilder().append(obj1, obj2).isEquals());772 }773 public static class TestACanEqualB {774 private int a;775 public TestACanEqualB(int a) {776 this.a = a;777 }778 public boolean equals(Object o) {779 if (o == this) {780 return true;781 }782 if (o instanceof TestACanEqualB) {783 return this.a == ((TestACanEqualB) o).getA();784 }785 if (o instanceof TestBCanEqualA) {786 return this.a == ((TestBCanEqualA) o).getB();787 }788 return false;789 }790 public int hashCode() {791 return 1;792 }793 public int getA() {794 return this.a;795 }796 }797 public static class TestBCanEqualA {798 private int b;799 public TestBCanEqualA(int b) {800 this.b = b;801 }802 public boolean equals(Object o) {803 if (o == this) {804 return true;805 }806 if (o instanceof TestACanEqualB) {807 return this.b == ((TestACanEqualB) o).getA();808 }809 if (o instanceof TestBCanEqualA) {810 return this.b == ((TestBCanEqualA) o).getB();811 }812 return false;813 }814 public int hashCode() {815 return 1;816 }817 public int getB() {818 return this.b;819 }820 }821 /**822 * Tests two instances of classes that can be equal and that are not "related". The two classes are not subclasses823 * of each other and do not share a parent aside from Object.824 * See http://issues.apache.org/bugzilla/show_bug.cgi?id=33069825 */826 @Test public void testUnrelatedClasses() {827 Object[] x = new Object[]{new TestACanEqualB(1)};828 Object[] y = new Object[]{new TestBCanEqualA(1)};829 // sanity checks:830 assertTrue(Arrays.equals(x, x));831 assertTrue(Arrays.equals(y, y));832 assertTrue(Arrays.equals(x, y));833 assertTrue(Arrays.equals(y, x));834 // real tests:835 assertTrue(x[0].equals(x[0]));836 assertTrue(y[0].equals(y[0]));837 assertTrue(x[0].equals(y[0]));838 assertTrue(y[0].equals(x[0]));839 assertTrue(new EqualsBuilder().append(x, x).isEquals());840 assertTrue(new EqualsBuilder().append(y, y).isEquals());841 assertTrue(new EqualsBuilder().append(x, y).isEquals());842 assertTrue(new EqualsBuilder().append(y, x).isEquals());843 }844 /**845 * Test from http://issues.apache.org/bugzilla/show_bug.cgi?id=33067846 */847 @Test public void testNpeForNullElement() {848 Object[] x1 = new Object[] { new Integer(1), null, new Integer(3) };849 Object[] x2 = new Object[] { new Integer(1), new Integer(2), new Integer(3) };850 // causes an NPE in 2.0 according to:851 // http://issues.apache.org/bugzilla/show_bug.cgi?id=33067852 new EqualsBuilder().append(x1, x2);853 }854 @Test public void testReflectionEqualsExcludeFields() throws Exception {855 TestObjectWithMultipleFields x1 = new TestObjectWithMultipleFields(1, 2, 3);856 TestObjectWithMultipleFields x2 = new TestObjectWithMultipleFields(1, 3, 4);...

Full Screen

Full Screen

Source:RapidEqualsBuilder.java Github

copy

Full Screen

...214 * @return RapidEqualsBuilder - used to chain calls.215 * @since 2.1.0216 */217 public RapidEqualsBuilder appendSuper(boolean superEquals) {218 boolean isEquals = isEquals();219 isEquals &= superEquals;220 return this;221 }222 //-------------------------------------------------------------------------223 /**224 * <p>Test if two <code>Object</code>s are equal using their225 * <code>equals</code> method.</p>226 *227 * @param rootProperty the left hand object228 * @param compareProperty the right hand object229 * @return RapidEqualsBuilder - used to chain calls.230 */231 public RapidEqualsBuilder append(Object rootProperty, Object compareProperty, String propertyName) {232 if (done()) {233 return this;234 }235 if (rootProperty == compareProperty) {236 return this;237 }238 if (rootProperty == null || compareProperty == null) {239 this.addDiff(propertyName, rootProperty, compareProperty);240 return this;241 }242 Class<?> lhsClass = rootProperty.getClass();243 if (!lhsClass.isArray()) {244 if (rootProperty instanceof java.math.BigDecimal && compareProperty instanceof java.math.BigDecimal) {245 boolean isEquals = (((java.math.BigDecimal) rootProperty).compareTo((java.math.BigDecimal) compareProperty) == 0);246 if (!isEquals)247 addDiff(propertyName, rootProperty, compareProperty);248 } else {249 // The simple case, not an array, just test the element250 boolean isEquals = rootProperty.equals(compareProperty);251 if (!isEquals)252 addDiff(propertyName, rootProperty, compareProperty);253 }254 } else if (rootProperty.getClass() != compareProperty.getClass()) {255 // Here when we compare different dimensions, for example: a boolean[][] to a boolean[]256 this.addDiff(propertyName, rootProperty, compareProperty);257 // 'Switch' on type of array, to dispatch to the correct handler258 // This handles multi dimensional arrays of the same depth259 } else if (rootProperty instanceof long[]) {260 append((long[]) rootProperty, (long[]) compareProperty, propertyName);261 } else if (rootProperty instanceof int[]) {262 append((int[]) rootProperty, (int[]) compareProperty, propertyName);263 } else if (rootProperty instanceof short[]) {264 append((short[]) rootProperty, (short[]) compareProperty, propertyName);265 } else if (rootProperty instanceof char[]) {266 append((char[]) rootProperty, (char[]) compareProperty, propertyName);267 } else if (rootProperty instanceof byte[]) {268 append((byte[]) rootProperty, (byte[]) compareProperty, propertyName);269 } else if (rootProperty instanceof double[]) {270 append((double[]) rootProperty, (double[]) compareProperty, propertyName);271 } else if (rootProperty instanceof float[]) {272 append((float[]) rootProperty, (float[]) compareProperty, propertyName);273 } else if (rootProperty instanceof boolean[]) {274 append((boolean[]) rootProperty, (boolean[]) compareProperty, propertyName);275 } else {276 // Not an array of primitives277 append((Object[]) rootProperty, (Object[]) compareProperty, propertyName);278 }279 return this;280 }281 //-------------------------------------------------------------------------282 /**283 * <p>284 * Test if two <code>long</code> s are equal.285 * </p>286 *287 * @param lhs the left hand <code>long</code>288 * @param rhs the right hand <code>long</code>289 * @return RapidEqualsBuilder - used to chain calls.290 */291 public RapidEqualsBuilder append(long lhs, long rhs) {292 boolean isEquals = isEquals();293 isEquals &= (lhs == rhs);294 return this;295 }296 /**297 * <p>Test if two <code>int</code>s are equal.</p>298 *299 * @param lhs the left hand <code>int</code>300 * @param rhs the right hand <code>int</code>301 * @return RapidEqualsBuilder - used to chain calls.302 */303 public RapidEqualsBuilder append(int lhs, int rhs) {304 boolean isEquals = isEquals();305 isEquals &= (lhs == rhs);306 return this;307 }308 /**309 * <p>Test if two <code>short</code>s are equal.</p>310 *311 * @param lhs the left hand <code>short</code>312 * @param rhs the right hand <code>short</code>313 * @return RapidEqualsBuilder - used to chain calls.314 */315 public RapidEqualsBuilder append(short lhs, short rhs) {316 boolean isEquals = isEquals();317 isEquals &= (lhs == rhs);318 return this;319 }320 /**321 * <p>Test if two <code>char</code>s are equal.</p>322 *323 * @param lhs the left hand <code>char</code>324 * @param rhs the right hand <code>char</code>325 * @return RapidEqualsBuilder - used to chain calls.326 */327 public RapidEqualsBuilder append(char lhs, char rhs) {328 boolean isEquals = isEquals();329 isEquals &= (lhs == rhs);330 return this;331 }332 /**333 * <p>Test if two <code>byte</code>s are equal.</p>334 *335 * @param lhs the left hand <code>byte</code>336 * @param rhs the right hand <code>byte</code>337 * @return RapidEqualsBuilder - used to chain calls.338 */339 public RapidEqualsBuilder append(byte lhs, byte rhs) {340 boolean isEquals = isEquals();341 isEquals &= (lhs == rhs);342 return this;343 }344 /**345 * <p>Test if two <code>double</code>s are equal by testing that the346 * pattern of bits returned by <code>doubleToLong</code> are equal.</p>347 *348 * <p>This handles NaNs, Infinities, and <code>-0.0</code>.</p>349 *350 * <p>It is compatible with the hash code generated by351 * <code>HashCodeBuilder</code>.</p>352 *353 * @param lhs the left hand <code>double</code>354 * @param rhs the right hand <code>double</code>355 * @return RapidEqualsBuilder - used to chain calls.356 */357 public RapidEqualsBuilder append(double lhs, double rhs) {358 if (!isEquals()) {359 return this;360 }361 return append(Double.doubleToLongBits(lhs), Double.doubleToLongBits(rhs));362 }363 /**364 * <p>Test if two <code>float</code>s are equal byt testing that the365 * pattern of bits returned by doubleToLong are equal.</p>366 *367 * <p>This handles NaNs, Infinities, and <code>-0.0</code>.</p>368 *369 * <p>It is compatible with the hash code generated by370 * <code>HashCodeBuilder</code>.</p>371 *372 * @param lhs the left hand <code>float</code>373 * @param rhs the right hand <code>float</code>374 * @return RapidEqualsBuilder - used to chain calls.375 */376 public RapidEqualsBuilder append(float lhs, float rhs) {377 if (done()) {378 return this;379 }380 return append(Float.floatToIntBits(lhs), Float.floatToIntBits(rhs));381 }382 /**383 * <p>Test if two <code>booleans</code>s are equal.</p>384 *385 * @param lhs the left hand <code>boolean</code>386 * @param rhs the right hand <code>boolean</code>387 * @return RapidEqualsBuilder - used to chain calls.388 */389 public RapidEqualsBuilder append(boolean lhs, boolean rhs) {390 boolean isEquals = isEquals();391 isEquals &= (lhs == rhs);392 return this;393 }394 /**395 * <p>Performs a deep comparison of two <code>Object</code> arrays.</p>396 *397 * <p>This also will be called for the top level of398 * multi-dimensional, ragged, and multi-typed arrays.</p>399 *400 * @param lhs the left hand <code>Object[]</code>401 * @param rhs the right hand <code>Object[]</code>402 * @return RapidEqualsBuilder - used to chain calls.403 */404 public RapidEqualsBuilder append(Object[] lhs, Object[] rhs, String property) {405 if (done()) {406 return this;407 }408 if (lhs == rhs) {409 return this;410 }411 if (lhs == null || rhs == null) {412 this.addDiff(property, lhs, rhs);413 return this;414 }415 if (lhs.length != rhs.length) {416 this.addDiff(property, lhs, rhs);417 return this;418 }419 for (int i = 0; i < lhs.length && isEquals(); ++i) {420 append(lhs[i], rhs[i], property);421 }422 return this;423 }424 /**425 * <p>Deep comparison of array of <code>long</code>. Length and all426 * values are compared.</p>427 *428 * <p>The method {@link #append(long, long)} is used.</p>429 *430 * @param lhs the left hand <code>long[]</code>431 * @param rhs the right hand <code>long[]</code>432 * @return RapidEqualsBuilder - used to chain calls.433 */434 public RapidEqualsBuilder append(long[] lhs, long[] rhs, String property) {435 if (done()) {436 return this;437 }438 if (lhs == rhs) {439 return this;440 }441 if (lhs == null || rhs == null) {442 this.addDiff(property, lhs, rhs);443 return this;444 }445 if (lhs.length != rhs.length) {446 this.addDiff(property, lhs, rhs);447 return this;448 }449 for (int i = 0; i < lhs.length && !done(); ++i) {450 append(lhs[i], rhs[i]);451 }452 return this;453 }454 /**455 * <p>Deep comparison of array of <code>int</code>. Length and all456 * values are compared.</p>457 *458 * <p>The method {@link #append(int, int)} is used.</p>459 *460 * @param lhs the left hand <code>int[]</code>461 * @param rhs the right hand <code>int[]</code>462 * @return RapidEqualsBuilder - used to chain calls.463 */464 public RapidEqualsBuilder append(int[] lhs, int[] rhs, String property) {465 if (done()) {466 return this;467 }468 if (lhs == rhs) {469 return this;470 }471 if (lhs == null || rhs == null) {472 this.addDiff(property, lhs, rhs);473 return this;474 }475 if (lhs.length != rhs.length) {476 this.addDiff(property, lhs, rhs);477 return this;478 }479 for (int i = 0; i < lhs.length && isEquals(); ++i) {480 append(lhs[i], rhs[i]);481 }482 return this;483 }484 /**485 * <p>Deep comparison of array of <code>short</code>. Length and all486 * values are compared.</p>487 *488 * <p>The method {@link #append(short, short)} is used.</p>489 *490 * @param lhs the left hand <code>short[]</code>491 * @param rhs the right hand <code>short[]</code>492 * @return RapidEqualsBuilder - used to chain calls.493 */494 public RapidEqualsBuilder append(short[] lhs, short[] rhs, String property) {495 if (done()) {496 return this;497 }498 if (lhs == rhs) {499 return this;500 }501 if (lhs == null || rhs == null) {502 this.addDiff(property, lhs, rhs);503 return this;504 }505 if (lhs.length != rhs.length) {506 this.addDiff(property, lhs, rhs);507 return this;508 }509 for (int i = 0; i < lhs.length && !done(); ++i) {510 append(lhs[i], rhs[i]);511 }512 return this;513 }514 /**515 * <p>Deep comparison of array of <code>char</code>. Length and all516 * values are compared.</p>517 *518 * <p>The method {@link #append(char, char)} is used.</p>519 *520 * @param lhs the left hand <code>char[]</code>521 * @param rhs the right hand <code>char[]</code>522 * @return RapidEqualsBuilder - used to chain calls.523 */524 public RapidEqualsBuilder append(char[] lhs, char[] rhs, String property) {525 if (done()) {526 return this;527 }528 if (lhs == rhs) {529 return this;530 }531 if (lhs == null || rhs == null) {532 this.addDiff(property, lhs, rhs);533 return this;534 }535 if (lhs.length != rhs.length) {536 this.addDiff(property, lhs, rhs);537 return this;538 }539 for (int i = 0; i < lhs.length && !done(); ++i) {540 append(lhs[i], rhs[i]);541 }542 return this;543 }544 /**545 * <p>Deep comparison of array of <code>byte</code>. Length and all546 * values are compared.</p>547 *548 * <p>The method {@link #append(byte, byte)} is used.</p>549 *550 * @param lhs the left hand <code>byte[]</code>551 * @param rhs the right hand <code>byte[]</code>552 * @return RapidEqualsBuilder - used to chain calls.553 */554 public RapidEqualsBuilder append(byte[] lhs, byte[] rhs, String property) {555 if (done()) {556 return this;557 }558 if (lhs == rhs) {559 return this;560 }561 if (lhs == null || rhs == null) {562 this.addDiff(property, lhs, rhs);563 return this;564 }565 if (lhs.length != rhs.length) {566 this.addDiff(property, lhs, rhs);567 return this;568 }569 for (int i = 0; i < lhs.length && !done(); ++i) {570 append(lhs[i], rhs[i]);571 }572 return this;573 }574 /**575 * <p>Deep comparison of array of <code>double</code>. Length and all576 * values are compared.</p>577 *578 * <p>The method {@link #append(double, double)} is used.</p>579 *580 * @param lhs the left hand <code>double[]</code>581 * @param rhs the right hand <code>double[]</code>582 * @return RapidEqualsBuilder - used to chain calls.583 */584 public RapidEqualsBuilder append(double[] lhs, double[] rhs, String property) {585 if (done()) {586 return this;587 }588 if (lhs == rhs) {589 return this;590 }591 if (lhs == null || rhs == null) {592 this.addDiff(property, lhs, rhs);593 return this;594 }595 if (lhs.length != rhs.length) {596 this.addDiff(property, lhs, rhs);597 return this;598 }599 for (int i = 0; i < lhs.length && !done(); ++i) {600 append(lhs[i], rhs[i]);601 }602 return this;603 }604 /**605 * <p>Deep comparison of array of <code>float</code>. Length and all606 * values are compared.</p>607 *608 * <p>The method {@link #append(float, float)} is used.</p>609 *610 * @param lhs the left hand <code>float[]</code>611 * @param rhs the right hand <code>float[]</code>612 * @return RapidEqualsBuilder - used to chain calls.613 */614 public RapidEqualsBuilder append(float[] lhs, float[] rhs, String property) {615 if (done()) {616 return this;617 }618 if (lhs == rhs) {619 return this;620 }621 if (lhs == null || rhs == null) {622 this.addDiff(property, lhs, rhs);623 return this;624 }625 if (lhs.length != rhs.length) {626 this.addDiff(property, lhs, rhs);627 return this;628 }629 for (int i = 0; i < lhs.length && !done(); ++i) {630 append(lhs[i], rhs[i]);631 }632 return this;633 }634 /**635 * <p>Deep comparison of array of <code>boolean</code>. Length and all636 * values are compared.</p>637 *638 * <p>The method {@link #append(boolean, boolean)} is used.</p>639 *640 * @param lhs the left hand <code>boolean[]</code>641 * @param rhs the right hand <code>boolean[]</code>642 * @return RapidEqualsBuilder - used to chain calls.643 */644 public RapidEqualsBuilder append(boolean[] lhs, boolean[] rhs, String property) {645 if (done()) {646 return this;647 }648 if (lhs == rhs) {649 return this;650 }651 if (lhs == null || rhs == null) {652 this.addDiff(property, lhs, rhs);653 return this;654 }655 if (lhs.length != rhs.length) {656 this.addDiff(property, lhs, rhs);657 return this;658 }659 for (int i = 0; i < lhs.length && !done(); ++i) {660 append(lhs[i], rhs[i]);661 }662 return this;663 }664 public Diff getDiff() {665 return this.diff;666 }667 /**668 * <p>Returns <code>true</code> if the fields that have been checked669 * are all equal.</p>670 *671 * @return boolean672 */673 public boolean isEquals() {674 return !this.diff.isDifferent();675 }676 677 public boolean minimalDiff(){678 return this.config.minimalDiff;679 }680 /**681 * Indicates that it is already clear that objects differ and only minimal diff is required682 * -> algorithm can stop and return result.683 * @return684 */685 public boolean done(){686 return !isEquals() && minimalDiff();687 }688 protected void addDiff(String property, Object rootValue, Object compareValue) {689 this.diff.addNode(Diff.DiffNode.builder()690 .property(property)691 .rootValue(rootValue)692 .compareValue(compareValue)693 .build());694 }695 /**696 * Represents Difference of root and compare object in this comparison context.697 */698 @Getter699 @ToString700 public static class Diff {...

Full Screen

Full Screen

Source:EqualsBuilder.java Github

copy

Full Screen

...6import java.util.Arrays;7import java.util.Collections;8import java.util.List;9class EqualsBuilder {10 private boolean isEquals = true;11 public static boolean reflectionEquals(Object obj, Object obj2) {12 return reflectionEquals(obj, obj2, false, (Class<?>) null, (String[]) null);13 }14 public static boolean reflectionEquals(Object obj, Object obj2, String[] strArr) {15 return reflectionEquals(obj, obj2, false, (Class<?>) null, strArr);16 }17 public static boolean reflectionEquals(Object obj, Object obj2, boolean z) {18 return reflectionEquals(obj, obj2, z, (Class<?>) null, (String[]) null);19 }20 public static boolean reflectionEquals(Object obj, Object obj2, boolean z, Class<?> cls) {21 return reflectionEquals(obj, obj2, z, cls, (String[]) null);22 }23 /* JADX WARNING: Code restructure failed: missing block: B:12:0x0029, code lost:24 if (r1.isInstance(r12) == false) goto L_0x002d;25 */26 /* JADX WARNING: Code restructure failed: missing block: B:8:0x001c, code lost:27 if (r2.isInstance(r11) == false) goto L_0x002c;28 */29 /* Code decompiled incorrectly, please refer to instructions dump. */30 public static boolean reflectionEquals(java.lang.Object r11, java.lang.Object r12, boolean r13, java.lang.Class<?> r14, java.lang.String[] r15) {31 /*32 if (r11 != r12) goto L_0x000433 r11 = 134 return r1135 L_0x0004:36 r0 = 037 if (r11 == 0) goto L_0x005638 if (r12 != 0) goto L_0x000a39 goto L_0x005640 L_0x000a:41 java.lang.Class r1 = r11.getClass()42 java.lang.Class r2 = r12.getClass()43 boolean r3 = r1.isInstance(r12)44 if (r3 == 0) goto L_0x001f45 boolean r3 = r2.isInstance(r11)46 if (r3 != 0) goto L_0x002d47 goto L_0x002c48 L_0x001f:49 boolean r3 = r2.isInstance(r11)50 if (r3 == 0) goto L_0x005651 boolean r3 = r1.isInstance(r12)52 if (r3 != 0) goto L_0x002c53 goto L_0x002d54 L_0x002c:55 r1 = r256 L_0x002d:57 org.mockito.internal.matchers.apachecommons.EqualsBuilder r10 = new org.mockito.internal.matchers.apachecommons.EqualsBuilder58 r10.<init>()59 r4 = r1160 r5 = r1261 r6 = r162 r7 = r1063 r8 = r1364 r9 = r1565 reflectionAppend(r4, r5, r6, r7, r8, r9) // Catch:{ IllegalArgumentException -> 0x0056 }66 L_0x003b:67 java.lang.Class r2 = r1.getSuperclass() // Catch:{ IllegalArgumentException -> 0x0056 }68 if (r2 == 0) goto L_0x005169 if (r1 == r14) goto L_0x005170 java.lang.Class r1 = r1.getSuperclass() // Catch:{ IllegalArgumentException -> 0x0056 }71 r2 = r1172 r3 = r1273 r4 = r174 r5 = r1075 r6 = r1376 r7 = r1577 reflectionAppend(r2, r3, r4, r5, r6, r7) // Catch:{ IllegalArgumentException -> 0x0056 }78 goto L_0x003b79 L_0x0051:80 boolean r11 = r10.isEquals()81 return r1182 L_0x0056:83 return r084 */85 throw new UnsupportedOperationException("Method not decompiled: org.mockito.internal.matchers.apachecommons.EqualsBuilder.reflectionEquals(java.lang.Object, java.lang.Object, boolean, java.lang.Class, java.lang.String[]):boolean");86 }87 private static void reflectionAppend(Object obj, Object obj2, Class<?> cls, EqualsBuilder equalsBuilder, boolean z, String[] strArr) {88 Field[] declaredFields = cls.getDeclaredFields();89 List asList = strArr != null ? Arrays.asList(strArr) : Collections.emptyList();90 AccessibleObject.setAccessible(declaredFields, true);91 for (int i = 0; i < declaredFields.length && equalsBuilder.isEquals; i++) {92 Field field = declaredFields[i];93 if (!asList.contains(field.getName()) && field.getName().indexOf(36) == -1 && ((z || !Modifier.isTransient(field.getModifiers())) && !Modifier.isStatic(field.getModifiers()))) {94 try {95 equalsBuilder.append(field.get(obj), field.get(obj2));96 } catch (IllegalAccessException unused) {97 throw new InternalError("Unexpected IllegalAccessException");98 }99 }100 }101 }102 public EqualsBuilder appendSuper(boolean z) {103 this.isEquals = z & this.isEquals;104 return this;105 }106 public EqualsBuilder append(Object obj, Object obj2) {107 if (!this.isEquals || obj == obj2) {108 return this;109 }110 boolean z = false;111 if (obj == null || obj2 == null) {112 setEquals(false);113 return this;114 }115 if (!obj.getClass().isArray()) {116 if (!(obj instanceof BigDecimal) || !(obj2 instanceof BigDecimal)) {117 this.isEquals = obj.equals(obj2);118 } else {119 if (((BigDecimal) obj).compareTo((BigDecimal) obj2) == 0) {120 z = true;121 }122 this.isEquals = z;123 }124 } else if (obj.getClass() != obj2.getClass()) {125 setEquals(false);126 } else if (obj instanceof long[]) {127 append((long[]) obj, (long[]) obj2);128 } else if (obj instanceof int[]) {129 append((int[]) obj, (int[]) obj2);130 } else if (obj instanceof short[]) {131 append((short[]) obj, (short[]) obj2);132 } else if (obj instanceof char[]) {133 append((char[]) obj, (char[]) obj2);134 } else if (obj instanceof byte[]) {135 append((byte[]) obj, (byte[]) obj2);136 } else if (obj instanceof double[]) {137 append((double[]) obj, (double[]) obj2);138 } else if (obj instanceof float[]) {139 append((float[]) obj, (float[]) obj2);140 } else if (obj instanceof boolean[]) {141 append((boolean[]) obj, (boolean[]) obj2);142 } else {143 append((Object[]) obj, (Object[]) obj2);144 }145 return this;146 }147 public EqualsBuilder append(long j, long j2) {148 this.isEquals = (j == j2) & this.isEquals;149 return this;150 }151 public EqualsBuilder append(int i, int i2) {152 this.isEquals = (i == i2) & this.isEquals;153 return this;154 }155 public EqualsBuilder append(short s, short s2) {156 this.isEquals = (s == s2) & this.isEquals;157 return this;158 }159 public EqualsBuilder append(char c, char c2) {160 this.isEquals = (c == c2) & this.isEquals;161 return this;162 }163 public EqualsBuilder append(byte b, byte b2) {164 this.isEquals = (b == b2) & this.isEquals;165 return this;166 }167 public EqualsBuilder append(double d, double d2) {168 if (!this.isEquals) {169 return this;170 }171 return append(Double.doubleToLongBits(d), Double.doubleToLongBits(d2));172 }173 public EqualsBuilder append(float f, float f2) {174 if (!this.isEquals) {175 return this;176 }177 return append(Float.floatToIntBits(f), Float.floatToIntBits(f2));178 }179 public EqualsBuilder append(boolean z, boolean z2) {180 this.isEquals = (z == z2) & this.isEquals;181 return this;182 }183 public EqualsBuilder append(Object[] objArr, Object[] objArr2) {184 if (!this.isEquals || objArr == objArr2) {185 return this;186 }187 if (objArr == null || objArr2 == null) {188 setEquals(false);189 return this;190 } else if (objArr.length != objArr2.length) {191 setEquals(false);192 return this;193 } else {194 for (int i = 0; i < objArr.length && this.isEquals; i++) {195 append(objArr[i], objArr2[i]);196 }197 return this;198 }199 }200 public EqualsBuilder append(long[] jArr, long[] jArr2) {201 if (!this.isEquals || jArr == jArr2) {202 return this;203 }204 if (jArr == null || jArr2 == null) {205 setEquals(false);206 return this;207 } else if (jArr.length != jArr2.length) {208 setEquals(false);209 return this;210 } else {211 for (int i = 0; i < jArr.length && this.isEquals; i++) {212 append(jArr[i], jArr2[i]);213 }214 return this;215 }216 }217 public EqualsBuilder append(int[] iArr, int[] iArr2) {218 if (!this.isEquals || iArr == iArr2) {219 return this;220 }221 if (iArr == null || iArr2 == null) {222 setEquals(false);223 return this;224 } else if (iArr.length != iArr2.length) {225 setEquals(false);226 return this;227 } else {228 for (int i = 0; i < iArr.length && this.isEquals; i++) {229 append(iArr[i], iArr2[i]);230 }231 return this;232 }233 }234 public EqualsBuilder append(short[] sArr, short[] sArr2) {235 if (!this.isEquals || sArr == sArr2) {236 return this;237 }238 if (sArr == null || sArr2 == null) {239 setEquals(false);240 return this;241 } else if (sArr.length != sArr2.length) {242 setEquals(false);243 return this;244 } else {245 for (int i = 0; i < sArr.length && this.isEquals; i++) {246 append(sArr[i], sArr2[i]);247 }248 return this;249 }250 }251 public EqualsBuilder append(char[] cArr, char[] cArr2) {252 if (!this.isEquals || cArr == cArr2) {253 return this;254 }255 if (cArr == null || cArr2 == null) {256 setEquals(false);257 return this;258 } else if (cArr.length != cArr2.length) {259 setEquals(false);260 return this;261 } else {262 for (int i = 0; i < cArr.length && this.isEquals; i++) {263 append(cArr[i], cArr2[i]);264 }265 return this;266 }267 }268 public EqualsBuilder append(byte[] bArr, byte[] bArr2) {269 if (!this.isEquals || bArr == bArr2) {270 return this;271 }272 if (bArr == null || bArr2 == null) {273 setEquals(false);274 return this;275 } else if (bArr.length != bArr2.length) {276 setEquals(false);277 return this;278 } else {279 for (int i = 0; i < bArr.length && this.isEquals; i++) {280 append(bArr[i], bArr2[i]);281 }282 return this;283 }284 }285 public EqualsBuilder append(double[] dArr, double[] dArr2) {286 if (!this.isEquals || dArr == dArr2) {287 return this;288 }289 if (dArr == null || dArr2 == null) {290 setEquals(false);291 return this;292 } else if (dArr.length != dArr2.length) {293 setEquals(false);294 return this;295 } else {296 for (int i = 0; i < dArr.length && this.isEquals; i++) {297 append(dArr[i], dArr2[i]);298 }299 return this;300 }301 }302 public EqualsBuilder append(float[] fArr, float[] fArr2) {303 if (!this.isEquals || fArr == fArr2) {304 return this;305 }306 if (fArr == null || fArr2 == null) {307 setEquals(false);308 return this;309 } else if (fArr.length != fArr2.length) {310 setEquals(false);311 return this;312 } else {313 for (int i = 0; i < fArr.length && this.isEquals; i++) {314 append(fArr[i], fArr2[i]);315 }316 return this;317 }318 }319 public EqualsBuilder append(boolean[] zArr, boolean[] zArr2) {320 if (!this.isEquals || zArr == zArr2) {321 return this;322 }323 if (zArr == null || zArr2 == null) {324 setEquals(false);325 return this;326 } else if (zArr.length != zArr2.length) {327 setEquals(false);328 return this;329 } else {330 for (int i = 0; i < zArr.length && this.isEquals; i++) {331 append(zArr[i], zArr2[i]);332 }333 return this;334 }335 }336 public boolean isEquals() {337 return this.isEquals;338 }339 /* access modifiers changed from: protected */340 public void setEquals(boolean z) {341 this.isEquals = z;342 }343}...

Full Screen

Full Screen

Source:a-EqualsBuilder.java Github

copy

Full Screen

...8/* 0*/import java.util.Collections;9/* 0*/import java.util.List;10/* 0*/11/* 0*/class EqualsBuilder {12/* 0*/ private boolean isEquals = true;13/* 0*/ 14/* 0*/ public static boolean reflectionEquals(Object lhs, Object rhs) {15/* 116*/ return reflectionEquals(lhs, rhs, false, null, null);16/* 0*/ }17/* 0*/ 18/* 0*/ public static boolean reflectionEquals(Object lhs, Object rhs, String[] excludeFields) {19/* 139*/ return reflectionEquals(lhs, rhs, false, null, excludeFields);20/* 0*/ }21/* 0*/ 22/* 0*/ public static boolean reflectionEquals(Object lhs, Object rhs, boolean testTransients) {23/* 163*/ return reflectionEquals(lhs, rhs, testTransients, null, null);24/* 0*/ }25/* 0*/ 26/* 0*/ public static boolean reflectionEquals(Object lhs, Object rhs, boolean testTransients, Class reflectUpToClass) {27/* 192*/ return reflectionEquals(lhs, rhs, testTransients, reflectUpToClass, null);28/* 0*/ }29/* 0*/ 30/* 0*/ public static boolean reflectionEquals(Object lhs, Object rhs, boolean testTransients, Class reflectUpToClass, String[] excludeFields) {31/* 0*/ Class<?> testClass;32/* 223*/ if (lhs == rhs)33/* 224*/ return true; 34/* 226*/ if (lhs == null || rhs == null)35/* 227*/ return false; 36/* 233*/ Class<?> lhsClass = lhs.getClass();37/* 234*/ Class<?> rhsClass = rhs.getClass();38/* 236*/ if (lhsClass.isInstance(rhs)) {39/* 237*/ testClass = lhsClass;40/* 238*/ if (!rhsClass.isInstance(lhs))41/* 240*/ testClass = rhsClass; 42/* 242*/ } else if (rhsClass.isInstance(lhs)) {43/* 243*/ testClass = rhsClass;44/* 244*/ if (!lhsClass.isInstance(rhs))45/* 246*/ testClass = lhsClass; 46/* 0*/ } else {47/* 250*/ return false;48/* 0*/ } 49/* 252*/ EqualsBuilder equalsBuilder = new EqualsBuilder();50/* 0*/ try {51/* 254*/ reflectionAppend(lhs, rhs, testClass, equalsBuilder, testTransients, excludeFields);52/* 255*/ while (testClass.getSuperclass() != null && testClass != reflectUpToClass) {53/* 256*/ testClass = testClass.getSuperclass();54/* 257*/ reflectionAppend(lhs, rhs, testClass, equalsBuilder, testTransients, excludeFields);55/* 0*/ } 56/* 259*/ } catch (IllegalArgumentException e) {57/* 265*/ return false;58/* 0*/ } 59/* 267*/ return equalsBuilder.isEquals();60/* 0*/ }61/* 0*/ 62/* 0*/ private static void reflectionAppend(Object lhs, Object rhs, Class clazz, EqualsBuilder builder, boolean useTransients, String[] excludeFields) {63/* 288*/ Field[] fields = clazz.getDeclaredFields();64/* 289*/ List excludedFieldList = (excludeFields != null) ? Arrays.<String>asList(excludeFields) : Collections.EMPTY_LIST;65/* 290*/ AccessibleObject.setAccessible((AccessibleObject[])fields, true);66/* 291*/ for (int i = 0; i < fields.length && builder.isEquals; i++) {67/* 292*/ Field f = fields[i];68/* 293*/ if (!excludedFieldList.contains(f.getName()) && f.getName().indexOf('$') == -1 && (useTransients || !Modifier.isTransient(f.getModifiers())) && !Modifier.isStatic(f.getModifiers()))69/* 0*/ try {70/* 298*/ builder.append(f.get(lhs), f.get(rhs));71/* 299*/ } catch (IllegalAccessException e) {72/* 302*/ throw new InternalError("Unexpected IllegalAccessException");73/* 0*/ } 74/* 0*/ } 75/* 0*/ }76/* 0*/ 77/* 0*/ public EqualsBuilder appendSuper(boolean superEquals) {78/* 318*/ this.isEquals &= superEquals;79/* 319*/ return this;80/* 0*/ }81/* 0*/ 82/* 0*/ public EqualsBuilder append(Object lhs, Object rhs) {83/* 333*/ if (!this.isEquals)84/* 334*/ return this; 85/* 336*/ if (lhs == rhs)86/* 337*/ return this; 87/* 339*/ if (lhs == null || rhs == null) {88/* 340*/ setEquals(false);89/* 341*/ return this;90/* 0*/ } 91/* 343*/ Class<?> lhsClass = lhs.getClass();92/* 344*/ if (!lhsClass.isArray()) {93/* 345*/ if (lhs instanceof BigDecimal && rhs instanceof BigDecimal) {94/* 346*/ this.isEquals = (((BigDecimal)lhs).compareTo((BigDecimal)rhs) == 0);95/* 0*/ } else {96/* 349*/ this.isEquals = lhs.equals(rhs);97/* 0*/ } 98/* 351*/ } else if (lhs.getClass() != rhs.getClass()) {99/* 353*/ setEquals(false);100/* 357*/ } else if (lhs instanceof long[]) {101/* 358*/ append((long[])lhs, (long[])rhs);102/* 359*/ } else if (lhs instanceof int[]) {103/* 360*/ append((int[])lhs, (int[])rhs);104/* 361*/ } else if (lhs instanceof short[]) {105/* 362*/ append((short[])lhs, (short[])rhs);106/* 363*/ } else if (lhs instanceof char[]) {107/* 364*/ append((char[])lhs, (char[])rhs);108/* 365*/ } else if (lhs instanceof byte[]) {109/* 366*/ append((byte[])lhs, (byte[])rhs);110/* 367*/ } else if (lhs instanceof double[]) {111/* 368*/ append((double[])lhs, (double[])rhs);112/* 369*/ } else if (lhs instanceof float[]) {113/* 370*/ append((float[])lhs, (float[])rhs);114/* 371*/ } else if (lhs instanceof boolean[]) {115/* 372*/ append((boolean[])lhs, (boolean[])rhs);116/* 0*/ } else {117/* 375*/ append((Object[])lhs, (Object[])rhs);118/* 0*/ } 119/* 377*/ return this;120/* 0*/ }121/* 0*/ 122/* 0*/ public EqualsBuilder append(long lhs, long rhs) {123/* 392*/ this.isEquals &= (lhs == rhs) ? true : false;124/* 393*/ return this;125/* 0*/ }126/* 0*/ 127/* 0*/ public EqualsBuilder append(int lhs, int rhs) {128/* 404*/ this.isEquals &= (lhs == rhs) ? true : false;129/* 405*/ return this;130/* 0*/ }131/* 0*/ 132/* 0*/ public EqualsBuilder append(short lhs, short rhs) {133/* 416*/ this.isEquals &= (lhs == rhs) ? true : false;134/* 417*/ return this;135/* 0*/ }136/* 0*/ 137/* 0*/ public EqualsBuilder append(char lhs, char rhs) {138/* 428*/ this.isEquals &= (lhs == rhs) ? true : false;139/* 429*/ return this;140/* 0*/ }141/* 0*/ 142/* 0*/ public EqualsBuilder append(byte lhs, byte rhs) {143/* 440*/ this.isEquals &= (lhs == rhs) ? true : false;144/* 441*/ return this;145/* 0*/ }146/* 0*/ 147/* 0*/ public EqualsBuilder append(double lhs, double rhs) {148/* 458*/ if (!this.isEquals)149/* 459*/ return this; 150/* 461*/ return append(Double.doubleToLongBits(lhs), Double.doubleToLongBits(rhs));151/* 0*/ }152/* 0*/ 153/* 0*/ public EqualsBuilder append(float lhs, float rhs) {154/* 478*/ if (!this.isEquals)155/* 479*/ return this; 156/* 481*/ return append(Float.floatToIntBits(lhs), Float.floatToIntBits(rhs));157/* 0*/ }158/* 0*/ 159/* 0*/ public EqualsBuilder append(boolean lhs, boolean rhs) {160/* 492*/ this.isEquals &= (lhs == rhs) ? true : false;161/* 493*/ return this;162/* 0*/ }163/* 0*/ 164/* 0*/ public EqualsBuilder append(Object[] lhs, Object[] rhs) {165/* 507*/ if (!this.isEquals)166/* 508*/ return this; 167/* 510*/ if (lhs == rhs)168/* 511*/ return this; 169/* 513*/ if (lhs == null || rhs == null) {170/* 514*/ setEquals(false);171/* 515*/ return this;172/* 0*/ } 173/* 517*/ if (lhs.length != rhs.length) {174/* 518*/ setEquals(false);175/* 519*/ return this;176/* 0*/ } 177/* 521*/ for (int i = 0; i < lhs.length && this.isEquals; i++)178/* 522*/ append(lhs[i], rhs[i]); 179/* 524*/ return this;180/* 0*/ }181/* 0*/ 182/* 0*/ public EqualsBuilder append(long[] lhs, long[] rhs) {183/* 538*/ if (!this.isEquals)184/* 539*/ return this; 185/* 541*/ if (lhs == rhs)186/* 542*/ return this; 187/* 544*/ if (lhs == null || rhs == null) {188/* 545*/ setEquals(false);189/* 546*/ return this;190/* 0*/ } 191/* 548*/ if (lhs.length != rhs.length) {192/* 549*/ setEquals(false);193/* 550*/ return this;194/* 0*/ } 195/* 552*/ for (int i = 0; i < lhs.length && this.isEquals; i++)196/* 553*/ append(lhs[i], rhs[i]); 197/* 555*/ return this;198/* 0*/ }199/* 0*/ 200/* 0*/ public EqualsBuilder append(int[] lhs, int[] rhs) {201/* 569*/ if (!this.isEquals)202/* 570*/ return this; 203/* 572*/ if (lhs == rhs)204/* 573*/ return this; 205/* 575*/ if (lhs == null || rhs == null) {206/* 576*/ setEquals(false);207/* 577*/ return this;208/* 0*/ } 209/* 579*/ if (lhs.length != rhs.length) {210/* 580*/ setEquals(false);211/* 581*/ return this;212/* 0*/ } 213/* 583*/ for (int i = 0; i < lhs.length && this.isEquals; i++)214/* 584*/ append(lhs[i], rhs[i]); 215/* 586*/ return this;216/* 0*/ }217/* 0*/ 218/* 0*/ public EqualsBuilder append(short[] lhs, short[] rhs) {219/* 600*/ if (!this.isEquals)220/* 601*/ return this; 221/* 603*/ if (lhs == rhs)222/* 604*/ return this; 223/* 606*/ if (lhs == null || rhs == null) {224/* 607*/ setEquals(false);225/* 608*/ return this;226/* 0*/ } 227/* 610*/ if (lhs.length != rhs.length) {228/* 611*/ setEquals(false);229/* 612*/ return this;230/* 0*/ } 231/* 614*/ for (int i = 0; i < lhs.length && this.isEquals; i++)232/* 615*/ append(lhs[i], rhs[i]); 233/* 617*/ return this;234/* 0*/ }235/* 0*/ 236/* 0*/ public EqualsBuilder append(char[] lhs, char[] rhs) {237/* 631*/ if (!this.isEquals)238/* 632*/ return this; 239/* 634*/ if (lhs == rhs)240/* 635*/ return this; 241/* 637*/ if (lhs == null || rhs == null) {242/* 638*/ setEquals(false);243/* 639*/ return this;244/* 0*/ } 245/* 641*/ if (lhs.length != rhs.length) {246/* 642*/ setEquals(false);247/* 643*/ return this;248/* 0*/ } 249/* 645*/ for (int i = 0; i < lhs.length && this.isEquals; i++)250/* 646*/ append(lhs[i], rhs[i]); 251/* 648*/ return this;252/* 0*/ }253/* 0*/ 254/* 0*/ public EqualsBuilder append(byte[] lhs, byte[] rhs) {255/* 662*/ if (!this.isEquals)256/* 663*/ return this; 257/* 665*/ if (lhs == rhs)258/* 666*/ return this; 259/* 668*/ if (lhs == null || rhs == null) {260/* 669*/ setEquals(false);261/* 670*/ return this;262/* 0*/ } 263/* 672*/ if (lhs.length != rhs.length) {264/* 673*/ setEquals(false);265/* 674*/ return this;266/* 0*/ } 267/* 676*/ for (int i = 0; i < lhs.length && this.isEquals; i++)268/* 677*/ append(lhs[i], rhs[i]); 269/* 679*/ return this;270/* 0*/ }271/* 0*/ 272/* 0*/ public EqualsBuilder append(double[] lhs, double[] rhs) {273/* 693*/ if (!this.isEquals)274/* 694*/ return this; 275/* 696*/ if (lhs == rhs)276/* 697*/ return this; 277/* 699*/ if (lhs == null || rhs == null) {278/* 700*/ setEquals(false);279/* 701*/ return this;280/* 0*/ } 281/* 703*/ if (lhs.length != rhs.length) {282/* 704*/ setEquals(false);283/* 705*/ return this;284/* 0*/ } 285/* 707*/ for (int i = 0; i < lhs.length && this.isEquals; i++)286/* 708*/ append(lhs[i], rhs[i]); 287/* 710*/ return this;288/* 0*/ }289/* 0*/ 290/* 0*/ public EqualsBuilder append(float[] lhs, float[] rhs) {291/* 724*/ if (!this.isEquals)292/* 725*/ return this; 293/* 727*/ if (lhs == rhs)294/* 728*/ return this; 295/* 730*/ if (lhs == null || rhs == null) {296/* 731*/ setEquals(false);297/* 732*/ return this;298/* 0*/ } 299/* 734*/ if (lhs.length != rhs.length) {300/* 735*/ setEquals(false);301/* 736*/ return this;302/* 0*/ } 303/* 738*/ for (int i = 0; i < lhs.length && this.isEquals; i++)304/* 739*/ append(lhs[i], rhs[i]); 305/* 741*/ return this;306/* 0*/ }307/* 0*/ 308/* 0*/ public EqualsBuilder append(boolean[] lhs, boolean[] rhs) {309/* 755*/ if (!this.isEquals)310/* 756*/ return this; 311/* 758*/ if (lhs == rhs)312/* 759*/ return this; 313/* 761*/ if (lhs == null || rhs == null) {314/* 762*/ setEquals(false);315/* 763*/ return this;316/* 0*/ } 317/* 765*/ if (lhs.length != rhs.length) {318/* 766*/ setEquals(false);319/* 767*/ return this;320/* 0*/ } 321/* 769*/ for (int i = 0; i < lhs.length && this.isEquals; i++)322/* 770*/ append(lhs[i], rhs[i]); 323/* 772*/ return this;324/* 0*/ }325/* 0*/ 326/* 0*/ public boolean isEquals() {327/* 782*/ return this.isEquals;328/* 0*/ }329/* 0*/ 330/* 0*/ protected void setEquals(boolean isEquals) {331/* 792*/ this.isEquals = isEquals;332/* 0*/ }333/* 0*/}...

Full Screen

Full Screen

Source:b-EqualsBuilder.java Github

copy

Full Screen

...8/* 0*/import java.util.Collections;9/* 0*/import java.util.List;10/* 0*/11/* 0*/class EqualsBuilder {12/* 0*/ private boolean isEquals = true;13/* 0*/ 14/* 0*/ public static boolean reflectionEquals(Object lhs, Object rhs) {15/* 116*/ return reflectionEquals(lhs, rhs, false, null, null);16/* 0*/ }17/* 0*/ 18/* 0*/ public static boolean reflectionEquals(Object lhs, Object rhs, String[] excludeFields) {19/* 139*/ return reflectionEquals(lhs, rhs, false, null, excludeFields);20/* 0*/ }21/* 0*/ 22/* 0*/ public static boolean reflectionEquals(Object lhs, Object rhs, boolean testTransients) {23/* 163*/ return reflectionEquals(lhs, rhs, testTransients, null, null);24/* 0*/ }25/* 0*/ 26/* 0*/ public static boolean reflectionEquals(Object lhs, Object rhs, boolean testTransients, Class reflectUpToClass) {27/* 192*/ return reflectionEquals(lhs, rhs, testTransients, reflectUpToClass, null);28/* 0*/ }29/* 0*/ 30/* 0*/ public static boolean reflectionEquals(Object lhs, Object rhs, boolean testTransients, Class reflectUpToClass, String[] excludeFields) {31/* 0*/ Class<?> testClass;32/* 223*/ if (lhs == rhs)33/* 224*/ return true; 34/* 226*/ if (lhs == null || rhs == null)35/* 227*/ return false; 36/* 233*/ Class<?> lhsClass = lhs.getClass();37/* 234*/ Class<?> rhsClass = rhs.getClass();38/* 236*/ if (lhsClass.isInstance(rhs)) {39/* 237*/ testClass = lhsClass;40/* 238*/ if (!rhsClass.isInstance(lhs))41/* 240*/ testClass = rhsClass; 42/* 242*/ } else if (rhsClass.isInstance(lhs)) {43/* 243*/ testClass = rhsClass;44/* 244*/ if (!lhsClass.isInstance(rhs))45/* 246*/ testClass = lhsClass; 46/* 0*/ } else {47/* 250*/ return false;48/* 0*/ } 49/* 252*/ EqualsBuilder equalsBuilder = new EqualsBuilder();50/* 0*/ try {51/* 254*/ reflectionAppend(lhs, rhs, testClass, equalsBuilder, testTransients, excludeFields);52/* 255*/ while (testClass.getSuperclass() != null && testClass != reflectUpToClass) {53/* 256*/ testClass = testClass.getSuperclass();54/* 257*/ reflectionAppend(lhs, rhs, testClass, equalsBuilder, testTransients, excludeFields);55/* 0*/ } 56/* 259*/ } catch (RuntimeException e) {57/* 265*/ return false;58/* 0*/ } 59/* 267*/ return equalsBuilder.isEquals();60/* 0*/ }61/* 0*/ 62/* 0*/ private static void reflectionAppend(Object lhs, Object rhs, Class clazz, EqualsBuilder builder, boolean useTransients, String[] excludeFields) {63/* 288*/ Field[] fields = clazz.getDeclaredFields();64/* 289*/ List excludedFieldList = (excludeFields != null) ? Arrays.<String>asList(excludeFields) : Collections.EMPTY_LIST;65/* 290*/ AccessibleObject.setAccessible((AccessibleObject[])fields, true);66/* 291*/ for (int i = 0; i < fields.length && builder.isEquals; i++) {67/* 292*/ Field f = fields[i];68/* 293*/ if (!excludedFieldList.contains(f.getName()) && f.getName().indexOf('$') == -1 && (useTransients || !Modifier.isTransient(f.getModifiers())) && !Modifier.isStatic(f.getModifiers()))69/* 0*/ try {70/* 298*/ builder.append(f.get(lhs), f.get(rhs));71/* 299*/ } catch (ReflectiveOperationException e) {72/* 302*/ throw new InternalError("Unexpected IllegalAccessException");73/* 0*/ } 74/* 0*/ } 75/* 0*/ }76/* 0*/ 77/* 0*/ public EqualsBuilder appendSuper(boolean superEquals) {78/* 318*/ this.isEquals &= superEquals;79/* 319*/ return this;80/* 0*/ }81/* 0*/ 82/* 0*/ public EqualsBuilder append(Object lhs, Object rhs) {83/* 333*/ if (!this.isEquals)84/* 334*/ return this; 85/* 336*/ if (lhs == rhs)86/* 337*/ return this; 87/* 339*/ if (lhs == null || rhs == null) {88/* 340*/ setEquals(false);89/* 341*/ return this;90/* 0*/ } 91/* 343*/ Class<?> lhsClass = lhs.getClass();92/* 344*/ if (!lhsClass.isArray()) {93/* 345*/ if (lhs instanceof BigDecimal && rhs instanceof BigDecimal) {94/* 346*/ this.isEquals = (((BigDecimal)lhs).compareTo((BigDecimal)rhs) == 0);95/* 0*/ } else {96/* 349*/ this.isEquals = lhs.equals(rhs);97/* 0*/ } 98/* 351*/ } else if (lhs.getClass() != rhs.getClass()) {99/* 353*/ setEquals(false);100/* 357*/ } else if (lhs instanceof long[]) {101/* 358*/ append((long[])lhs, (long[])rhs);102/* 359*/ } else if (lhs instanceof int[]) {103/* 360*/ append((int[])lhs, (int[])rhs);104/* 361*/ } else if (lhs instanceof short[]) {105/* 362*/ append((short[])lhs, (short[])rhs);106/* 363*/ } else if (lhs instanceof char[]) {107/* 364*/ append((char[])lhs, (char[])rhs);108/* 365*/ } else if (lhs instanceof byte[]) {109/* 366*/ append((byte[])lhs, (byte[])rhs);110/* 367*/ } else if (lhs instanceof double[]) {111/* 368*/ append((double[])lhs, (double[])rhs);112/* 369*/ } else if (lhs instanceof float[]) {113/* 370*/ append((float[])lhs, (float[])rhs);114/* 371*/ } else if (lhs instanceof boolean[]) {115/* 372*/ append((boolean[])lhs, (boolean[])rhs);116/* 0*/ } else {117/* 375*/ append((Object[])lhs, (Object[])rhs);118/* 0*/ } 119/* 377*/ return this;120/* 0*/ }121/* 0*/ 122/* 0*/ public EqualsBuilder append(long lhs, long rhs) {123/* 392*/ this.isEquals &= (lhs == rhs) ? true : false;124/* 393*/ return this;125/* 0*/ }126/* 0*/ 127/* 0*/ public EqualsBuilder append(int lhs, int rhs) {128/* 404*/ this.isEquals &= (lhs == rhs) ? true : false;129/* 405*/ return this;130/* 0*/ }131/* 0*/ 132/* 0*/ public EqualsBuilder append(short lhs, short rhs) {133/* 416*/ this.isEquals &= (lhs == rhs) ? true : false;134/* 417*/ return this;135/* 0*/ }136/* 0*/ 137/* 0*/ public EqualsBuilder append(char lhs, char rhs) {138/* 428*/ this.isEquals &= (lhs == rhs) ? true : false;139/* 429*/ return this;140/* 0*/ }141/* 0*/ 142/* 0*/ public EqualsBuilder append(byte lhs, byte rhs) {143/* 440*/ this.isEquals &= (lhs == rhs) ? true : false;144/* 441*/ return this;145/* 0*/ }146/* 0*/ 147/* 0*/ public EqualsBuilder append(double lhs, double rhs) {148/* 458*/ if (!this.isEquals)149/* 459*/ return this; 150/* 461*/ return append(Double.doubleToLongBits(lhs), Double.doubleToLongBits(rhs));151/* 0*/ }152/* 0*/ 153/* 0*/ public EqualsBuilder append(float lhs, float rhs) {154/* 478*/ if (!this.isEquals)155/* 479*/ return this; 156/* 481*/ return append(Float.floatToIntBits(lhs), Float.floatToIntBits(rhs));157/* 0*/ }158/* 0*/ 159/* 0*/ public EqualsBuilder append(boolean lhs, boolean rhs) {160/* 492*/ this.isEquals &= (lhs == rhs) ? true : false;161/* 493*/ return this;162/* 0*/ }163/* 0*/ 164/* 0*/ public EqualsBuilder append(Object[] lhs, Object[] rhs) {165/* 507*/ if (!this.isEquals)166/* 508*/ return this; 167/* 510*/ if (lhs == rhs)168/* 511*/ return this; 169/* 513*/ if (lhs == null || rhs == null) {170/* 514*/ setEquals(false);171/* 515*/ return this;172/* 0*/ } 173/* 517*/ if (lhs.length != rhs.length) {174/* 518*/ setEquals(false);175/* 519*/ return this;176/* 0*/ } 177/* 521*/ for (int i = 0; i < lhs.length && this.isEquals; i++)178/* 522*/ append(lhs[i], rhs[i]); 179/* 524*/ return this;180/* 0*/ }181/* 0*/ 182/* 0*/ public EqualsBuilder append(long[] lhs, long[] rhs) {183/* 538*/ if (!this.isEquals)184/* 539*/ return this; 185/* 541*/ if (lhs == rhs)186/* 542*/ return this; 187/* 544*/ if (lhs == null || rhs == null) {188/* 545*/ setEquals(false);189/* 546*/ return this;190/* 0*/ } 191/* 548*/ if (lhs.length != rhs.length) {192/* 549*/ setEquals(false);193/* 550*/ return this;194/* 0*/ } 195/* 552*/ for (int i = 0; i < lhs.length && this.isEquals; i++)196/* 553*/ append(lhs[i], rhs[i]); 197/* 555*/ return this;198/* 0*/ }199/* 0*/ 200/* 0*/ public EqualsBuilder append(int[] lhs, int[] rhs) {201/* 569*/ if (!this.isEquals)202/* 570*/ return this; 203/* 572*/ if (lhs == rhs)204/* 573*/ return this; 205/* 575*/ if (lhs == null || rhs == null) {206/* 576*/ setEquals(false);207/* 577*/ return this;208/* 0*/ } 209/* 579*/ if (lhs.length != rhs.length) {210/* 580*/ setEquals(false);211/* 581*/ return this;212/* 0*/ } 213/* 583*/ for (int i = 0; i < lhs.length && this.isEquals; i++)214/* 584*/ append(lhs[i], rhs[i]); 215/* 586*/ return this;216/* 0*/ }217/* 0*/ 218/* 0*/ public EqualsBuilder append(short[] lhs, short[] rhs) {219/* 600*/ if (!this.isEquals)220/* 601*/ return this; 221/* 603*/ if (lhs == rhs)222/* 604*/ return this; 223/* 606*/ if (lhs == null || rhs == null) {224/* 607*/ setEquals(false);225/* 608*/ return this;226/* 0*/ } 227/* 610*/ if (lhs.length != rhs.length) {228/* 611*/ setEquals(false);229/* 612*/ return this;230/* 0*/ } 231/* 614*/ for (int i = 0; i < lhs.length && this.isEquals; i++)232/* 615*/ append(lhs[i], rhs[i]); 233/* 617*/ return this;234/* 0*/ }235/* 0*/ 236/* 0*/ public EqualsBuilder append(char[] lhs, char[] rhs) {237/* 631*/ if (!this.isEquals)238/* 632*/ return this; 239/* 634*/ if (lhs == rhs)240/* 635*/ return this; 241/* 637*/ if (lhs == null || rhs == null) {242/* 638*/ setEquals(false);243/* 639*/ return this;244/* 0*/ } 245/* 641*/ if (lhs.length != rhs.length) {246/* 642*/ setEquals(false);247/* 643*/ return this;248/* 0*/ } 249/* 645*/ for (int i = 0; i < lhs.length && this.isEquals; i++)250/* 646*/ append(lhs[i], rhs[i]); 251/* 648*/ return this;252/* 0*/ }253/* 0*/ 254/* 0*/ public EqualsBuilder append(byte[] lhs, byte[] rhs) {255/* 662*/ if (!this.isEquals)256/* 663*/ return this; 257/* 665*/ if (lhs == rhs)258/* 666*/ return this; 259/* 668*/ if (lhs == null || rhs == null) {260/* 669*/ setEquals(false);261/* 670*/ return this;262/* 0*/ } 263/* 672*/ if (lhs.length != rhs.length) {264/* 673*/ setEquals(false);265/* 674*/ return this;266/* 0*/ } 267/* 676*/ for (int i = 0; i < lhs.length && this.isEquals; i++)268/* 677*/ append(lhs[i], rhs[i]); 269/* 679*/ return this;270/* 0*/ }271/* 0*/ 272/* 0*/ public EqualsBuilder append(double[] lhs, double[] rhs) {273/* 693*/ if (!this.isEquals)274/* 694*/ return this; 275/* 696*/ if (lhs == rhs)276/* 697*/ return this; 277/* 699*/ if (lhs == null || rhs == null) {278/* 700*/ setEquals(false);279/* 701*/ return this;280/* 0*/ } 281/* 703*/ if (lhs.length != rhs.length) {282/* 704*/ setEquals(false);283/* 705*/ return this;284/* 0*/ } 285/* 707*/ for (int i = 0; i < lhs.length && this.isEquals; i++)286/* 708*/ append(lhs[i], rhs[i]); 287/* 710*/ return this;288/* 0*/ }289/* 0*/ 290/* 0*/ public EqualsBuilder append(float[] lhs, float[] rhs) {291/* 724*/ if (!this.isEquals)292/* 725*/ return this; 293/* 727*/ if (lhs == rhs)294/* 728*/ return this; 295/* 730*/ if (lhs == null || rhs == null) {296/* 731*/ setEquals(false);297/* 732*/ return this;298/* 0*/ } 299/* 734*/ if (lhs.length != rhs.length) {300/* 735*/ setEquals(false);301/* 736*/ return this;302/* 0*/ } 303/* 738*/ for (int i = 0; i < lhs.length && this.isEquals; i++)304/* 739*/ append(lhs[i], rhs[i]); 305/* 741*/ return this;306/* 0*/ }307/* 0*/ 308/* 0*/ public EqualsBuilder append(boolean[] lhs, boolean[] rhs) {309/* 755*/ if (!this.isEquals)310/* 756*/ return this; 311/* 758*/ if (lhs == rhs)312/* 759*/ return this; 313/* 761*/ if (lhs == null || rhs == null) {314/* 762*/ setEquals(false);315/* 763*/ return this;316/* 0*/ } 317/* 765*/ if (lhs.length != rhs.length) {318/* 766*/ setEquals(false);319/* 767*/ return this;320/* 0*/ } 321/* 769*/ for (int i = 0; i < lhs.length && this.isEquals; i++)322/* 770*/ append(lhs[i], rhs[i]); 323/* 772*/ return this;324/* 0*/ }325/* 0*/ 326/* 0*/ public boolean isEquals() {327/* 782*/ return this.isEquals;328/* 0*/ }329/* 0*/ 330/* 0*/ protected void setEquals(boolean isEquals) {331/* 792*/ this.isEquals = isEquals;332/* 0*/ }333/* 0*/}...

Full Screen

Full Screen

isEquals

Using AI Code Generation

copy

Full Screen

1import org.mockito.internal.matchers.apachecommons.EqualsBuilder;2public class EqualsBuilderTest {3 public static void main(String[] args) {4 EqualsBuilder equalsBuilder = new EqualsBuilder();5 System.out.println(equalsBuilder.isEquals());6 }7}

Full Screen

Full Screen

isEquals

Using AI Code Generation

copy

Full Screen

1import org.mockito.internal.matchers.apachecommons.EqualsBuilder;2import org.mockito.internal.matchers.apachecommons.HashCodeBuilder;3import org.mockito.internal.matchers.apachecommons.Lang;4public class EqualsBuilderTest {5 public static void main(String[] args) {6 EqualsBuilderTest test = new EqualsBuilderTest();7 test.testEquals();8 test.testEquals2();9 }10 public void testEquals() {11 EqualsBuilder equalsBuilder = new EqualsBuilder();12 equalsBuilder.appendSuper(true);13 equalsBuilder.append(1, 1);14 equalsBuilder.append(2, 2);15 equalsBuilder.append(3, 3);16 equalsBuilder.append(4, 4);17 equalsBuilder.append(5, 5);18 equalsBuilder.append(6, 6);19 equalsBuilder.append(7, 7);20 equalsBuilder.append(8, 8);21 equalsBuilder.append(9, 9);22 equalsBuilder.append(10, 10);23 equalsBuilder.append(11, 11);24 equalsBuilder.append(12, 12);25 equalsBuilder.append(13, 13);26 equalsBuilder.append(14, 14);27 equalsBuilder.append(15, 15);28 equalsBuilder.append(16, 16);29 equalsBuilder.append(17, 17);30 equalsBuilder.append(18, 18);31 equalsBuilder.append(19, 19);32 equalsBuilder.append(20, 20);33 equalsBuilder.append(21, 21);34 equalsBuilder.append(22, 22);35 equalsBuilder.append(23, 23);36 equalsBuilder.append(24, 24);37 equalsBuilder.append(25, 25);38 equalsBuilder.append(26, 26);39 equalsBuilder.append(27, 27);40 equalsBuilder.append(28, 28);41 equalsBuilder.append(29, 29);42 equalsBuilder.append(30, 30);43 equalsBuilder.append(31, 31);44 equalsBuilder.append(32, 32);45 equalsBuilder.append(33, 33);46 equalsBuilder.append(34, 34);47 equalsBuilder.append(35, 35);48 equalsBuilder.append(36, 36);49 equalsBuilder.append(37, 37);50 equalsBuilder.append(38, 38);51 equalsBuilder.append(39, 39);52 equalsBuilder.append(

Full Screen

Full Screen

isEquals

Using AI Code Generation

copy

Full Screen

1package com.example;2import java.util.ArrayList;3import java.util.List;4import org.junit.Assert;5import org.junit.Test;6import org.mockito.internal.matchers.apachecommons.EqualsBuilder;7public class EqualsBuilderTest {8 public void testEqualsBuilder() {9 List<String> list1 = new ArrayList<String>();10 list1.add("a");11 list1.add("b");12 list1.add("c");13 list1.add("d");14 List<String> list2 = new ArrayList<String>();15 list2.add("a");16 list2.add("b");17 list2.add("c");18 list2.add("d");19 Assert.assertTrue(EqualsBuilder.reflectionEquals(list1, list2));20 }21}22Related Posts: Mockito - How to use when() and thenReturn() methods23Mockito - How to use when() and thenThrow() methods24Mockito - How to use when() and thenAnswer() methods25Mockito - How to use doThrow() method26Mockito - How to use doAnswer() method27Mockito - How to use doNothing() method28Mockito - How to use doReturn() method29Mockito - How to use doCallRealMethod() method30Mockito - How to use doNothing() method31Mockito - How to use doAnswer() method32Mockito - How to use doThrow() method33Mockito - How to use doCallRealMethod() method34Mockito - How to use doReturn() method35Mockito - How to use when() and thenAnswer() methods36Mockito - How to use when() and thenThrow() methods

Full Screen

Full Screen

isEquals

Using AI Code Generation

copy

Full Screen

1import org.mockito.internal.matchers.apachecommons.EqualsBuilder;2import org.mockito.internal.matchers.apachecommons.HashCodeBuilder;3public class EqualsBuilderTest {4 public static void main(String[] args) {5 EqualsBuilder equalsBuilder = new EqualsBuilder();6 boolean result = equalsBuilder.append("test", "test").isEquals();7 System.out.println(result);8 }9}

Full Screen

Full Screen

isEquals

Using AI Code Generation

copy

Full Screen

1import org.mockito.internal.matchers.apachecommons.EqualsBuilder;2import org.mockito.internal.matchers.apachecommons.HashCodeBuilder;3public class EqualsBuilderTest {4 public static void main(String[] args) {5 EqualsBuilder equalsBuilder = new EqualsBuilder();6 System.out.println(equalsBuilder.append(1, 1));7 System.out.println(equalsBuilder.append("hello", "hello"));8 System.out.println(equalsBuilder.append(1, 2));9 System.out.println(equalsBuilder.append("hello", "world"));10 System.out.println(equalsBuilder.append(1, 1));11 System.out.println(equalsBuilder.append("hello", "hello"));12 }13}

Full Screen

Full Screen

isEquals

Using AI Code Generation

copy

Full Screen

1public class TestEqualsBuilder {2 public static void main(String[] args) {3 EqualsBuilder eq = new EqualsBuilder();4 String str1 = "Hello";5 String str2 = "Hello";6 String str3 = "Hello";7 String str4 = "Hello";8 String str5 = "Hello";9 String str6 = "Hello";10 String str7 = "Hello";11 String str8 = "Hello";12 String str9 = "Hello";13 String str10 = "Hello";14 String str11 = "Hello";15 String str12 = "Hello";16 String str13 = "Hello";17 String str14 = "Hello";18 String str15 = "Hello";19 String str16 = "Hello";20 String str17 = "Hello";21 String str18 = "Hello";22 String str19 = "Hello";23 String str20 = "Hello";24 String str21 = "Hello";25 String str22 = "Hello";26 String str23 = "Hello";27 String str24 = "Hello";28 String str25 = "Hello";29 String str26 = "Hello";30 String str27 = "Hello";31 String str28 = "Hello";32 String str29 = "Hello";33 String str30 = "Hello";34 String str31 = "Hello";35 String str32 = "Hello";36 String str33 = "Hello";37 String str34 = "Hello";38 String str35 = "Hello";39 String str36 = "Hello";40 String str37 = "Hello";41 String str38 = "Hello";42 String str39 = "Hello";43 String str40 = "Hello";44 String str41 = "Hello";45 String str42 = "Hello";46 String str43 = "Hello";47 String str44 = "Hello";48 String str45 = "Hello";49 String str46 = "Hello";50 String str47 = "Hello";51 String str48 = "Hello";52 String str49 = "Hello";53 String str50 = "Hello";54 String str51 = "Hello";55 String str52 = "Hello";56 String str53 = "Hello";57 String str54 = "Hello";58 String str55 = "Hello";59 String str56 = "Hello";60 String str57 = "Hello";61 String str58 = "Hello";62 String str59 = "Hello";

Full Screen

Full Screen

isEquals

Using AI Code Generation

copy

Full Screen

1package org.mockito.internal.matchers.apachecommons;2import org.mockito.internal.matchers.apachecommons.EqualsBuilder;3public class EqualsBuilderTest {4 public static void main(String[] args) {5 EqualsBuilderTest test = new EqualsBuilderTest();6 test.testEquals();7 }8 public void testEquals() {9 Object o1 = new Object();10 Object o2 = new Object();11 EqualsBuilder eb = new EqualsBuilder();12 boolean b = eb.append(o1, o2).isEquals();13 System.out.println(b);14 }15}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Mockito automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful