## lang/src/main/java/org/apache/commons/lang3/math/NumberUtils.java:1520-1540
1520:      *   NumberUtils.toInt("", 1)   = 1
1521:      *   NumberUtils.toInt("1", 0)  = 1
1522:      * </pre>
1523:      *
1524:      * @param str          the string to convert, may be null.
1525:      * @param defaultValue the default value.
1526:      * @return the int represented by the string, or the default if conversion fails.
1527:      * @since 2.1
1528:      */
1529:     public static int toInt(final String str, final int defaultValue) {
1530:         try {
1531:             return Integer.parseInt(str);
1532:         } catch (final RuntimeException e) {
1533:             return defaultValue;
1534:         }
1535:     }
1536: 
1537:     /**
1538:      * Converts a {@link String} to a {@code long}, returning {@code zero} if the conversion fails.
1539:      *
1540:      * <p>

## lang/src/main/java/org/apache/commons/lang3/EnumUtils.java:205-235
205: 
206:     /**
207:      * Gets the enum for the class, returning {@code defaultEnum} if not found.
208:      *
209:      * <p>This method differs from {@link Enum#valueOf} in that it does not throw an exception
210:      * for an invalid enum name.</p>
211:      *
212:      * @param <E> the type of the enumeration.
213:      * @param enumClass   the class of the enum to query, null returns default enum.
214:      * @param enumName    the enum name, null returns default enum.
215:      * @param defaultEnum the default enum.
216:      * @return the enum, default enum if not found.
217:      * @since 3.10
218:      */
219:     public static <E extends Enum<E>> E getEnum(final Class<E> enumClass, final String enumName, final E defaultEnum) {
220:         if (enumClass == null || enumName == null) {
221:             return defaultEnum;
222:         }
223:         try {
224:             return Enum.valueOf(enumClass, enumName);
225:         } catch (final IllegalArgumentException e) {
226:             return defaultEnum;
227:         }
228:     }
229: 
230:     /**
231:      * Gets the enum for the class, returning {@code null} if not found.
232:      *
233:      * <p>This method differs from {@link Enum#valueOf} in that it does not throw an exception
234:      * for an invalid enum name and performs case insensitive matching of the name.</p>
235:      *

## lang/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java:1690-1705
1690:     /**
1691:      * Test for {@link NumberUtils#toInt(String, int)}.
1692:      */
1693:     @Test
1694:     void testToIntStringI() {
1695:         assertEquals(12345, NumberUtils.toInt("12345", 5), "toInt(String, int) 1 failed");
1696:         assertEquals(5, NumberUtils.toInt("1234.5", 5), "toInt(String, int) 2 failed");
1697:         assertEquals(5, NumberUtils.toInt("", 5));
1698:         assertEquals(5, NumberUtils.toInt(null, 5));
1699:     }
1700: 
1701:     /**
1702:      * Test for {@link NumberUtils#toLong(String)}.
1703:      */
1704:     @Test
1705:     void testToLongString() {
