本文整理汇总了Java中jodd.util.StringUtil.containsOnlyDigits方法的典型用法代码示例。如果您正苦于以下问题:Java StringUtil.containsOnlyDigits方法的具体用法?Java StringUtil.containsOnlyDigits怎么用?Java StringUtil.containsOnlyDigits使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jodd.util.StringUtil
的用法示例。
在下文中一共展示了StringUtil.containsOnlyDigits方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convert
import jodd.util.StringUtil; //导入方法依赖的package包/类
public Date convert(Object value) {
if (value == null) {
return null;
}
if (value instanceof Date) {
return (Date) value;
}
if (value instanceof Calendar) {
return new Date(((Calendar)value).getTimeInMillis());
}
if (value instanceof JDateTime) {
return ((JDateTime) value).convertToDate();
}
if (value instanceof Number) {
return new Date(((Number) value).longValue());
}
String stringValue = value.toString().trim();
if (!StringUtil.containsOnlyDigits(stringValue)) {
// try to parse default string format
JDateTime jdt = new JDateTime(stringValue, JDateTime.DEFAULT_FORMAT);
return jdt.convertToDate();
}
try {
long milliseconds = Long.parseLong(stringValue);
return new Date(milliseconds);
} catch (NumberFormatException nfex) {
throw new TypeConversionException(value, nfex);
}
}
示例2: convert
import jodd.util.StringUtil; //导入方法依赖的package包/类
public JDateTime convert(Object value) {
if (value == null) {
return null;
}
if (value instanceof JDateTime) {
return (JDateTime) value;
}
if (value instanceof Calendar) {
return new JDateTime((Calendar)value);
}
if (value instanceof Date) {
return new JDateTime((Date) value);
}
if (value instanceof Number) {
return new JDateTime(((Number) value).longValue());
}
if (value instanceof JulianDateStamp) {
return new JDateTime((JulianDateStamp) value);
}
if (value instanceof DateTimeStamp) {
return new JDateTime((DateTimeStamp) value);
}
String stringValue = value.toString().trim();
if (!StringUtil.containsOnlyDigits(stringValue)) {
return new JDateTime(stringValue, JDateTime.DEFAULT_FORMAT);
}
try {
long milliseconds = Long.parseLong(stringValue);
return new JDateTime(milliseconds);
} catch (NumberFormatException nfex) {
throw new TypeConversionException(value, nfex);
}
}
示例3: convert
import jodd.util.StringUtil; //导入方法依赖的package包/类
public Time convert(Object value) {
if (value == null) {
return null;
}
if (value instanceof Time) {
return (Time) value;
}
if (value instanceof Calendar) {
return new Time(((Calendar) value).getTimeInMillis());
}
if (value instanceof Date) {
return new Time(((Date)value).getTime());
}
if (value instanceof JDateTime) {
return ((JDateTime) value).convertToSqlTime();
}
if (value instanceof Number) {
return new Time(((Number) value).longValue());
}
String stringValue = value.toString().trim();
// try yyyy-mm-dd for valueOf
if (!StringUtil.containsOnlyDigits(stringValue)) {
try {
return Time.valueOf(stringValue);
} catch (IllegalArgumentException iaex) {
throw new TypeConversionException(value, iaex);
}
}
// assume string to be a number
try {
long milliseconds = Long.parseLong(stringValue);
return new Time(milliseconds);
} catch (NumberFormatException nfex) {
throw new TypeConversionException(value, nfex);
}
}
示例4: convert
import jodd.util.StringUtil; //导入方法依赖的package包/类
public Date convert(Object value) {
if (value == null) {
return null;
}
if (value instanceof Date) {
return (Date) value;
}
if (value instanceof Calendar) {
return new Date(((Calendar)value).getTimeInMillis());
}
if (value instanceof java.util.Date) {
return new Date(((java.util.Date)value).getTime());
}
if (value instanceof JDateTime) {
return ((JDateTime) value).convertToSqlDate();
}
if (value instanceof Number) {
return new Date(((Number) value).longValue());
}
String stringValue = value.toString().trim();
// try yyyy-mm-dd for valueOf
if (!StringUtil.containsOnlyDigits(stringValue)) {
try {
return Date.valueOf(stringValue);
} catch (IllegalArgumentException iaex) {
throw new TypeConversionException(value, iaex);
}
}
// assume string to be a number
try {
long milliseconds = Long.parseLong(stringValue);
return new Date(milliseconds);
} catch (NumberFormatException nfex) {
throw new TypeConversionException(value, nfex);
}
}
示例5: convert
import jodd.util.StringUtil; //导入方法依赖的package包/类
public Timestamp convert(Object value) {
if (value == null) {
return null;
}
if (value instanceof Timestamp) {
return (Timestamp) value;
}
if (value instanceof Calendar) {
Calendar calendar = (Calendar) value;
return new Timestamp(calendar.getTimeInMillis());
}
if (value instanceof Date) {
Date date = (Date) value;
return new Timestamp(date.getTime());
}
if (value instanceof JDateTime) {
return ((JDateTime) value).convertToSqlTimestamp();
}
if (value instanceof Number) {
return new Timestamp(((Number)value).longValue());
}
String stringValue = value.toString().trim();
// try yyyy-mm-dd for valueOf
if (!StringUtil.containsOnlyDigits(stringValue)) {
try {
return Timestamp.valueOf(stringValue);
} catch (IllegalArgumentException iaex) {
throw new TypeConversionException(value, iaex);
}
}
// assume string to be a number
try {
long milliseconds = Long.parseLong(stringValue);
return new Timestamp(milliseconds);
} catch (NumberFormatException nfex) {
throw new TypeConversionException(value, nfex);
}
}