当前位置: 首页>>代码示例>>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;未经允许,请勿转载。