Skip to content

Commit f480f13

Browse files
author
atsticks
committed
Updated user guide.
1 parent 46f873c commit f480f13

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

src/main/asciidoc/userguide.adoc

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,3 +790,69 @@ MonetaryAmountFormat formatQueried = MonetaryFormats.getAmountFormat(
790790

791791
=== Registering your own Formats
792792

793+
You can add additional formats by registering instances of +MonetaryAmountFormatProviderSpi+. Be default this has to be
794+
done based on the mechanism as defined by the Java +ServiceLoader+.
795+
796+
[source,java]
797+
.Implement a +MonetaryAmountFormatProviderSpi+ providing a format for "GKC" (GeeCoin)
798+
--------------------------------------------
799+
public final class GeeCoinFormatProviderSpi implements MonetaryAmountFormatProviderSpi{
800+
801+
private static final String PROVIDER_NAME = "GeeCoin";
802+
/** The supported locales. */
803+
private Set<Locale> supportedSets = new HashSet<>();
804+
/** The provided formats, by name. */
805+
private Set<String> formatNames = new HashSet<>();
806+
807+
public GeeCoinFormatProviderSpi(){
808+
supportedSets.addAll(Locale.CHINA);
809+
supportedSets = Collections.unmodifiableSet(supportedSets);
810+
formatNames.add("GeeCoin");
811+
formatNames = Collections.unmodifiableSet(formatNames);
812+
}
813+
814+
/*
815+
* (non-Javadoc)
816+
* @see
817+
* javax.money.spi.MonetaryAmountFormatProviderSpi#getProviderName()
818+
*/
819+
@Override
820+
public String getProviderName(){
821+
return PROVIDER_NAME;
822+
}
823+
824+
/*
825+
* (non-Javadoc)
826+
* @see
827+
* javax.money.spi.MonetaryAmountFormatProviderSpi#getFormat(javax.money.format.AmountFormatContext)
828+
*/
829+
@Override
830+
public Collection<MonetaryAmountFormat> getAmountFormats(AmountFormatQuery amountFormatQuery){
831+
Objects.requireNonNull(amountFormatQuery, "AmountFormatContext required");
832+
if(!amountFormatQuery.getProviders().isEmpty() && !amountFormatQuery.getProviders().contains(getProviderName())){
833+
return Collections.emptySet();
834+
}
835+
if(!(amountFormatQuery.getFormatName()==null || DEFAULT_STYLE.equals(amountFormatQuery.getFormatName()))){
836+
return Collections.emptySet();
837+
}
838+
AmountFormatContextBuilder builder = AmountFormatContextBuilder.create(PROVIDER_NAME);
839+
if(amountFormatQuery.getLocale()!=null){
840+
builder.setLocale(amountFormatQuery.getLocale());
841+
}
842+
builder.importContext(amountFormatQuery, false);
843+
builder.setMonetaryAmountFactory(amountFormatQuery.getMonetaryAmountFactory());
844+
return Arrays.asList(new MonetaryAmountFormat[]{new GeeCoinAmountFormat(builder.build())});
845+
}
846+
847+
@Override
848+
public Set<Locale> getAvailableLocales(){
849+
return supportedSets;
850+
}
851+
852+
@Override
853+
public Set<String> getAvailableFormatNames(){
854+
return formatNames;
855+
}
856+
857+
}
858+
--------------------------------------------

0 commit comments

Comments
 (0)