本文整理了Java中org.apache.commons.lang3.math.NumberUtils.toByte()
方法的一些代码示例,展示了NumberUtils.toByte()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。NumberUtils.toByte()
方法的具体详情如下:
包路径:org.apache.commons.lang3.math.NumberUtils
类名称:NumberUtils
方法名:toByte
[英]Convert a String
to a byte
, returning zero
if the conversion fails.
If the string is null
, zero
is returned.
NumberUtils.toByte(null) = 0
NumberUtils.toByte("") = 0
NumberUtils.toByte("1") = 1
[中]
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* <p>Convert a <code>String</code> to a <code>byte</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.toByte(null) = 0
* NumberUtils.toByte("") = 0
* NumberUtils.toByte("1") = 1
* </pre>
*
* @param str the string to convert, may be null
* @return the byte represented by the string, or <code>zero</code> if
* conversion fails
* @since 2.5
*/
public static byte toByte(final String str) {
return toByte(str, (byte) 0);
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* Test for {@link NumberUtils#toByte(String)}.
*/
@Test
public void testToByteString() {
assertTrue("toByte(String) 1 failed", NumberUtils.toByte("123") == 123);
assertTrue("toByte(String) 2 failed", NumberUtils.toByte("abc") == 0);
assertTrue("toByte(empty) failed", NumberUtils.toByte("") == 0);
assertTrue("toByte(null) failed", NumberUtils.toByte(null) == 0);
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* Test for {@link NumberUtils#toByte(String, byte)}.
*/
@Test
public void testToByteStringI() {
assertTrue("toByte(String,byte) 1 failed", NumberUtils.toByte("123", (byte) 5) == 123);
assertTrue("toByte(String,byte) 2 failed", NumberUtils.toByte("12.3", (byte) 5) == 5);
}
代码示例来源:origin: tacitknowledge/flip
/** {@inheritDoc } */
public Object convert(String expression, Class outputClass) {
return NumberUtils.toByte(expression);
}
代码示例来源:origin: de.knightsoft-net/gwt-commons-lang3
/**
* <p>Convert a <code>String</code> to a <code>byte</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.toByte(null) = 0
* NumberUtils.toByte("") = 0
* NumberUtils.toByte("1") = 1
* </pre>
*
* @param str the string to convert, may be null
* @return the byte represented by the string, or <code>zero</code> if
* conversion fails
* @since 2.5
*/
public static byte toByte(final String str) {
return toByte(str, (byte) 0);
}
代码示例来源:origin: io.virtdata/virtdata-lib-curves4
/**
* <p>Convert a <code>String</code> to a <code>byte</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.toByte(null) = 0
* NumberUtils.toByte("") = 0
* NumberUtils.toByte("1") = 1
* </pre>
*
* @param str the string to convert, may be null
* @return the byte represented by the string, or <code>zero</code> if
* conversion fails
* @since 2.5
*/
public static byte toByte(final String str) {
return toByte(str, (byte) 0);
}
代码示例来源:origin: io.virtdata/virtdata-lib-realer
/**
* <p>Convert a <code>String</code> to a <code>byte</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.toByte(null) = 0
* NumberUtils.toByte("") = 0
* NumberUtils.toByte("1") = 1
* </pre>
*
* @param str the string to convert, may be null
* @return the byte represented by the string, or <code>zero</code> if
* conversion fails
* @since 2.5
*/
public static byte toByte(final String str) {
return toByte(str, (byte) 0);
}
代码示例来源:origin: apache/syncope
@Override
public T getObject() {
T value = null;
if (list != null && !list.isEmpty()
&& list.get(0) != null && StringUtils.isNotBlank(list.get(0).toString())) {
value = reference.equals(Integer.class)
? reference.cast(NumberUtils.toInt(list.get(0).toString()))
: reference.equals(Long.class)
? reference.cast(NumberUtils.toLong(list.get(0).toString()))
: reference.equals(Short.class)
? reference.cast(NumberUtils.toShort(list.get(0).toString()))
: reference.equals(Float.class)
? reference.cast(NumberUtils.toFloat(list.get(0).toString()))
: reference.equals(byte.class)
? reference.cast(NumberUtils.toByte(list.get(0).toString()))
: reference.cast(NumberUtils.toDouble(list.get(0).toString()));
}
return value;
}
内容来源于网络,如有侵权,请联系作者删除!