## lang/src/main/java/org/apache/commons/lang3/tuple/Pair.java:158-180
158:         // @formatter:on
159:     }
160: 
161:     /**
162:      * Compares this pair to another based on the two elements.
163:      *
164:      * @param obj  the object to compare to, null returns false.
165:      * @return true if the elements of the pair are equal.
166:      */
167:     @Override
168:     public boolean equals(final Object obj) {
169:         if (obj == this) {
170:             return true;
171:         }
172:         if (obj instanceof Map.Entry<?, ?>) {
173:             final Map.Entry<?, ?> other = (Map.Entry<?, ?>) obj;
174:             return Objects.equals(getKey(), other.getKey())
175:                     && Objects.equals(getValue(), other.getValue());
176:         }
177:         return false;
178:     }
179: 
180:     /**

## lang/src/main/java/org/apache/commons/lang3/builder/ReflectionToStringBuilder.java:601-665
601:      * @return Whether or not to append the given {@link Field}.
602:      */
603:     protected boolean accept(final Field field) {
604:         if (field.getName().indexOf(ClassUtils.INNER_CLASS_SEPARATOR_CHAR) != -1) {
605:             // Reject field from inner class.
606:             return false;
607:         }
608:         if (Modifier.isTransient(field.getModifiers()) && !isAppendTransients()) {
609:             // Reject transient fields.
610:             return false;
611:         }
612:         if (Modifier.isStatic(field.getModifiers()) && !isAppendStatics()) {
613:             // Reject static fields.
614:             return false;
615:         }
616: 
617:         if (this.excludeFieldNames != null
618:             && Arrays.binarySearch(this.excludeFieldNames, field.getName()) >= 0) {
619:             // Reject fields from the getExcludeFieldNames list.
620:             return false;
621:         }
622: 
623:         if (ArrayUtils.isNotEmpty(includeFieldNames)) {
624:             // Accept fields from the getIncludeFieldNames list. {@code null} or empty means all fields are included. All fields are included by default.
625:             return Arrays.binarySearch(this.includeFieldNames, field.getName()) >= 0;
626:         }
627: 
628:         return !field.isAnnotationPresent(ToStringExclude.class);
629:     }
630: 
631:     /**
632:      * Appends the fields and values defined by the given object of the given Class.
633:      *
634:      * <p>
635:      * If a cycle is detected as an object is &quot;toString()'ed&quot;, such an object is rendered as if
636:      * {@code Object.toString()} had been called and not implemented by the object.
637:      * </p>
638:      *
639:      * @param clazz
640:      *            The class of object parameter
641:      */
642:     protected void appendFieldsIn(final Class<?> clazz) {
643:         if (clazz.isArray()) {
644:             reflectionAppendArray(getObject());
645:             return;
646:         }
647:         // The elements in the returned array are not sorted and are not in any particular order.
648:         final Field[] fields = ArraySorter.sort(clazz.getDeclaredFields(), Comparator.comparing(Field::getName));
649:         AccessibleObject.setAccessible(fields, true);
650:         for (final Field field : fields) {
651:             final String fieldName = field.getName();
652:             if (accept(field)) {
653:                 try {
654:                     // Warning: Field.get(Object) creates wrappers objects
655:                     // for primitive types.
656:                     final Object fieldValue = getValue(field);
657:                     if (!excludeNullValues || fieldValue != null) {
658:                         this.append(fieldName, fieldValue, !field.isAnnotationPresent(ToStringSummary.class));
659:                     }
660:                 } catch (final IllegalAccessException e) {
661:                     // this can't happen. Would get a Security exception instead throw a runtime exception in case the
662:                     // impossible happens.
663:                     throw new IllegalStateException(e);
664:                 }
665:             }

## lang/src/test/java/org/apache/commons/lang3/tuple/PairTest.java:248-284
248:     private void testMapEntry(final Map<Integer, String> map) {
249:         map.put(0, "foo");
250:         final Entry<Integer, String> entry = map.entrySet().iterator().next();
251:         final Pair<Integer, String> pair = ImmutablePair.of(0, "foo");
252:         assertEquals(pair, entry);
253:         assertEquals(pair.hashCode(), entry.hashCode());
254:         // LANG-1736:
255:         map.clear();
256:         map.put(0, "value1");
257:         map.put(1, "value2");
258:         map.entrySet().forEach(e -> {
259:             final Pair<Integer, String> p = ImmutablePair.of(e.getKey(), e.getValue());
260:             assertEquals(p, e);
261:             assertEquals(p.hashCode(), e.hashCode());
262:         });
263:     }
264: 
265:     @Test
266:     void testOfNonNull() {
267:         assertNullPointerException(() -> Pair.ofNonNull(null, null));
268:         assertNullPointerException(() -> Pair.ofNonNull(null, "x"));
269:         assertNullPointerException(() -> Pair.ofNonNull("x", null));
270:         final Pair<String, String> pair = Pair.ofNonNull("x", "y");
271:         assertEquals("x", pair.getLeft());
272:         assertEquals("y", pair.getRight());
273:     }
274: 
275:     @Test
276:     void testPairOfAbstractMapSimpleEntry() {
277:         final Entry<Integer, String> entry = new AbstractMap.SimpleEntry<>(0, "foo");
278:         final Pair<Integer, String> pair = Pair.of(entry);
279:         assertEquals(entry.getKey(), pair.getLeft());
280:         assertEquals(entry.getValue(), pair.getRight());
281:         assertEquals(entry, pair);
282:         assertEquals(entry.hashCode(), pair.hashCode());
283:         assertEquals(pair, entry);
284:         assertEquals(pair.hashCode(), entry.hashCode());
