📄 tostringbuffer.java
字号:
/* * listToStringBuffer.java * * This is a required part of the com.adaptiveview.ospso package. * * Copyright (C) 2003 AdaptiveView.com * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * You may contact AdaptiveView.com via email at: comments.pso@adaptiveview.com * */package com.adaptiveview.toolkits.arrays;/** Utility Class (private contructor) used to format array contents * in (or to) a StringBuffer. * @author AdaptiveView.com */public final class ToStringBuffer implements com.adaptiveview.ospso.dmi.DMI_GPL_License { /** Can't Create an instance of listToStringBuffer */ private ToStringBuffer() {} /** Returns new StringBuffer with formatted contents of a double * array. Accepts a pre, separator and post <code>String</code> to use when * formatting the contents. * <p>Given <CODE>double[] array = {1.0, 2.0}</CODE>,<p> * <CODE>ToStringBuffer.list(array,"double[] = {",", ","}")</CODE> returns a * StringBuffer containing:<p>"<CODE>double[] = {1.0, 2.0}</CODE>". * * @param array the array of <CODE>double</CODE>s. * @param pre String to prefix the array contents with. * @param separator String to insert between each item in the array. * @param post String to add after the array contents. * @return a new StringBuffer with the formatted array contents. */ public static final StringBuffer list(double[] array, String pre, String separator, String post) { StringBuffer s = new StringBuffer(); s.append(pre); s.append(array[0]); for (int i = 1,size = array.length; i < size; i++) { s.append(separator); s.append(array[i]); } s.append(post); return s; } /** Appends to referenced StringBuffer (arg 5) the formatted contents of a double * array. Accepts a pre, separator and post <code>String</code> to use when * formatting the contents. * <p>Given <CODE>double[] array = {1.0, 2.0}</CODE> * and <p><CODE>StringBuffer buffer = "My array: "</CODE>, * <p>method <CODE>ToStringBuffer.list(array,"double[] = {",", ","}",buffer)</CODE> * will append to <CODE>buffer</CODE> yeilding:<p>"<CODE>My array: double[] = {1.0, 2.0}</CODE>". * @param array the array of <CODE>double</CODE>s. * @param pre String to prefix the array contents with. * @param separator String to insert between each item in the array. * @param post String to add after the array contents. * @param buffer the <CODE>StringBuffer</CODE> to be appended to. */ public static final void list(double[] array, String pre, String separator, String post, StringBuffer buffer) { buffer.append(pre); buffer.append(array[0]); for (int i = 1,size = array.length; i < size; i++) { buffer.append(separator); buffer.append(array[i]); } buffer.append(post); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -