Example usage for java.util Currency getInstance

List of usage examples for java.util Currency getInstance

Introduction

In this page you can find the example usage for java.util Currency getInstance.

Prototype

public static Currency getInstance(Locale locale) 

Source Link

Document

Returns the Currency instance for the country of the given locale.

Usage

From source file:de.hybris.platform.integration.cis.payment.commands.DefaultCisSubscriptionAuthorizationCommandTest.java

@Test
public void shouldAuthorize() throws Exception {
    final RestResponse hpfUrl = this.paymentClient.pspUrl("test");
    final String testClientRef = "JUNIT-TEST-CLIENT";

    //here we create a profile through Cybersource SOP, this profile will be used for the test authorizations
    final List<BasicNameValuePair> validFormData = CisPaymentIntegrationTestHelper.getValidFormDataMap();
    final Map<String, String> profileCreationResponse = CisPaymentIntegrationTestHelper
            .createNewProfile(hpfUrl.getLocation().toASCIIString(), validFormData);

    final CreateSubscriptionResult subscriptionResult = getCreateSubscriptionResult(testClientRef,
            profileCreationResponse);/*  w  w  w .  j  a  v a  2s.c o  m*/

    final BillingInfo billingInfo = createBillingInfo();
    final SubscriptionAuthorizationRequest request = new SubscriptionAuthorizationRequest("order1234",
            subscriptionResult.getSubscriptionInfoData().getSubscriptionID(), Currency.getInstance("USD"),
            BigDecimal.TEN, billingInfo, "cisCybersource");

    final CommandFactory commandFactory = commandFactoryRegistry.getFactory("cisCybersource");
    final SubscriptionAuthorizationCommand command = commandFactory
            .createCommand(SubscriptionAuthorizationCommand.class);
    final AuthorizationResult authResult = command.perform(request);
    Assert.assertEquals(TransactionStatus.ACCEPTED, authResult.getTransactionStatus());
}

From source file:org.orcid.core.cli.MigrateFundingAmountToANumericValue.java

private BigDecimal getAmountAsBigDecimal(String amount, String currencyCode, Locale locale) throws Exception {
    try {//ww w  .  j  a v a2  s  .co m
        ParsePosition parsePosition = new ParsePosition(0);
        NumberFormat numberFormat = NumberFormat.getInstance(locale);
        Number number = null;
        if (!PojoUtil.isEmpty(currencyCode)) {
            Currency currency = Currency.getInstance(currencyCode);
            String currencySymbol = currency.getSymbol();
            number = numberFormat.parse(amount.replace(currencySymbol, StringUtils.EMPTY), parsePosition);
        } else {
            number = numberFormat.parse(amount, parsePosition);
        }
        if (parsePosition.getIndex() != amount.length())
            throw new Exception("Unable to parse amount into BigDecimal");
        return new BigDecimal(number.toString());
    } catch (Exception e) {
        throw e;
    }
}

From source file:org.gnucash.android.ui.accounts.AccountsActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_accounts);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    Locale locale = Locale.getDefault();
    //sometimes the locale en_UK is returned which causes a crash with Currency
    if (locale.getCountry().equals("UK")) {
        locale = new Locale(locale.getLanguage(), "GB");
    }//from   w ww  .j a  v a2s.c  om
    String currencyCode = null;
    try { //there are some strange locales out there
        currencyCode = prefs.getString(getString(R.string.key_default_currency),
                Currency.getInstance(locale).getCurrencyCode());
    } catch (Exception e) {
        Log.e(TAG, e.getMessage());
        currencyCode = "USD"; //just use USD and let the user choose
    }

    Money.DEFAULT_CURRENCY_CODE = currencyCode;

    boolean firstRun = prefs.getBoolean(getString(R.string.key_first_run), true);
    if (firstRun) {
        createDefaultAccounts();
    }

    FragmentManager fragmentManager = getSupportFragmentManager();

    AccountsListFragment accountsListFragment = (AccountsListFragment) fragmentManager
            .findFragmentByTag(FRAGMENT_ACCOUNTS_LIST);

    if (accountsListFragment == null) {
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.add(R.id.fragment_container, new AccountsListFragment(), FRAGMENT_ACCOUNTS_LIST);

        fragmentTransaction.commit();
    }
}

From source file:se.urvancevav.divider.ListViewFragment.java

private void recalculateSums() {
    BigDecimal total = new BigDecimal(0);
    // Recalculate total sum
    for (int idx = 0; idx < listViewAdapter.getCount(); idx++) {
        ListItem listItem = listViewAdapter.getItem(idx);
        total = total.add(listItem.getPaidAmount());
    }/* w  w w  .ja  v  a2  s.  co m*/

    BigDecimal meanValue = BigDecimal.ZERO;
    if (!listViewAdapter.isEmpty()) {
        meanValue = total.divide(new BigDecimal(listViewAdapter.getCount()),
                Currency.getInstance(Locale.getDefault()).getDefaultFractionDigits(), RoundingMode.HALF_EVEN);
    }

    for (int idx = 0; idx < listViewAdapter.getCount(); idx++) {
        ListItem listItem = listViewAdapter.getItem(idx);
        listItem.setReturnAmount(listItem.getPaidAmount().subtract(meanValue));
    }

    listViewAdapter.notifyDataSetChanged();
}

From source file:org.netxilia.api.impl.value.NumberParser.java

@Override
public void afterPropertiesSet() throws Exception {
    this.locale = localeId != null ? new Locale(localeId) : Locale.getDefault();
    this.formats = getNumberFormats();

    // Use the appropriate currency symbol if our locale has a country, otherwise try the dollar sign!
    if (locale.getCountry() != null && !"".equals(locale.getCountry())) {
        this.currencySymbol = Currency.getInstance(locale).getSymbol(locale);
    } else {/*w ww  . java 2 s  .co m*/
        this.currencySymbol = "$";
    }

}

From source file:org.hoteia.qalingo.core.domain.CurrencyReferential.java

public NumberFormat getStandardCurrencyformat() {
    NumberFormat formatter = NumberFormat.getCurrencyInstance();
    if (StringUtils.isNotEmpty(getFormatLocale())) {
        formatter = NumberFormat.getCurrencyInstance(getLocale());
    }//from  w  ww.  j a  v a2s.  c  o  m
    Currency currency = Currency.getInstance(getCode());
    formatter.setCurrency(currency);
    return formatter;
}

From source file:com.erudika.para.i18n.CurrencyUtils.java

/**
 * Returns the currency instance for a given currency code
 * @param cur the 3-letter currency code
 * @return the currency/*  w  w  w.j  ava  2 s .  c  om*/
 */
public Currency getCurrency(String cur) {
    Currency currency = Currency.getInstance("EUR");
    if (StringUtils.isBlank(cur) || cur.length() != 3) {
        return currency;
    }
    try {
        currency = Currency.getInstance(cur.toUpperCase());
    } catch (Exception e) {
        logger.error(null, e);
    }
    return currency;
}

From source file:org.openestate.io.examples.IdxWritingExample.java

/**
 * Create an {@link IdxRecord} with some example data.
 *
 * @return/*ww w.  j  ava  2s.c om*/
 * created example object
 */
protected static IdxRecord createRecord() {
    // create an example real estate
    IdxRecord obj = new IdxRecord();
    obj.setAdvertisementId(RandomStringUtils.randomAlphanumeric(5));
    obj.setAgencyCity("Berlin");
    obj.setAgencyCountry(Locale.GERMANY.getCountry());
    obj.setAgencyEmail("tester@test.org");
    obj.setAgencyFax("030/123456");
    obj.setAgencyId(RandomStringUtils.randomAlphanumeric(5));
    obj.setAgencyName("agency name");
    obj.setAgencyName2("additional agency name");
    obj.setAgencyPhone("030/123457");
    obj.setAgencyReference(RandomStringUtils.randomAlphanumeric(5));
    obj.setAgencyStreet("example street 123");
    obj.setAgencyZip("12345");
    obj.setAnimalAllowed(RandomUtils.nextInt(0, 2) == 1);
    obj.setAvailableFrom(Calendar.getInstance());
    obj.setBalcony(RandomUtils.nextInt(0, 2) == 1);
    obj.setBillingCompany("agency name");
    obj.setBillingCountry("Germany");
    obj.setBillingFirstName("Max");
    obj.setBillingLanguage(Language.GERMAN);
    obj.setBillingMobile("030/132456");
    obj.setBillingName("Mustermann");
    obj.setBillingPhone("030/123457");
    obj.setBillingPhone2("030/123458");
    obj.setBillingPlaceName("Berlin");
    obj.setBillingPostBox("additional address notes");
    obj.setBillingSalutation(Salutation.MALE);
    obj.setBillingStreet("example street 123");
    obj.setBillingZip("12345");
    obj.setBuildingLandConnected(RandomUtils.nextInt(0, 2) == 1);
    obj.setCableTv(RandomUtils.nextInt(0, 2) == 1);
    obj.setCarryingCapacityCrane(RandomUtils.nextDouble(500, 5000));
    obj.setCarryingCapacityElevator(RandomUtils.nextDouble(500, 5000));
    obj.setCeilingHeight(RandomUtils.nextDouble(2, 10));
    obj.setChildFriendly(RandomUtils.nextInt(0, 2) == 1);
    obj.setCornerHouse(RandomUtils.nextInt(0, 2) == 1);
    obj.setCurrency(Currency.getInstance("EUR"));
    obj.setDistanceKindergarten(RandomUtils.nextInt(50, 5000));
    obj.setDistanceMotorway(RandomUtils.nextInt(50, 5000));
    obj.setDistancePublicTransport(RandomUtils.nextInt(50, 5000));
    obj.setDistanceSchool1(RandomUtils.nextInt(50, 5000));
    obj.setDistanceSchool2(RandomUtils.nextInt(50, 5000));
    obj.setDistanceShop(RandomUtils.nextInt(50, 5000));
    obj.setElevator(RandomUtils.nextInt(0, 2) == 1);
    obj.setFireplace(RandomUtils.nextInt(0, 2) == 1);
    obj.setFlatSharingCommunity(RandomUtils.nextInt(0, 2) == 1);
    obj.setFloor(RandomUtils.nextInt(0, 10));
    obj.setGarage(RandomUtils.nextInt(0, 2) == 1);
    obj.setGardenhouse(RandomUtils.nextInt(0, 2) == 1);
    obj.setGasSupply(RandomUtils.nextInt(0, 2) == 1);
    obj.setGrossPremium(GrossPremium.FROM_4_UNTIL_5);
    obj.setHallHeight(RandomUtils.nextDouble(3, 15));
    obj.setIsdn(RandomUtils.nextInt(0, 2) == 1);
    obj.setLastModified(Calendar.getInstance());
    obj.setLiftingPlatform(RandomUtils.nextInt(0, 2) == 1);
    obj.setMaximalFloorLoading(RandomUtils.nextDouble(50, 5000));
    obj.setMiddleHouse(RandomUtils.nextInt(0, 2) == 1);
    obj.setMinEnergyCertified(RandomUtils.nextInt(0, 2) == 1);
    obj.setMinEnergyGeneral(RandomUtils.nextInt(0, 2) == 1);
    obj.setNewBuilding(RandomUtils.nextInt(0, 2) == 1);
    obj.setNumberOfApartments(RandomUtils.nextDouble(1, 10));
    obj.setNumberOfFloors(RandomUtils.nextInt(1, 10));
    obj.setNumberOfRooms(RandomUtils.nextDouble(1, 10));
    obj.setObjectCity("Berlin");
    obj.setObjectCountry(Locale.GERMANY.getCountry());
    obj.setObjectDescription("some description" + SystemUtils.LINE_SEPARATOR + " about the object");
    obj.setObjectSituation("some description about the location");
    obj.setObjectState("BE");
    obj.setObjectStreet("example street 124");
    obj.setObjectTitle("title of object");
    obj.setObjectType(ObjectType.HOUSE_VILLA);
    obj.setObjectZip("12345");
    obj.setOfferType(OfferType.SALE);
    obj.setOldBuilding(RandomUtils.nextInt(0, 2) == 1);
    obj.setOwnObjectUrl("http://test.org/object/123");
    obj.setParking(RandomUtils.nextInt(0, 2) == 1);
    obj.setPowerSupply(RandomUtils.nextInt(0, 2) == 1);
    obj.setPriceUnit(PriceUnit.MONTHLY);
    obj.setRailwayTerminal(RandomUtils.nextInt(0, 2) == 1);
    obj.setRaisedGroundFloor(RandomUtils.nextInt(0, 2) == 1);
    obj.setRamp(RandomUtils.nextInt(0, 2) == 1);
    obj.setRefHouse(RandomStringUtils.randomAlphanumeric(5));
    obj.setRefObject(RandomStringUtils.randomAlphanumeric(5));
    obj.setRefProperty(RandomStringUtils.randomAlphanumeric(5));
    obj.setRentExtra(RandomUtils.nextLong(100, 1000));
    obj.setRentNet(RandomUtils.nextLong(100, 1000));
    obj.setRestrooms(RandomUtils.nextInt(0, 2) == 1);
    obj.setSellingPrice(RandomUtils.nextLong(100, 1000));
    obj.setSenderId("OpenEstate.org");
    obj.setSewageSupply(RandomUtils.nextInt(0, 2) == 1);
    obj.setSparefield1("spare field 1");
    obj.setSparefield2("spare field 2");
    obj.setSparefield3("spare field 3");
    obj.setSparefield4("spare field 4");
    obj.setSurfaceLiving(RandomUtils.nextLong(50, 300));
    obj.setSurfaceProperty(RandomUtils.nextLong(100, 1000));
    obj.setSurfaceUsable(RandomUtils.nextLong(100, 1000));
    obj.setSwimmingpool(RandomUtils.nextInt(0, 2) == 1);
    obj.setUnderBuildingLaws(RandomUtils.nextInt(0, 2) == 1);
    obj.setUnderRoof(RandomUtils.nextInt(0, 2) == 1);
    obj.setUrl("http://test.org/object/123");
    obj.setView(RandomUtils.nextInt(0, 2) == 1);
    obj.setVisitName("Max Mustermann");
    obj.setVisitPhone("030/123456");
    obj.setVisitRemark("notes about the contact person");
    obj.setVolume(RandomUtils.nextLong(50, 500));
    obj.setWaterSupply(RandomUtils.nextInt(0, 2) == 1);
    obj.setWheelcharAccessible(RandomUtils.nextInt(0, 2) == 1);
    obj.setYearBuilt(RandomUtils.nextInt(1900, 1995));
    obj.setYearRenovated(RandomUtils.nextInt(1995, 2010));

    obj.setDocument(new Media("document.pdf", "a document about the object"));
    obj.setMovie(new Media("document.mp4", "a document about the object"));
    obj.setPicture1(new Media("image1.jpg", "title for image 1", "description for image 1"));
    obj.setPicture2(new Media("image2.jpg", "title for image 2", "description for image 2"));
    obj.setPicture3(new Media("image3.jpg", "title for image 3", "description for image 3"));
    obj.setPicture4(new Media("image4.jpg", "title for image 4", "description for image 4"));
    obj.setPicture5(new Media("image5.jpg", "title for image 5", "description for image 5"));
    obj.setPicture6(new Media("image6.jpg", "title for image 6", "description for image 6"));
    obj.setPicture7(new Media("image7.jpg", "title for image 7", "description for image 7"));
    obj.setPicture8(new Media("image8.jpg", "title for image 8", "description for image 8"));
    obj.setPicture9(new Media("image9.jpg", "title for image 9", "description for image 9"));
    obj.setPicture10(new Media("image10.jpg", "title for image 10", "description for image 10"));
    obj.setPicture11(new Media("image11.jpg", "title for image 11", "description for image 11"));
    obj.setPicture12(new Media("image12.jpg", "title for image 12", "description for image 12"));
    obj.setPicture13(new Media("image13.jpg", "title for image 13", "description for image 13"));

    return obj;
}

From source file:com.mnxfst.basar.product.actor.persistence.CreateProductCacheElementActorTest.java

/**
 * Test case for {@link CreateProductCacheElementActor#createProductCacheElement(Product)} being provided a valid product entity
 */// w  ww.  j  av  a 2 s .  c om
@Test
@SuppressWarnings("unchecked")
public void testCreateProductCacheElementWithValidInput() throws Exception {
    RedisConnection<String, String> mockedRedisClientConnection = Mockito.mock(RedisConnection.class);
    ActorSystem system = ActorSystem.create("junit");
    TestActorRef<CreateProductCacheElementActor> actorRef = TestActorRef.create(system,
            Props.create(CreateProductCacheElementActor.class, mockedRedisClientConnection));
    Product input = new Product();
    input.setAgeLimit(18);
    input.setBrand("test-brand");
    input.addColor("red");
    input.addColor("green");
    input.setCountryOfOrigin("Germany");
    input.setCreated(new Date());
    input.setDefaultOrderQuantity(Integer.valueOf(10));
    input.addDefaultPrice(
            new ProductPrice(ProductPriceType.MSRP, 1.23, Currency.getInstance(Locale.getDefault())));
    input.addDeliveryCondition(
            new ProductDelivery(ProductDeliveryType.EXPRESS, "express delivery", 1.44, "test-carrier", "DE"));
    input.addDescription(new ProductDescription(ProductDescriptionType.SHORT, "short-description", "DE"));
    input.addExternalLink(ProductExternalLinkType.PRODUCT_DOC, "test-doc-url");
    input.setFirstOrderingDate(new Date());
    input.setGtin("gtin:1234");
    Product result = actorRef.underlyingActor().createProductCacheElement(input);

    Mockito.verify(mockedRedisClientConnection, Mockito.atLeast(1)).set(result.getProductId(),
            productJSONMapper.writeValueAsString(input));
    Mockito.verify(mockedRedisClientConnection, Mockito.atMost(1)).set(result.getProductId(),
            productJSONMapper.writeValueAsString(input));
}

From source file:net.rrm.ehour.ui.admin.config.MainConfigBackingBean.java

public static List<Locale> getAvailableCurrencies() {
    List<Locale> locales = getAvailableLocales();
    SortedSet<Locale> currencyLocales = new TreeSet<>(new Comparator<Locale>() {
        public int compare(Locale o1, Locale o2) {
            Currency curr1 = Currency.getInstance(o1);
            Currency curr2 = Currency.getInstance(o2);

            return (o1.getDisplayCountry() + ": " + curr1.getSymbol(o1))
                    .compareTo(o2.getDisplayCountry() + ": " + curr2.getSymbol(o2));
        }// w w w.  jav  a  2s .  co m
    });

    for (Locale locale : locales) {
        if (!StringUtils.isBlank(locale.getCountry())) {
            currencyLocales.add(locale);
        }
    }

    return new ArrayList<>(currencyLocales);
}