CountryCode cc = CountryCode.getByCode("JP"); System.out.println("Country name = " + cc.getName()); // "Japan" System.out.println("ISO 3166-1 alpha-2 code = " + cc.getAlpha2()); // "JP" System.out.println("ISO 3166-1 alpha-3 code = " + cc.getAlpha3()); // "JPN" System.out.println("ISO 3166-1 numeric code = " + cc.getNumeric()); // 392
/** The optional country where this price applies, used in price calculations. * * @return The ISO 3166-1 (alpha-2) string representation of the country. If country is not defined, returns "" (empty string). * */ public String getCountryString() { return country == null ? "" : country.getAlpha2(); }
public PriceSelectionBuilder priceCountry(@Nullable final CountryCode priceCountry) { this.priceCountry = Optional.ofNullable(priceCountry).map(c -> c.getAlpha2()).orElse(null); return this; }
public PriceSelectionBuilder priceCountry(@Nullable final CountryCode priceCountry) { this.priceCountry = Optional.ofNullable(priceCountry).map(c -> c.getAlpha2()).orElse(null); return this; }
@Override public QueryPredicate<T> isNot(final CountryCode countryCode) { return isNotPredicate(countryCode.getAlpha2()); } }
public Predicate<T> is(final CountryCode countryCode) { return EqPredicate.of(this, countryCode.getAlpha2()); } }
public String getCode() { CountryCode code = code(countryId); return code != null ? code.getAlpha2().toLowerCase() : UNKNOWN_CODE; }
@Override public QueryPredicate<T> is(final CountryCode countryCode) { return isPredicate(countryCode.getAlpha2()); }
private static List<NameValuePair> createQueryParameters(final CountryCode country, @Nullable final String state, @Nullable final CurrencyUnit currency) { final List<NameValuePair> queryParameters = new ArrayList<>(); queryParameters.add(NameValuePair.of("country", country.getAlpha2())); Optional.ofNullable(state).ifPresent(x -> queryParameters.add(NameValuePair.of("state", x))); Optional.ofNullable(currency).ifPresent(x -> queryParameters.add(NameValuePair.of("currency", x.getCurrencyCode()))); return queryParameters; } }
private static List<NameValuePair> createQueryParameters(final CountryCode country, @Nullable final String state, @Nullable final CurrencyUnit currency) { final List<NameValuePair> queryParameters = new ArrayList<>(); queryParameters.add(NameValuePair.of("country", country.getAlpha2())); Optional.ofNullable(state).ifPresent(x -> queryParameters.add(NameValuePair.of("state", x))); Optional.ofNullable(currency).ifPresent(x -> queryParameters.add(NameValuePair.of("currency", x.getCurrencyCode()))); return queryParameters; } }
public String forLocation(CountryCode country, String state, Currency currency) { String stateParam = ""; if (state != null && !state.isEmpty()) stateParam = "&state=" + Util.urlEncode(state); return root() + "?" + "country=" + country.getAlpha2() + "¤cy=" + currency.getCurrencyCode() + stateParam; }
public static String alpha3toAlpha2(String alpha3) throws UnknownCountryException { if(alpha3.length()==0) return " "; CountryCode countryCode = CountryCode.getByCode(alpha3); if(null==countryCode){ throw new UnknownCountryException("Can't find country "+alpha3, alpha3); } return countryCode.getAlpha2(); } }
private String defaultCountry() { final ProjectContext projectContext = injector().getInstance(ProjectContext.class); return projectContext.defaultCountry().getAlpha2(); }
private static String identifierToSearchFor(final CountryCode country, @Nullable final String state, @Nullable final CurrencyUnit currency) { final UrlQueryBuilder urlQueryBuilder = UrlQueryBuilder.of(); urlQueryBuilder.add("country", country.getAlpha2()); Optional.ofNullable(state).ifPresent(x -> urlQueryBuilder.add("state", x)); Optional.ofNullable(currency).ifPresent(x -> urlQueryBuilder.add("currency", x.getCurrencyCode())); return urlQueryBuilder.toStringWithOptionalQuestionMark(); } }
private List<FormSelectableOptionBean> createCountryFormOptions() { final List<FormSelectableOptionBean> countrySelector = projectContext.countries().stream() .map(countryCode -> { final FormSelectableOptionBean bean = new FormSelectableOptionBean(); bean.setLabel(countryCode.getName()); bean.setValue(countryCode.getAlpha2()); bean.setSelected(countryCode.equals(userContext.country())); return bean; }).collect(toList()); return (countrySelector.size() > 1) ? countrySelector : emptyList(); }
@Override public String toString() { String c = country == null ? "all-countries" : country.getAlpha2(); String g = customerGroup.isEmpty() ? "all-groups" : customerGroup.getId(); return "(" + value.toString() + ", " + c + ", " + g + ")"; } }
protected final void initializeFormSelectableOption(final FormSelectableOptionBean bean, final CountryCode country, final @Nullable String selectedCountryCode) { final String countryCode = country.getAlpha2(); bean.setLabel(country.toLocale().getDisplayCountry(userContext.locale())); bean.setValue(countryCode); bean.setSelected(countryCode.equals(selectedCountryCode)); }
private String queryParameters() { final UrlQueryBuilder urlQueryBuilder = UrlQueryBuilder.of(); urlQueryBuilder.add("country", country.getAlpha2()); state.ifPresent(x -> urlQueryBuilder.add("state", x)); currency.ifPresent(x -> urlQueryBuilder.add("currency", x.getCurrencyCode())); return urlQueryBuilder.toStringWithOptionalQuestionMark(); } }
private void applyShippingAddress(final Address address) { this.titleShipping = address.getTitle(); this.firstNameShipping = address.getFirstName(); this.lastNameShipping = address.getLastName(); this.streetNameShipping = address.getStreetName(); this.additionalStreetInfoShipping = address.getAdditionalStreetInfo(); this.cityShipping = address.getCity(); this.postalCodeShipping = address.getPostalCode(); this.countryShipping = address.getCountry().getAlpha2(); this.regionShipping = address.getRegion(); this.phoneShipping = address.getPhone(); this.emailShipping = address.getEmail(); }
private void applyBillingAddress(final Address address) { this.titleBilling = address.getTitle(); this.firstNameBilling = address.getFirstName(); this.lastNameBilling = address.getLastName(); this.streetNameBilling = address.getStreetName(); this.additionalStreetInfoBilling = address.getAdditionalStreetInfo(); this.cityBilling = address.getCity(); this.postalCodeBilling = address.getPostalCode(); this.countryBilling = address.getCountry().getAlpha2(); this.regionBilling = address.getRegion(); this.phoneBilling = address.getPhone(); this.emailBilling = address.getEmail(); }