}
if(type!=Part.Type.ARG_START) {
continue;
}
int argLimit=msgPattern.getLimitPartIndex(i);
ArgType argType=part.getArgType();
part=msgPattern.getPart(++i);
Object arg;
String noArg=null;
Object argId=null;
if(args!=null) {
int argNumber=part.getValue(); // ARG_NUMBER
if (dest.attributes != null) {
// We only need argId if we add it into the attributes.
argId = Integer.valueOf(argNumber);
}
if(0<=argNumber && argNumber<args.length) {
arg=args[argNumber];
} else {
arg=null;
noArg="{"+argNumber+"}";
}
} else {
String key;
if(part.getType()==MessagePattern.Part.Type.ARG_NAME) {
key=msgPattern.getSubstring(part);
} else /* ARG_NUMBER */ {
key=Integer.toString(part.getValue());
}
argId = key;
if(argsMap!=null && argsMap.containsKey(key)) {
arg=argsMap.get(key);
} else {
arg=null;
noArg="{"+key+"}";
}
}
++i;
int prevDestLength=dest.length;
Format formatter = null;
if (noArg != null) {
dest.append(noArg);
} else if (arg == null) {
dest.append("null");
} else if(cachedFormatters!=null && (formatter=cachedFormatters.get(i - 2))!=null) {
// Handles all ArgType.SIMPLE, and formatters from setFormat() and its siblings.
if ( formatter instanceof ChoiceFormat ||
formatter instanceof PluralFormat ||
formatter instanceof SelectFormat) {
// We only handle nested formats here if they were provided via setFormat() or its siblings.
// Otherwise they are not cached and instead handled below according to argType.
String subMsgString = formatter.format(arg);
if (subMsgString.indexOf('{') >= 0 ||
(subMsgString.indexOf('\'') >= 0 && !msgPattern.jdkAposMode())) {
MessageFormat subMsgFormat = new MessageFormat(subMsgString, ulocale);
subMsgFormat.format(0, 0, args, argsMap, dest, null);
} else if (dest.attributes == null) {
dest.append(subMsgString);
} else {
// This formats the argument twice, once above to get the subMsgString
// and then once more here.
// It only happens in formatToCharacterIterator()
// on a complex Format set via setFormat(),
// and only when the selected subMsgString does not need further formatting.
// This imitates ICU 4.6 behavior.
dest.formatAndAppend(formatter, arg);
}
} else {
dest.formatAndAppend(formatter, arg);
}
} else if(
argType==ArgType.NONE ||
(cachedFormatters!=null && cachedFormatters.containsKey(i - 2))) {
// ArgType.NONE, or
// any argument which got reset to null via setFormat() or its siblings.
if (arg instanceof Number) {
// format number if can
if (stockNumberFormatter == null) {
stockNumberFormatter = NumberFormat.getInstance(ulocale);
}
dest.formatAndAppend(stockNumberFormatter, arg);
} else if (arg instanceof Date) {
// format a Date if can
if (stockDateFormatter == null) {
stockDateFormatter = DateFormat.getDateTimeInstance(
DateFormat.SHORT, DateFormat.SHORT, ulocale);//fix
}
dest.formatAndAppend(stockDateFormatter, arg);
} else {
dest.append(arg.toString());
}
} else if(argType==ArgType.CHOICE) {
if (!(arg instanceof Number)) {
throw new IllegalArgumentException("'" + arg + "' is not a Number");
}
double number = ((Number)arg).doubleValue();
int subMsgStart=findChoiceSubMessage(msgPattern, i, number);
formatComplexSubMessage(subMsgStart, 0, args, argsMap, dest);
} else if(argType.hasPluralStyle()) {
if (!(arg instanceof Number)) {
throw new IllegalArgumentException("'" + arg + "' is not a Number");
}
double number = ((Number)arg).doubleValue();
PluralSelector selector;