All Downloads are FREE. Search and download functionalities are using the official Maven repository.

pl.allegro.finance.tradukisto.internal.languages.hindi.IndianNumberToWordsConverter Maven / Gradle / Ivy

Go to download

Small java library created to convert numbers to their word representations

There is a newer version: 3.1.0
Show newest version
package pl.allegro.finance.tradukisto.internal.languages.hindi;

import pl.allegro.finance.tradukisto.internal.GenderAwareIntegerToStringConverter;
import pl.allegro.finance.tradukisto.internal.converters.NumberToWordsConverter;
import pl.allegro.finance.tradukisto.internal.languages.PluralForms;
import pl.allegro.finance.tradukisto.internal.support.Assert;
import pl.allegro.finance.tradukisto.internal.support.IndianNumberChunking;
import pl.allegro.finance.tradukisto.internal.support.NumberChunking;

import java.util.List;

public class IndianNumberToWordsConverter extends NumberToWordsConverter {

    private final NumberChunking numberChunking = new IndianNumberChunking();

    public IndianNumberToWordsConverter(GenderAwareIntegerToStringConverter hundredsToWordsConverter, List pluralForms) {
        super(hundredsToWordsConverter, pluralForms);
    }

    @Override
    public String asWords(Long value) {
        Assert.isTrue(value >= 0, () -> String.format("can't convert negative numbers for value %d", value));

        List valueChunks = numberChunking.chunk(value);
        List formsToUse = getRequiredFormsInReversedOrder(valueChunks.size());


        return joinValueChunksWithForms(valueChunks.iterator(), formsToUse.iterator());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy