Here you can find the source of PluralTemplateHelper(int count, String singularTemplate, String pluralTemplate)
Parameter | Description |
---|---|
count | The count of items |
singularTemplate | The singular template |
pluralTemplate | The plural template |
public static String PluralTemplateHelper(int count, String singularTemplate, String pluralTemplate)
//package com.java2s; //License from project: Open Source License public class Main { /**//from w ww . j a v a 2 s.c om * For even more complex sentences, it may just be easiest to provide a * template, which will be replaced, if the count is singular or plural. * Both singularTemplate and pluralTemplate are expected to be String.format * templates with a %d in them, which will be replaced with the actual count * number. If the count == 1, then the singularTemplate will be used, else * the pluralTemplate will be used. Usage example: * * <pre> * String message = PluralTemplateHelper(count, "I will buy %d car if it has a good price", * "I will buy %d cars if they have a good price"); * </pre> * * @param count The count of items * @param singularTemplate The singular template * @param pluralTemplate The plural template * @return */ public static String PluralTemplateHelper(int count, String singularTemplate, String pluralTemplate) { if (count == 1) { return String.format(singularTemplate, count); } else { return String.format(pluralTemplate, count); } } }