Java tutorial
/* * Copyright (C) 2008 feilong * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.feilong.core.text; import java.text.Format; import java.text.MessageFormat; import org.apache.commons.lang3.Validate; /** * {@link MessageFormat}, . * * @author <a href="http://feitianbenyue.iteye.com/">feilong</a> * @see MessageFormat * @see Format * @since 1.0.2 */ public final class MessageFormatUtil { /** Don't let anyone instantiate this class. */ private MessageFormatUtil() { //AssertionError?. ?????. ???. //see Effective Java 2nd throw new AssertionError("No " + getClass().getName() + " instances for you!"); } /** * ?. * * <h3>:</h3> * * <blockquote> * * <pre class="code"> * MessageFormatUtil.format("name={0}a{1}", "jin", "xin") = "name=jinaxin" * MessageFormatUtil.format("name={0,number}a{1}", 5, "xin") = "name=5axin" * MessageFormatUtil.format("name={0,date}a{1}", DateUtil.toDate("2000", DatePattern.yyyy), "xin") = "name=2000-1-1axin" * </pre> * * </blockquote> * * @param pattern * ?????: * <ul> * <li>{argumentIndex}: 0-9 ,?????</li> * <li>{argumentIndex,formatType}: ??</li> * <li>{argumentIndex,formatType,FormatStyle}: ??,???????.</li> * </ul> * @param arguments * ?? * @return <code>pattern</code> null, {@link NullPointerException}<br> */ public static String format(String pattern, Object... arguments) { Validate.notNull(pattern, "pattern can't be null!"); return MessageFormat.format(pattern, arguments); } }