Java tutorial
/* * Copyright (C) 2008 feilong (venusdrogon@163.com) * * 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.commons.core.util; import org.apache.commons.lang3.SystemUtils; /** * StringBuilder,??. * * @author <a href="mailto:venusdrogon@163.com"></a> * @version 1.0 2012-7-11 ?5:05:56 * @since 1.0.0 */ public final class StringBuilderUtil { /** Don't let anyone instantiate this class. */ private StringBuilderUtil() { //AssertionError?. ?????. ???. //see Effective Java 2nd throw new AssertionError("No " + getClass().getName() + " instances for you!"); } /** * ??,?string * * @param strings * ?? * @return stringBuilder.append? */ public static final String append(Object... strings) { if (Validator.isNotNullOrEmpty(strings)) { StringBuilder stringBuilder = new StringBuilder(); for (Object string : strings) { stringBuilder.append(string); } return stringBuilder.toString(); } return null; } /** * append ?. * * @param stringBuilder * stringBuilder * @param text * ?append */ public static final void appendTextWithLn(StringBuilder stringBuilder, Object text) { stringBuilder.append(text); stringBuilder.append(SystemUtils.LINE_SEPARATOR); } /** * <code> * stringBuilder.append(Constants.lineSeparator); * </code> * * @param stringBuilder * the string builder */ public static final void appendLn(StringBuilder stringBuilder) { stringBuilder.append(SystemUtils.LINE_SEPARATOR); } /** * append ?,?. * * @param stringBuilder * stringBuilder * @param key * key * @param value * value */ public static final void appendTextWithLn(StringBuilder stringBuilder, String key, Object value) { stringBuilder.append(key); stringBuilder.append(":"); stringBuilder.append(value); stringBuilder.append(SystemUtils.LINE_SEPARATOR); } /** * , .: * * <pre> * ***************************************** * </pre> * * @param stringBuilder * the string builder */ public static final void appendTextWithSeparated(StringBuilder stringBuilder) { appendTextWithSeparatedWithTitle(stringBuilder, null); } /** * , <br> * : * * <pre> * ***************,?-******************* * </pre> * * . * * @param stringBuilder * the string builder * @param title * the title */ public static final void appendTextWithSeparatedWithTitle(StringBuilder stringBuilder, String title) { stringBuilder.append(SystemUtils.LINE_SEPARATOR); stringBuilder.append("**************************"); if (Validator.isNotNullOrEmpty(title)) { stringBuilder.append(title); } stringBuilder.append("**************************"); stringBuilder.append(SystemUtils.LINE_SEPARATOR); } /** * , . * * @return stringBuilder */ public static final StringBuilder appendTextWithSeparated() { StringBuilder stringBuilder = new StringBuilder(); appendTextWithSeparated(stringBuilder); return stringBuilder; } }