/** * <p>Convert a <code>String</code> to an <code>int</code>, returning * <code>zero</code> if the conversion fails.</p> * * <p>If the string is <code>null</code>, <code>zero</code> is returned.</p> * * <pre> * NumberUtils.stringToInt(null) = 0 * NumberUtils.stringToInt("") = 0 * NumberUtils.stringToInt("1") = 1 * </pre> * * @param str the string to convert, may be null * @return the int represented by the string, or <code>zero</code> if * conversion fails * @deprecated Use {@link #toInt(String)} * This method will be removed in Commons Lang 3.0 */ public static int stringToInt(String str) { return toInt(str); }
/** * <p>Convert a <code>String</code> to an <code>int</code>, returning * <code>zero</code> if the conversion fails.</p> * * <p>If the string is <code>null</code>, <code>zero</code> is returned.</p> * * <pre> * NumberUtils.toInt(null) = 0 * NumberUtils.toInt("") = 0 * NumberUtils.toInt("1") = 1 * </pre> * * @param str the string to convert, may be null * @return the int represented by the string, or <code>zero</code> if * conversion fails * @since 2.1 */ public static int toInt(String str) { return toInt(str, 0); }
/** * <p>Convert a <code>String</code> to an <code>int</code>, returning a * default value if the conversion fails.</p> * * <p>If the string is <code>null</code>, the default value is returned.</p> * * <pre> * NumberUtils.stringToInt(null, 1) = 1 * NumberUtils.stringToInt("", 1) = 1 * NumberUtils.stringToInt("1", 0) = 1 * </pre> * * @param str the string to convert, may be null * @param defaultValue the default value * @return the int represented by the string, or the default if conversion fails * @deprecated Use {@link #toInt(String, int)} * This method will be removed in Commons Lang 3.0 */ public static int stringToInt(String str, int defaultValue) { return toInt(str, defaultValue); }
@Override Integer parse(String s) { return StringUtils.isBlank(s) ? null : NumberUtils.toInt(s); } }
public static <A> Integer firstInteger( List<A> list ) { A a = first( list ); if ( a == null ) { return null; } if ( a instanceof Integer ) { return ( Integer ) a; } try { return NumberUtils.toInt( ( String ) a ); } catch ( Exception e ) { logger.warn( "Could not convert list item {} to int", a, e ); } return null; }
public static <A> Integer firstInteger( List<A> list ) { A a = first( list ); if ( a == null ) { return null; } if ( a instanceof Integer ) { return ( Integer ) a; } try { return NumberUtils.toInt( ( String ) a ); } catch ( Exception e ) { logger.warn( "Could not convert list item {} to int", a, e ); } return null; }
public static int getInt( Object obj ) { if ( obj instanceof Integer ) { return ( Integer ) obj; } if ( obj instanceof Number ) { return ( ( Number ) obj ).intValue(); } if ( obj instanceof String ) { return NumberUtils.toInt( ( String ) obj ); } if ( obj instanceof Date ) { return ( int ) ( ( Date ) obj ).getTime(); } if ( obj instanceof byte[] ) { return getInt( ( byte[] ) obj ); } if ( obj instanceof ByteBuffer ) { return getInt( ( ByteBuffer ) obj ); } return 0; }
public static int getInt( Object obj ) { if ( obj instanceof Integer ) { return ( Integer ) obj; } if ( obj instanceof Number ) { return ( ( Number ) obj ).intValue(); } if ( obj instanceof String ) { return NumberUtils.toInt( ( String ) obj ); } if ( obj instanceof Date ) { return ( int ) ( ( Date ) obj ).getTime(); } if ( obj instanceof byte[] ) { return getInt( ( byte[] ) obj ); } if ( obj instanceof ByteBuffer ) { return getInt( ( ByteBuffer ) obj ); } return 0; }
scale = (dec_digits == null) ? 0 : NumberUtils.toInt(dec_digits.toString()); } else if (dec_digits instanceof Integer) { scale = (dec_digits == null) ? 0 : (Integer) dec_digits;
int sepIdx = journalName.indexOf("."); String fileIndex = journalName.substring(sepIdx + 1); int index = NumberUtils.toInt(fileIndex) + 1; String newJournalName = journalName.substring(0, sepIdx) + "." + StringUtils.leftPad(String.valueOf(index), fileIndex.length(), "0");
@Override public int role(String[] roleIds, int id) { int result = 0; // 删除旧记录 UpmsUserRoleExample upmsUserRoleExample = new UpmsUserRoleExample(); upmsUserRoleExample.createCriteria() .andUserIdEqualTo(id); upmsUserRoleMapper.deleteByExample(upmsUserRoleExample); // 增加新记录 if (null != roleIds) { for (String roleId : roleIds) { if (StringUtils.isBlank(roleId)) { continue; } UpmsUserRole upmsUserRole = new UpmsUserRole(); upmsUserRole.setUserId(id); upmsUserRole.setRoleId(NumberUtils.toInt(roleId)); result = upmsUserRoleMapper.insertSelective(upmsUserRole); } } return result; }
@Override public int organization(String[] organizationIds, int id) { int result = 0; // 删除旧记录 UpmsUserOrganizationExample upmsUserOrganizationExample = new UpmsUserOrganizationExample(); upmsUserOrganizationExample.createCriteria() .andUserIdEqualTo(id); upmsUserOrganizationMapper.deleteByExample(upmsUserOrganizationExample); // 增加新记录 if (null != organizationIds) { for (String organizationId : organizationIds) { if (StringUtils.isBlank(organizationId)) { continue; } UpmsUserOrganization upmsUserOrganization = new UpmsUserOrganization(); upmsUserOrganization.setUserId(id); upmsUserOrganization.setOrganizationId(NumberUtils.toInt(organizationId)); result = upmsUserOrganizationMapper.insertSelective(upmsUserOrganization); } } return result; }
public static int parseInt(String s, int defaultValue) { return NumberUtils.toInt(s, defaultValue); }
@Override public int getReplicationFactor() { return NumberUtils.toInt(strategyOptions.get(REPLICATION_FACTOR), 1); }
/** * Get property as integer. * * @param key property key * @return property integer value */ public int getPropertyInt(String key) { return NumberUtils.toInt(getProperty(key)); }
/** * Get the parameter passed by controller. When it's executed in the * validation mode, always returns the given default value 0. * * @return param. 0 if the param was not provided. * @since 3.2.3 */ public static int getParamInt() { return NumberUtils.toInt(getParam("0"), 0); }
public ThriftKsDef(KsDef k) { Assert.notNull(k, "KsDef is null"); name = k.name; strategyClass = k.strategy_class; strategyOptions = k.strategy_options != null ? k.strategy_options : new HashMap<String, String>(); durableWrites = k.durable_writes; setReplicationFactor(NumberUtils.toInt(strategyOptions.get(REPLICATION_FACTOR), 1)); cfDefs = ThriftCfDef.fromThriftList(k.cf_defs); }
int processCount = NumberUtils.toInt(processCountStr, 1); long desirableXmx; // make 500M as default. long permGen = 32 * 1024 * 1024;
/** * Convert the given string to ip and port pair. * <p/> * This supports IP6 and IP4. * <p/> * <ul> * <li>127.0.0.1:30 ==> 127.0.0.1 and 30</li> * <li>2001:0:9d38:90d7:469:1f94:f5bf:cf5d:30 ==> 2001:0:9d38:90d7:469:1f94:f5bf:cf5d and 30</li> * <li>[2001:0:9d38:90d7:469:1f94:f5bf:cf5d]:30 ==> 2001:0:9d38:90d7:469:1f94:f5bf:cf5d and 30</li> * </ul> * * @param ipPortString textual representation of ip and port pair * @param defaultPort default port used when port is invisible. * @return ip and port pair */ public static IPPortPair convertIPAndPortPair(String ipPortString, int defaultPort) { // If it's the scoped IP6 address ipPortString = removeScopedMarkerFromIP(ipPortString); if (InetAddresses.isInetAddress(ipPortString)) { return new IPPortPair(ipPortString, defaultPort); } final int i = ipPortString.lastIndexOf(":"); String ipPart = ipPortString; int portPart = defaultPort; if (i != -1) { portPart = NumberUtils.toInt(ipPortString.substring(i + 1)); ipPart = ipPortString.substring(0, i); } return new IPPortPair(getIP(ipPart), portPart); }