当前位置: 首页>>代码示例>>Java>>正文


Java TypeUtils.isDecimalNumber方法代码示例

本文整理汇总了Java中com.holonplatform.core.internal.utils.TypeUtils.isDecimalNumber方法的典型用法代码示例。如果您正苦于以下问题:Java TypeUtils.isDecimalNumber方法的具体用法?Java TypeUtils.isDecimalNumber怎么用?Java TypeUtils.isDecimalNumber使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.holonplatform.core.internal.utils.TypeUtils的用法示例。


在下文中一共展示了TypeUtils.isDecimalNumber方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getNumberFormat

import com.holonplatform.core.internal.utils.TypeUtils; //导入方法依赖的package包/类
/**
 * Gets the NumberFormat to use to convert values
 * @param locale Locale to use
 * @return the numberFormat If a NumberFormat was specified using {@link #setNumberFormat(NumberFormat)}, this one
 *         is returned. Otherwise, a NumberFormat is obtained using given Locale
 */
public NumberFormat getNumberFormat(Locale locale) {
	Locale lcl = (locale != null) ? locale
			: LocalizationContext.getCurrent().filter(l -> l.isLocalized()).flatMap(l -> l.getLocale())
					.orElse(Locale.getDefault());
	return (numberFormat != null) ? numberFormat
			: TypeUtils.isDecimalNumber(numberType) ? NumberFormat.getNumberInstance(lcl)
					: NumberFormat.getIntegerInstance(lcl);
}
 
开发者ID:holon-platform,项目名称:holon-vaadin7,代码行数:15,代码来源:StringToNumberConverter.java

示例2: setupLocaleSymbolsInputValidation

import com.holonplatform.core.internal.utils.TypeUtils; //导入方法依赖的package包/类
/**
 * Setup user input validation allowed symbols according to current Locale and number type
 */
protected void setupLocaleSymbolsInputValidation() {

	Locale locale = LocalizationContext.getCurrent().filter(l -> l.isLocalized()).flatMap(l -> l.getLocale())
			.orElse(getLocale());
	if (locale == null) {
		// use default
		locale = Locale.getDefault();
	}

	// check grouping
	boolean useGrouping = true;
	if (getInternalField().getConverter() instanceof StringToNumberConverter) {
		NumberFormat nf = ((StringToNumberConverter<?>) getInternalField().getConverter()).getNumberFormat(locale);
		if (nf != null) {
			useGrouping = nf.isGroupingUsed();
		}
	}

	DecimalFormatSymbols dfs = new DecimalFormatSymbols(locale);

	char[] symbols = null;
	if (useGrouping) {
		if (TypeUtils.isDecimalNumber(getType())) {
			symbols = new char[] { dfs.getGroupingSeparator(), dfs.getDecimalSeparator() };
		} else {
			symbols = new char[] { dfs.getGroupingSeparator() };
		}
	} else {
		if (TypeUtils.isDecimalNumber(getType())) {
			symbols = new char[] { dfs.getDecimalSeparator() };
		}
	}

	getInternalField().setAllowedSymbols(symbols);
}
 
开发者ID:holon-platform,项目名称:holon-vaadin7,代码行数:39,代码来源:NumberField.java

示例3: getNumberFormat

import com.holonplatform.core.internal.utils.TypeUtils; //导入方法依赖的package包/类
@Override
public NumberFormat getNumberFormat(Class<? extends Number> numberType, int decimalPositions,
		boolean disableGrouping) {

	int decimals = decimalPositions;
	if (decimals < 0) {
		// use default, if any
		if (getLocalization() != null) {
			decimals = getLocalization().getDefaultDecimalPositions().orElse(-1);
		}
	}

	NumberFormat format = null;

	if (TypeUtils.isDecimalNumber(numberType)) {
		format = NumberFormat.getInstance(checkLocalized());
		if (decimals > -1) {
			format.setMinimumFractionDigits(decimals);
			format.setMaximumFractionDigits(decimals);
		}
	} else {
		format = NumberFormat.getIntegerInstance(checkLocalized());
	}

	if (disableGrouping) {
		format.setGroupingUsed(false);
	}
	return format;
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:30,代码来源:DefaultLocalizationContext.java

示例4: setupLocaleSymbolsInputValidation

import com.holonplatform.core.internal.utils.TypeUtils; //导入方法依赖的package包/类
/**
 * Setup user input validation allowed symbols according to current Locale and number type
 */
protected void setupLocaleSymbolsInputValidation() {

	Locale locale = LocalizationContext.getCurrent().filter(l -> l.isLocalized()).flatMap(l -> l.getLocale())
			.orElse(getLocale());
	if (locale == null) {
		// use default
		locale = Locale.getDefault();
	}

	// check grouping
	boolean useGrouping = true;
	NumberFormat nf = getConverter().getNumberFormat(locale);
	if (nf != null) {
		useGrouping = nf.isGroupingUsed();
	}

	DecimalFormatSymbols dfs = new DecimalFormatSymbols(locale);

	char[] symbols = null;
	if (useGrouping) {
		if (TypeUtils.isDecimalNumber(getType())) {
			symbols = new char[] { dfs.getGroupingSeparator(), dfs.getDecimalSeparator() };
		} else {
			symbols = new char[] { dfs.getGroupingSeparator() };
		}
	} else {
		if (TypeUtils.isDecimalNumber(getType())) {
			symbols = new char[] { dfs.getDecimalSeparator() };
		}
	}

	getInternalField().setAllowedSymbols(symbols);
}
 
开发者ID:holon-platform,项目名称:holon-vaadin,代码行数:37,代码来源:NumberField.java

示例5: serializeParameterValue

import com.holonplatform.core.internal.utils.TypeUtils; //导入方法依赖的package包/类
/**
 * Serialize given parameter value as String
 * @param value Value to serialize
 * @param dateFormat Date format to use with {@link Date} value types
 * @return Serialized value
 */
private static String serializeParameterValue(Object value, DateFormat dateFormat) {
	if (!isNullOrEmpty(value)) {
		if (TypeUtils.isString(value.getClass())) {
			return (String) value;
		}
		if (TypeUtils.isBoolean(value.getClass())) {
			return ((Boolean) value) ? "true" : "false";
		}
		if (TypeUtils.isEnum(value.getClass())) {
			int ordinal = ((Enum<?>) value).ordinal();
			return String.valueOf(ordinal);
		}
		if (TypeUtils.isNumber(value.getClass())) {
			if (TypeUtils.isDecimalNumber(value.getClass())) {
				return PARAMETER_VALUE_DECIMAL_FORMAT.format(value);
			} else {
				return PARAMETER_VALUE_INTEGER_FORMAT.format(value);
			}
		}
		if (TypeUtils.isDate(value.getClass())) {
			return dateFormat.format((Date) value);
		}
		if (TypeUtils.isTemporal(value.getClass())) {
			TemporalType type = TemporalType.getTemporalType((Temporal) value);
			if (type == null) {
				type = TemporalType.DATE;
			}
			switch (type) {
			case DATE_TIME:
				return DateTimeFormatter.ISO_LOCAL_DATE_TIME.format((Temporal) value);
			case TIME:
				return DateTimeFormatter.ISO_LOCAL_TIME.format((Temporal) value);
			case DATE:
			default:
				return DateTimeFormatter.ISO_LOCAL_DATE.format((Temporal) value);
			}
		}
		throw new UnsupportedOperationException(
				"Parameter value serialization " + "not supported for type: " + value.getClass().getName());
	}
	return null;
}
 
开发者ID:holon-platform,项目名称:holon-vaadin7,代码行数:49,代码来源:ViewNavigationUtils.java

示例6: digits

import com.holonplatform.core.internal.utils.TypeUtils; //导入方法依赖的package包/类
/**
 * Build a validator that checks that given {@link Number} value is a number within accepted range.
 * <p>
 * Supported data types: {@link Number}
 * </p>
 * @param <T> Validator type
 * @param integral maximum number of integral digits accepted for this number (not negative)
 * @param fractional maximum number of fractional digits accepted for this number (not negative)
 * @param message Validation error message
 * @param messageCode Optional validation error message localization code
 * @return Validator
 */
@SuppressWarnings("serial")
static <T extends Number> Validator<T> digits(int integral, int fractional, String message, String messageCode) {
	if (integral < 0) {
		throw new IllegalArgumentException("Integral digits max number cannot be negative");
	}
	if (fractional < 0) {
		throw new IllegalArgumentException("Fractional digits max number cannot be negative");
	}
	return new BuiltinValidator<T>() {

		@Override
		public void validate(T v) throws ValidationException {
			if (v != null) {
				String string = null;
				if (TypeUtils.isDecimalNumber(v.getClass())) {
					BigDecimal bd = (v instanceof BigDecimal) ? (BigDecimal) v
							: BigDecimal.valueOf(v.doubleValue());
					string = bd.stripTrailingZeros().toPlainString();
				} else {
					BigInteger bi = (v instanceof BigInteger) ? (BigInteger) v : BigInteger.valueOf(v.longValue());
					string = bi.toString();
				}
				if (string != null) {
					if (string.startsWith("-")) {
						string = string.substring(1);
					}
					int index = string.indexOf(".");
					int itg = index < 0 ? string.length() : index;
					int fct = index < 0 ? 0 : string.length() - index - 1;
					if (itg > integral) {
						throw new ValidationException(message, messageCode);
					}
					if (fct > fractional) {
						throw new ValidationException(message, messageCode);
					}
				}
			}
		}

		@Override
		public Optional<ValidatorDescriptor> getDescriptor() {
			return Optional
					.of(ValidatorDescriptor.builder().integerDigits(integral).fractionDigits(fractional).build());
		}
	};
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:59,代码来源:Validator.java

示例7: serializeValue

import com.holonplatform.core.internal.utils.TypeUtils; //导入方法依赖的package包/类
/**
 * Serialize given {@link LiteralValue} as SQL string.
 * @param value Value to serialize
 * @param temporalType Optional temporal type
 * @return Serialized SQL value
 */
public static String serializeValue(Object value, TemporalType temporalType) {

	if (value != null) {

		// CharSequence
		if (TypeUtils.isCharSequence(value.getClass())) {
			return "'" + value.toString() + "'";
		}

		// Number
		if (TypeUtils.isNumber(value.getClass())) {
			if (TypeUtils.isDecimalNumber(value.getClass())) {
				return DECIMAL_FORMAT.format(value);
			}
			return INTEGER_FORMAT.format(value);
		}

		// Enum (by default, ordinal value is used)
		if (TypeUtils.isEnum(value.getClass())) {
			return String.valueOf(((Enum<?>) value).ordinal());
		}

		// Reader
		if (Reader.class.isAssignableFrom(value.getClass())) {
			try (Reader reader = ((Reader) value)) {
				StringBuilder sb = new StringBuilder();
				sb.append("'");
				int buffer;
				while ((buffer = reader.read()) != -1) {
					sb.append((char) buffer);
				}
				sb.append("'");
				return sb.toString();
			} catch (IOException e) {
				throw new QueryBuildException("Failed to read value from the Reader [" + value + "]", e);
			}
		}

		// Date and times
		Optional<String> serializedDate = serializeDate(value, temporalType);
		if (serializedDate.isPresent()) {
			return "'" + serializedDate.get() + "'";
		}

		// defaults to toString()
		return value.toString();
	}

	return null;
}
 
开发者ID:holon-platform,项目名称:holon-datastore-jdbc,代码行数:57,代码来源:SQLValueSerializer.java


注:本文中的com.holonplatform.core.internal.utils.TypeUtils.isDecimalNumber方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。