本文整理匯總了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;
}