本文整理汇总了Java中javax.validation.constraints.Digits类的典型用法代码示例。如果您正苦于以下问题:Java Digits类的具体用法?Java Digits怎么用?Java Digits使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Digits类属于javax.validation.constraints包,在下文中一共展示了Digits类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import javax.validation.constraints.Digits; //导入依赖的package包/类
@Override
public Object process(AnnotationInfo ctx, Object value) throws Exception {
if (!ctx.isAnnotationPresent(Digits.class)) {
return value;
}
int integrals = ctx.getAnnotation(Digits.class).integer();
String number = "0";
if (integrals > 0) {
number = RandomStringUtils.randomNumeric(integrals);
}
int fractions = ctx.getAnnotation(Digits.class).fraction();
if (fractions > 0) {
number += "." + RandomStringUtils.randomNumeric(fractions);
}
return ReflectionUtils.stringToNumber(number, value.getClass());
}
示例2: updateCost
import javax.validation.constraints.Digits; //导入依赖的package包/类
@Action(
semantics = SemanticsOf.IDEMPOTENT
)
public ToDoItem updateCost(
@Parameter(optionality = Optionality.OPTIONAL)
@Digits(integer = 10, fraction = 2)
final BigDecimal newCost) {
final String titleOf = titleService.titleOf(this);
LOG.debug("%s: cost updated: %s -> %s", titleOf, getCost(), newCost);
// just to simulate a long-running action
try {
Thread.sleep(3000);
} catch (final InterruptedException ignored) {
}
setCost(newCost);
return this;
}
示例3: testDigits
import javax.validation.constraints.Digits; //导入依赖的package包/类
@Test
public void testDigits() {
Set<ConstraintViolation<ObjectWithValidation>> violations = validator.validate(obj, Digits.class);
assertNotNull(violations);
assertEquals(violations.size(), 1);
if (runPeformance) {
long time = System.currentTimeMillis();
for (int index = 0; index < 10000; index++) {
validator.validate(obj, Digits.class);
}
long used = System.currentTimeMillis() - time;
System.out.println("Hibernate Validator [Digits] check used " + used + "ms, avg. " + ((double) used)
/ 10000 + "ms.");
}
}
示例4: fromAnnotation
import javax.validation.constraints.Digits; //导入依赖的package包/类
/**
* Builds a new constraint from the annotation data.
* @param anno JSR-303 annotation instance
* @return a new constraint
*/
public static Constraint fromAnnotation(Annotation anno) {
if (anno instanceof Min) {
return min(((Min) anno).value());
} else if (anno instanceof Max) {
return max(((Max) anno).value());
} else if (anno instanceof Size) {
return size(((Size) anno).min(), ((Size) anno).max());
} else if (anno instanceof Digits) {
return digits(((Digits) anno).integer(), ((Digits) anno).fraction());
} else if (anno instanceof Pattern) {
return pattern(((Pattern) anno).regexp());
} else {
return new Constraint(VALIDATORS.get(anno.annotationType()),
simplePayload(VALIDATORS.get(anno.annotationType()))) {
public boolean isValid(Object actualValue) {
return true;
}
};
}
}
示例5: changeItemDetails
import javax.validation.constraints.Digits; //导入依赖的package包/类
public IncomingDocViewModel changeItemDetails(
final String description,
@Digits(integer=13, fraction = 2)
final BigDecimal netAmount,
@Digits(integer=13, fraction = 2)
@Nullable
final BigDecimal vatAmount,
@Nullable
final Tax tax,
@Digits(integer=13, fraction = 2)
@Nullable
final BigDecimal grossAmount
){
setDescription(description);
setNetAmount(netAmount);
setVatAmount(vatAmount);
setTax(tax);
setGrossAmount(grossAmount);
calculateVat();
determineAmounts();
return this;
}
示例6: addItem
import javax.validation.constraints.Digits; //导入依赖的package包/类
@MemberOrder(name="items", sequence = "1")
public IncomingInvoice addItem(
final IncomingInvoiceType type,
final Charge charge,
final String description,
@Digits(integer=13, fraction = 2)
final BigDecimal netAmount,
@Nullable
@Digits(integer=13, fraction = 2)
final BigDecimal vatAmount,
@Digits(integer=13, fraction = 2)
final BigDecimal grossAmount,
@Nullable final Tax tax,
@Nullable final LocalDate dueDate,
@Nullable final String period,
@Nullable final Property property,
@Nullable final Project project,
@Nullable final BudgetItem budgetItem) {
addItemToThis(
type, charge, description, netAmount, vatAmount, grossAmount, tax, dueDate,
period, property, project, budgetItem);
return this;
}
示例7: updateAmounts
import javax.validation.constraints.Digits; //导入依赖的package包/类
@Action(semantics = SemanticsOf.IDEMPOTENT)
public IncomingInvoiceItem updateAmounts(
@Digits(integer=13, fraction = 2)
final BigDecimal netAmount,
@Nullable
@Digits(integer=13, fraction = 2)
final BigDecimal vatAmount,
@Digits(integer=13, fraction = 2)
final BigDecimal grossAmount,
@Nullable
final Tax tax){
setNetAmount(netAmount);
setVatAmount(vatAmount);
setGrossAmount(grossAmount);
setTax(tax);
IncomingInvoice invoice = (IncomingInvoice) getInvoice();
return this;
}
示例8: updateAmounts
import javax.validation.constraints.Digits; //导入依赖的package包/类
@Action(semantics = SemanticsOf.IDEMPOTENT)
public OrderItem updateAmounts(
@Digits(integer=13, fraction = 2)
final BigDecimal netAmount,
@Nullable
@Digits(integer=13, fraction = 2)
final BigDecimal vatAmount,
@Nullable
@Digits(integer=13, fraction = 2)
final BigDecimal grossAmount,
@Nullable
final Tax tax){
setNetAmount(netAmount);
setVatAmount(vatAmount);
setGrossAmount(grossAmount);
setTax(tax);
return this;
}
示例9: addItem
import javax.validation.constraints.Digits; //导入依赖的package包/类
@MemberOrder(name="items", sequence = "1")
public Order addItem(
final Charge charge,
@Nullable final String description,
@Digits(integer=13, fraction = 2)
final BigDecimal netAmount,
@Nullable
@Digits(integer=13, fraction = 2)
final BigDecimal vatAmount,
@Nullable
@Digits(integer=13, fraction = 2)
final BigDecimal grossAmount,
@Nullable final Tax tax,
@Nullable final String period,
@Nullable final org.estatio.module.asset.dom.Property property,
@Nullable final Project project,
@Nullable final BudgetItem budgetItem
) {
orderItemRepository.upsert(
this, charge, description, netAmount, vatAmount, grossAmount, tax, PeriodUtil.yearFromPeriod(period).startDate(), PeriodUtil.yearFromPeriod(period).endDate(), property, project, budgetItem);
// (we think there's) no need to add to the getItems(), because the item points back to this order.
return this;
}
示例10: applyDigits
import javax.validation.constraints.Digits; //导入依赖的package包/类
private static void applyDigits(Property property, ConstraintDescriptor<?> descriptor) {
if ( Digits.class.equals( descriptor.getAnnotation().annotationType() ) ) {
@SuppressWarnings("unchecked")
ConstraintDescriptor<Digits> digitsConstraint = (ConstraintDescriptor<Digits>) descriptor;
int integerDigits = digitsConstraint.getAnnotation().integer();
int fractionalDigits = digitsConstraint.getAnnotation().fraction();
Column col = (Column) property.getColumnIterator().next();
col.setPrecision( integerDigits + fractionalDigits );
col.setScale( fractionalDigits );
}
}
示例11: getPrice
import javax.validation.constraints.Digits; //导入依赖的package包/类
/**
* 获取商品价格
*
* @return 商品价格
*/
@JsonProperty
@NotNull
@Min(0)
@Digits(integer = 12, fraction = 3)
@Column(nullable = false, precision = 21, scale = 6)
public BigDecimal getPrice() {
return price;
}
示例12: getBalance
import javax.validation.constraints.Digits; //导入依赖的package包/类
/**
* 获取余额
*
* @return 余额
*/
@NotNull(groups = Save.class)
@Min(0)
@Digits(integer = 12, fraction = 3)
@Column(nullable = false, precision = 27, scale = 12)
public BigDecimal getBalance() {
return balance;
}
示例13: getAmount
import javax.validation.constraints.Digits; //导入依赖的package包/类
/**
* 获取付款金额
*
* @return 付款金额
*/
@NotNull
@Min(0)
@Digits(integer = 12, fraction = 3)
@Column(nullable = false, updatable = false, precision = 21, scale = 6)
public BigDecimal getAmount() {
return amount;
}
示例14: getFreight
import javax.validation.constraints.Digits; //导入依赖的package包/类
/**
* 获取运费
*
* @return 运费
*/
@NotNull
@Min(0)
@Digits(integer = 12, fraction = 3)
@Column(nullable = false, precision = 21, scale = 6)
public BigDecimal getFreight() {
return freight;
}
示例15: getOffsetAmount
import javax.validation.constraints.Digits; //导入依赖的package包/类
/**
* 获取调整金额
*
* @return 调整金额
*/
@NotNull
@Digits(integer = 12, fraction = 3)
@Column(nullable = false, precision = 21, scale = 6)
public BigDecimal getOffsetAmount() {
return offsetAmount;
}