/** * Returns an integer from the defaults. If the value for {@code key} is not * an {@code int}, {@code 0} is returned. * * @param key * an {@code Object} specifying the integer * @return the {@code int} * @throws NullPointerException * if {@code key} is {@code null} */ public static int getInt(Object key) { return getInt(key, null); }
/** * Returns an integer from the defaults. If the value for {@code key} is not * an {@code int}, {@code 0} is returned. * * @param key * an {@code Object} specifying the integer * @return the {@code int} * @throws NullPointerException * if {@code key} is {@code null} */ public static int getInt(Object key) { return getInt(key, null); }
/** * Returns an integer from the defaults. If the value for {@code key} is not * an {@code int}, {@code 0} is returned. * * @param key * an {@code Object} specifying the integer * @return the {@code int} * @throws NullPointerException * if {@code key} is {@code null} */ public static int getInt(Object key) { return getInt(key, null); }
/** * Returns an integer from the defaults. If the value for {@code key} is not * an {@code int}, {@code 0} is returned. * * @param key * an {@code Object} specifying the integer * @return the {@code int} * @throws NullPointerException * if {@code key} is {@code null} */ public static int getInt(Object key) { return getInt(key, null); }
/** * test that the getInt doesn't choke on non-numbers */ @Test public void testGetIntLenientWithUnparseable() { String key = "badInt"; Locale locale = JComponent.getDefaultLocale(); String columnString = UIManagerExt.getString(key, locale); if (columnString == null) { LOG.info("cant run test - no resource found for key: " + key); return; } try { Integer.decode(columnString); LOG.info("cant run test - valid integer: " + columnString); } catch (Exception ex) { // must not bark UIManagerExt.getInt(key, locale); } } }
/** * test that we get an int from the localized resource. */ @Test public void testGetIntFromResource() { String key = "goodInt"; Locale locale = JComponent.getDefaultLocale(); String columnString = UIManagerExt.getString(key, locale); if (columnString == null) { LOG.info("cant run test - no resource found for key: " + key); return; } Object value = UIManagerExt.getInt(key, locale); assertNotNull(value); assertEquals(Integer.decode(columnString), value); }
/** * test that a value in the UIManager is not overwritten. */ @Test public void testGetIntUIManagerFirst() { String key = "goodInt"; Locale locale = JComponent.getDefaultLocale(); String columnString = UIManagerExt.getString(key, locale); if (columnString == null) { LOG.info("cant run test - no resource found for key: " + key); return; } try { Integer temp = 150; UIManager.put(key, temp); Object value = UIManagerExt.getInt(key, locale); assertNotNull(value); assertEquals(temp, value); } finally { // restore uimanager UIManager.put(key, null); } }