當前位置: 首頁>>代碼示例>>Java>>正文


Java Currency.getInstance方法代碼示例

本文整理匯總了Java中java.util.Currency.getInstance方法的典型用法代碼示例。如果您正苦於以下問題:Java Currency.getInstance方法的具體用法?Java Currency.getInstance怎麽用?Java Currency.getInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.Currency的用法示例。


在下文中一共展示了Currency.getInstance方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: test_for_issue

import java.util.Currency; //導入方法依賴的package包/類
public void test_for_issue() throws Exception {
    Money money = new Money();
    money.currency = Currency.getInstance("CNY");
    money.amount = new BigDecimal("10.03");

    String json = JSON.toJSONString(money);

    Money moneyBack = JSON.parseObject(json, Money.class);
    Assert.assertEquals(money.currency, moneyBack.currency);
    Assert.assertEquals(money.amount, moneyBack.amount);

    JSONObject jsonObject = JSON.parseObject(json);
    Money moneyCast = JSON.toJavaObject(jsonObject, Money.class);
    Assert.assertEquals(money.currency, moneyCast.currency);
    Assert.assertEquals(money.amount, moneyCast.amount);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:17,代碼來源:Bug_for_issue_349.java

示例2: transformLocale

import java.util.Currency; //導入方法依賴的package包/類
private ArrayList<Currency> transformLocale(Locale[] locales) {
    ArrayList<Currency> currencies = new ArrayList<>();

    for (Locale locale : locales) {
        try {
            Currency currency = Currency.getInstance(locale);

            if (!currencies.contains(currency)) {
                currencies.add(currency);
            }

        } catch (IllegalArgumentException e) {
            continue;
        }
    }

    return currencies;
}
 
開發者ID:WGPlaner,項目名稱:wg_planer,代碼行數:19,代碼來源:GroupSettingsActivity.java

示例3: readTradingEnvironmentInformationMessage

import java.util.Currency; //導入方法依賴的package包/類
private TradingEnvironmentInformationMessage readTradingEnvironmentInformationMessage()
        throws CommunicationException {
    final String brokerName = connection.tryReceiveString();
    final long accountNumber = connection.tryReceiveLong();
    final String rawCurrency = connection.tryReceiveString();
    final AccountInformation accountInformation;
    try {
        accountInformation = new AccountInformation(brokerName, accountNumber, Currency.getInstance(rawCurrency));
    } catch (final IllegalArgumentException e) {
        throw new MessageReadException("The account currency is \"" + rawCurrency + "\" which is not valid.");
    }
    return new TradingEnvironmentInformationMessage(new TradingEnvironmentInformation(accountInformation,
            new ForexSymbol(connection.tryReceiveString()), new ForexSymbol(connection.tryReceiveString()),
            new SpecialFeesInformation(new Price(connection.tryReceiveInteger()),
                    new Price(connection.tryReceiveInteger())),
            Instant.ofEpochSecond(connection.tryReceiveLong()),
            new VolumeConstraints(new Volume(connection.tryReceiveLong(), VolumeUnit.BASE),
                    new Volume(connection.tryReceiveLong(), VolumeUnit.BASE),
                    new Volume(connection.tryReceiveLong(), VolumeUnit.BASE))));
}
 
開發者ID:rbi,項目名稱:trading4j,代碼行數:21,代碼來源:MessageBasedClientConnection.java

示例4: adjustForCurrencyDefaultFractionDigits

import java.util.Currency; //導入方法依賴的package包/類
/**
 * Adjusts the minimum and maximum fraction digits to values that
 * are reasonable for the currency's default fraction digits.
 */
private static void adjustForCurrencyDefaultFractionDigits(
        DecimalFormat format, DecimalFormatSymbols symbols) {
    Currency currency = symbols.getCurrency();
    if (currency == null) {
        try {
            currency = Currency.getInstance(symbols.getInternationalCurrencySymbol());
        } catch (IllegalArgumentException e) {
        }
    }
    if (currency != null) {
        int digits = currency.getDefaultFractionDigits();
        if (digits != -1) {
            int oldMinDigits = format.getMinimumFractionDigits();
            // Common patterns are "#.##", "#.00", "#".
            // Try to adjust all of them in a reasonable way.
            if (oldMinDigits == format.getMaximumFractionDigits()) {
                format.setMinimumFractionDigits(digits);
                format.setMaximumFractionDigits(digits);
            } else {
                format.setMinimumFractionDigits(Math.min(digits, oldMinDigits));
                format.setMaximumFractionDigits(digits);
            }
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:30,代碼來源:NumberFormatProviderImpl.java

示例5: validate

import java.util.Currency; //導入方法依賴的package包/類
/**
 * Validates that the given value contains an currency ISO code.
 * 
 * @param context
 *            FacesContext for the request we are processing
 * @param component
 *            UIComponent we are checking for correctness
 * @param value
 *            the value to validate
 * @throws ValidatorException
 *             if validation fails
 */
public void validate(FacesContext facesContext, UIComponent component,
        Object value) throws ValidatorException {
    if (value == null) {
        return;
    }
    String currencyCode = value.toString();
    if (currencyCode.length() == 0) {
        return;
    }
    try {
        Currency.getInstance(currencyCode);
    } catch (IllegalArgumentException e) {
        String label = JSFUtils.getLabel(component);
        ValidationException ve = new ValidationException(
                ReasonEnum.INVALID_CURRENCY, label,
                new Object[] { currencyCode });
        String text = JSFUtils.getText(ve.getMessageKey(),
                new Object[] { currencyCode }, facesContext);
        throw new ValidatorException(new FacesMessage(
                FacesMessage.SEVERITY_ERROR, text, null));
    }
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:35,代碼來源:CurrencyValidator.java

示例6: wrap

import java.util.Currency; //導入方法依賴的package包/類
@Override
public <X> Currency wrap(X value, WrapperOptions options) {
	if ( value == null ) {
		return null;
	}
	if ( String.class.isInstance( value ) ) {
		return Currency.getInstance( (String) value );
	}
	throw unknownWrap( value.getClass() );
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:11,代碼來源:CurrencyTypeDescriptor.java

示例7: readObject

import java.util.Currency; //導入方法依賴的package包/類
/**
 * Reads the default serializable fields, provides default values for objects
 * in older serial versions, and initializes non-serializable fields.
 * If <code>serialVersionOnStream</code>
 * is less than 1, initializes <code>monetarySeparator</code> to be
 * the same as <code>decimalSeparator</code> and <code>exponential</code>
 * to be 'E'.
 * If <code>serialVersionOnStream</code> is less than 2,
 * initializes <code>locale</code>to the root locale, and initializes
 * If <code>serialVersionOnStream</code> is less than 3, it initializes
 * <code>exponentialSeparator</code> using <code>exponential</code>.
 * Sets <code>serialVersionOnStream</code> back to the maximum allowed value so that
 * default serialization will work properly if this object is streamed out again.
 * Initializes the currency from the intlCurrencySymbol field.
 *
 * @since JDK 1.1.6
 */
private void readObject(ObjectInputStream stream)
        throws IOException, ClassNotFoundException {
    stream.defaultReadObject();
    if (serialVersionOnStream < 1) {
        // Didn't have monetarySeparator or exponential field;
        // use defaults.
        monetarySeparator = decimalSeparator;
        exponential       = 'E';
    }
    if (serialVersionOnStream < 2) {
        // didn't have locale; use root locale
        locale = Locale.ROOT;
    }
    if (serialVersionOnStream < 3) {
        // didn't have exponentialSeparator. Create one using exponential
        exponentialSeparator = Character.toString(exponential);
    }
    serialVersionOnStream = currentSerialVersion;

    if (intlCurrencySymbol != null) {
        try {
             currency = Currency.getInstance(intlCurrencySymbol);
        } catch (IllegalArgumentException e) {
        }
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:44,代碼來源:DecimalFormatSymbols.java

示例8: testCurrencyDefined

import java.util.Currency; //導入方法依賴的package包/類
private static void testCurrencyDefined(String currencyCode, int digits) {
    Currency currency = Currency.getInstance(currencyCode);
    if (currency.getDefaultFractionDigits() != digits) {
        throw new RuntimeException("[" + currencyCode
                + "] expected: " + digits
                + "; got: " + currency.getDefaultFractionDigits());
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:9,代碼來源:Bug4512215.java

示例9: testValidCurrency

import java.util.Currency; //導入方法依賴的package包/類
static void testValidCurrency(String currencyCode) {
    Currency currency1 = Currency.getInstance(currencyCode);
    Currency currency2 = Currency.getInstance(currencyCode);
    if (currency1 != currency2) {
        throw new RuntimeException("Didn't get same instance for same currency code");
    }
    if (!currency1.getCurrencyCode().equals(currencyCode)) {
        throw new RuntimeException("Currency code changed");
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:11,代碼來源:CurrencyTest.java

示例10: createGroup

import java.util.Currency; //導入方法依賴的package包/類
@Override
public boolean createGroup(String name, Currency currency, Bitmap imagecr, Context context) {
    Group group = new Group();
    group.setDisplayName(name);
    group.setCurrency(currency.getCurrencyCode());
    imageStoreInstance.setGroupPicture(imagecr);

    ApiResponse<Group> groupResponse = createGroup(group);

    if (groupResponse != null && groupResponse.getData() != null) {
        group = groupResponse.getData();
        currentGroupUID = group.getUid();
        currentGroupName = group.getDisplayName();
        currentGroupCurrency = Currency.getInstance(group.getCurrency());
        currentGroupMembersUids = group.getMembers();
        currentGroupAdminsUids = group.getAdmins();
        imageStoreInstance.setGroupPicture(imagecr);
        serverCallsInstance.updateGroupImageAsync(imageStoreInstance.getGroupPictureFile(), null);

        ApiResponse<SuccessResponse> imageResponse = serverCallsInstance.updateGroupImage(imageStoreInstance.getGroupPictureFile());

        initializeMembers(context);

        callAllListeners(DataType.CURRENT_GROUP);
        syncShoppingList();
        return true;
    }

    return false;
}
 
開發者ID:WGPlaner,項目名稱:wg_planer,代碼行數:31,代碼來源:DataProvider.java

示例11: testFormatting

import java.util.Currency; //導入方法依賴的package包/類
static void testFormatting() {
    boolean failed = false;
    Locale[] locales = {
        Locale.US,
        Locale.JAPAN,
        Locale.GERMANY,
        Locale.ITALY,
        new Locale("it", "IT", "EURO") };
    Currency[] currencies = {
        null,
        Currency.getInstance("USD"),
        Currency.getInstance("JPY"),
        Currency.getInstance("DEM"),
        Currency.getInstance("EUR"),
    };
    String[][] expecteds = {
        {"$1,234.56", "$1,234.56", "JPY1,235", "DEM1,234.56", "EUR1,234.56"},
        {"\uFFE51,235", "USD1,234.56", "\uFFE51,235", "DEM1,234.56", "EUR1,234.56"},
        {"1.234,56 \u20AC", "1.234,56 USD", "1.235 JPY", "1.234,56 DM", "1.234,56 \u20AC"},
        {"\u20AC 1.234,56", "USD 1.234,56", "JPY 1.235", "DEM 1.234,56", "\u20AC 1.234,56"},
        {"\u20AC 1.234,56", "USD 1.234,56", "JPY 1.235", "DEM 1.234,56", "\u20AC 1.234,56"},
    };

    for (int i = 0; i < locales.length; i++) {
        Locale locale = locales[i];
        NumberFormat format = NumberFormat.getCurrencyInstance(locale);
        for (int j = 0; j < currencies.length; j++) {
            Currency currency = currencies[j];
            String expected = expecteds[i][j];
            if (currency != null) {
                format.setCurrency(currency);
                int digits = currency.getDefaultFractionDigits();
                format.setMinimumFractionDigits(digits);
                format.setMaximumFractionDigits(digits);
            }
            String result = format.format(1234.56);
            if (!result.equals(expected)) {
                failed = true;
                System.out.println("FAIL: Locale " + locale
                    + (currency == null ? ", default currency" : (", currency: " + currency))
                    + ", expected: " + expected
                    + ", actual: " + result);
            }
        }
    }

    if (failed) {
        throw new RuntimeException();
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:51,代碼來源:CurrencyFormat.java

示例12: validateVehicleAndUpdate

import java.util.Currency; //導入方法依賴的package包/類
private int validateVehicleAndUpdate(final Uri uri, final ContentValues contentValues, final long id) {

        if (contentValues.containsKey(VehicleEntry.COLUMN_NAME)) {
            String name = contentValues.getAsString(VehicleEntry.COLUMN_NAME).trim();
            if (isNotVehicleNameUnique(name, id)) {
                return VEHICLE_UPDATE_NAME_NOT_UNIQUE;
            }
        }

        if (contentValues.containsKey(VehicleEntry.COLUMN_TYPE)) {
            Integer typeId = contentValues.getAsInteger(VehicleEntry.COLUMN_TYPE);
            if (typeId == null) {
                throw new IllegalArgumentException("Vehicle Type must be set.");
            }
            if (typeNotExists(typeId)) {
                throw new IllegalArgumentException("Vehicle Type must exists.");
            }
        }

        if (contentValues.containsKey(VehicleEntry.COLUMN_VOLUME_UNIT)) {
            String volumeUnit = contentValues.getAsString(VehicleEntry.COLUMN_VOLUME_UNIT);
            List<String> allowedVolumeUnits = Arrays.asList(VolumeUnit.LITRE.name(), VolumeUnit.GALLON_UK.name(), VolumeUnit.GALLON_US.name());
            if (volumeUnit == null) {
                throw new IllegalArgumentException("Vehicle volumeUnit must be set.");
            }
            if (!allowedVolumeUnits.contains(volumeUnit)) {
                throw new IllegalArgumentException("VolumeUnit value is not allowed.");
            }
        }

        if (contentValues.containsKey(VehicleEntry.COLUMN_CURRENCY)) {
            String currency = contentValues.getAsString(VehicleEntry.COLUMN_CURRENCY).toUpperCase();
            Currency currencyInstance = Currency.getInstance(currency);
            if (!CurrencyUtil.getSupportedCurrencies().contains(currencyInstance)) {
                throw new IllegalArgumentException("This currency is not supported by this app.");
            }
            if (currencyInstance == null) {
                throw new IllegalArgumentException("Currency '" + currency + "' is not supported by system.");
            }
        }

        final String selection = VehicleEntry._ID + "=?";
        final String[] idArgument = new String[] { String.valueOf(id) };

        getContext().getContentResolver().notifyChange(uri, null);
        return mDbHelper.getWritableDatabase().update(
                VehicleEntry.TABLE_NAME, contentValues, selection, idArgument);
    }
 
開發者ID:piskula,項目名稱:FuelUp,代碼行數:49,代碼來源:VehicleProvider.java

示例13: validateVehicleAndInsert

import java.util.Currency; //導入方法依賴的package包/類
private Uri validateVehicleAndInsert(Uri uri, ContentValues contentValues) {

        String name = contentValues.getAsString(VehicleEntry.COLUMN_NAME).trim();
        if (isNotVehicleNameUnique(name, null)) {
            throw new IllegalArgumentException("Vehicle name must be set and unique.");
        }

        Integer typeId = contentValues.getAsInteger(VehicleEntry.COLUMN_TYPE);
        if (typeId == null) {
            throw new IllegalArgumentException("Vehicle Type must be set.");
        }
        if (typeNotExists(typeId)) {
            throw new IllegalArgumentException("Vehicle Type must exists.");
        }

        String volumeUnit = contentValues.getAsString(VehicleEntry.COLUMN_VOLUME_UNIT);
        List<String> allowedVolumeUnits = Arrays.asList(VolumeUnit.LITRE.name(), VolumeUnit.GALLON_UK.name(), VolumeUnit.GALLON_US.name());
        if (volumeUnit == null) {
            throw new IllegalArgumentException("Vehicle volumeUnit must be set.");
        }
        if (!allowedVolumeUnits.contains(volumeUnit)) {
            throw new IllegalArgumentException("VolumeUnit value is not allowed.");
        }

        String currency = contentValues.getAsString(VehicleEntry.COLUMN_CURRENCY).toUpperCase();
        Currency currencyInstance = Currency.getInstance(currency);
        if (!CurrencyUtil.getSupportedCurrencies().contains(currencyInstance)) {
            throw new IllegalArgumentException("This currency is not supported by this app.");
        }
        if (currencyInstance == null) {
            throw new IllegalArgumentException("Currency '" + currency + "' is not supported by system.");
        }

        SQLiteDatabase database = mDbHelper.getWritableDatabase();
        long id = database.insert(VehicleEntry.TABLE_NAME, null, contentValues);

        if (id == -1) {
            Log.e(LOG_TAG, "Failed to insert row for " + uri);
            return null;
        }

        getContext().getContentResolver().notifyChange(uri, null);
        return ContentUris.withAppendedId(uri, id);
    }
 
開發者ID:piskula,項目名稱:FuelUp,代碼行數:45,代碼來源:VehicleProvider.java

示例14: setInternationalCurrencySymbol

import java.util.Currency; //導入方法依賴的package包/類
/**
 * Sets the ISO 4217 currency code of the currency of these
 * DecimalFormatSymbols.
 * If the currency code is valid (as defined by
 * {@link java.util.Currency#getInstance(java.lang.String) Currency.getInstance}),
 * this also sets the currency attribute to the corresponding Currency
 * instance and the currency symbol attribute to the currency's symbol
 * in the DecimalFormatSymbols' locale. If the currency code is not valid,
 * then the currency attribute is set to null and the currency symbol
 * attribute is not modified.
 *
 * @param currencyCode the currency code
 * @see #setCurrency
 * @see #setCurrencySymbol
 * @since 1.2
 */
public void setInternationalCurrencySymbol(String currencyCode)
{
    intlCurrencySymbol = currencyCode;
    currency = null;
    if (currencyCode != null) {
        try {
            currency = Currency.getInstance(currencyCode);
            currencySymbol = currency.getSymbol();
        } catch (IllegalArgumentException e) {
        }
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:29,代碼來源:DecimalFormatSymbols.java

示例15: MoneyUtil

import java.util.Currency; //導入方法依賴的package包/類
/**
 * 構造器。
 * <p>創建一個具有參數<code>amount</code>指定金額和缺省幣種的貨幣對象。
 * 如果金額不能轉換為整數分,則使用指定的取整模式<code>roundingMode</code>取整。
 * @param amount 金額,以元為單位。
 * @param roundingMode 取整模式
 */
public MoneyUtil(BigDecimal amount, int roundingMode) {
	this(amount, Currency.getInstance(DEFAULT_CURRENCY_CODE), roundingMode);
}
 
開發者ID:zhiqiang94,項目名稱:BasicsProject,代碼行數:11,代碼來源:MoneyUtil.java


注:本文中的java.util.Currency.getInstance方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。