Java Code Examples for org.apache.commons.lang3.math.NumberUtils#LONG_ZERO
The following examples show how to use
org.apache.commons.lang3.math.NumberUtils#LONG_ZERO .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NumberUtility.java From FX-AlgorithmTrading with MIT License | 6 votes |
/** * 文字と数字の混ざった文字列から、数字のみを取り出してLongを作成します。 * 主に、外部で採番されたIDから数字のIDを作成するために使用します。 * * @param stringWithNumber * @return */ public static Long extractNumberString(Long headerNumber, String stringWithNumber) { StringBuilder sb = new StringBuilder(30); if (headerNumber != null) { sb.append(headerNumber.longValue()); } for (int i = 0; i < stringWithNumber.length(); i++) { if (CharUtils.isAsciiNumeric(stringWithNumber.charAt(i))) { sb.append(stringWithNumber.charAt(i)); } } if (sb.length() == 0) { return NumberUtils.LONG_ZERO; } else if(sb.length() >= 19) { // 19桁以上の場合は先頭の18文字を使用する return Long.valueOf(sb.substring(0, 18)); } else { return Long.valueOf(sb.toString()); } }
Example 2
Source File: InventoryUpdateActionUtils.java From commercetools-sync-java with Apache License 2.0 | 3 votes |
/** * Compares the {@code quantityOnStock} values of an {@link InventoryEntry} and an {@link InventoryEntryDraft} * and returns an {@link Optional} of update action, which would contain the {@code "changeQuantity"} * {@link UpdateAction}. If both {@link InventoryEntry} and {@link InventoryEntryDraft} have the same * {@code quantityOnStock} values, then no update action is needed and empty optional will be returned. * If the {@code quantityOnStock} from the {@code newEntry} is {@code null}, the new {@code quantityOnStock} will * have a value of 0L. * * @param oldEntry the inventory entry that should be updated * @param newEntry the inventory entry draft which contains new quantity on stock * @return optional containing update action or empty optional if quantities on stock are identical */ @Nonnull public static Optional<UpdateAction<InventoryEntry>> buildChangeQuantityAction(@Nonnull final InventoryEntry oldEntry, @Nonnull final InventoryEntryDraft newEntry) { final Long oldQuantityOnStock = oldEntry.getQuantityOnStock(); final Long newQuantityOnStock = newEntry.getQuantityOnStock() == null ? NumberUtils.LONG_ZERO : newEntry .getQuantityOnStock(); return buildUpdateAction(oldQuantityOnStock, newQuantityOnStock, () -> ChangeQuantity.of(newQuantityOnStock)); }