/* XBN Java: Generically useful, non-GUI Java code. http://sourceforge.net/projects/xbnjava Copyright (C) 1997-2003, Jeff Epstein All rights reserved. Modifications: No Redistribution in binary form, with or without modifications, are permitted provided that the following conditions are met: * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * If modifications are made to source code then this license should indicate that fact in the "Modifications" section above. * Neither the author, nor the contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. [NOTE: This license contains NO advertising clause.] */ package xbn.array.primitive; import xbn.XBNObject; import xbn.string.StringOrBuffer; import xbn.string.SOBString; import xbn.string.UtilString; import xbn.string.UtilStringBuffer; import xbn.string.PASStringOrBuffer; /**

Lists an array existing inside a PrimitiveArray. See PrimitiveArray.

Source code:  ListPA.java

@version 0.9b @author Jeff Epstein, http://sourceforge.net/projects/xbnjava. **/ public class ListPA extends XBNObject { private UtilString uStr = new UtilString(); private UtilStringBuffer uSB = new UtilStringBuffer(); private LPAConfig lpac = null; /**

Create a ListPA with default configuration.

Equal to ListPA(new LPAConfig())

**/ public ListPA() { this(new LPAConfig()); } /**

Create a ListPA.

Equal to ListPA(new LPAConfig(s_divider))

**/ public ListPA(String s_divider) { this(new LPAConfig(s_divider)); } /**

Create a ListPA.

Equal to ListPA(new LPAConfig(s_prefix, s_postfix))

**/ public ListPA(String s_prefix, String s_postfix) { this(new LPAConfig(s_prefix, s_postfix)); } /**

Create a ListPA.

Equal to ListPA(new LPAConfig(s_prefix, s_divider, s_postfix))

**/ public ListPA(String s_prefix, String s_divider, String s_postfix) { this(new LPAConfig(s_prefix, s_divider, s_postfix)); } /**

Create a ListPA.

@param lpa_config The LPAConfig. May not be null. See getLPAConfig. **/ public ListPA(LPAConfig lpa_config) { throwAXIfNull(lpa_config, "lpa_config", sCNSTR); lpac = lpa_config; } /**

Get the LPAConfig for direct manipulation.

@return lpa_config Exactly as provided to the constructor. **/ public final LPAConfig getLPAConfig() { return lpac; } /**

Get a list of the provided characters.

@return The contents of SOBString after append(new SOBString(""), a_char) **/ public String get(char[] a_char) { SOBString ss = new SOBString(sES); append(ss, a_char); return ss.toString(); } /**

Get a list of the provided ints.

@return The contents of SOBString after append(new SOBString(""), a_int) **/ public String get(int[] a_int) { SOBString ss = new SOBString(sES); append(ss, a_int); return ss.toString(); } /**

Get a list of the provided strings.

@return The contents of SOBString after append(new SOBString(""), a_string) **/ public String get(String[] a_string) { SOBString ss = new SOBString(sES); append(ss, a_string); return ss.toString(); } /**

Get a list of the provided StringBuffers.

@return The contents of SOBString after append(new SOBString(""), a_stringBuffer) **/ public String get(StringBuffer[] a_stringBuffer) { SOBString ss = new SOBString(sES); append(ss, a_stringBuffer); return ss.toString(); } /**

Get a list of the provided StringOrBuffers.

@return The contents of SOBString after append(new SOBString(""), a_strOrBfr) **/ public String get(StringOrBuffer[] a_strOrBfr) { SOBString ss = new SOBString(sES); append(ss, a_strOrBfr); return ss.toString(); } /**

Get a list of the provided PrimitiveArray values.

@return The contents of SOBString after append(new SOBString(""), primitive_array) **/ public String get(PrimitiveArray primitive_array) { SOBString ss = new SOBString(sES); append(ss, primitive_array); return ss.toString(); } private static final String sAPPEND = "append"; /**

Append a list of the provided characters onto the provided StringBuffer.

Equal to append([UtilStringBuffer].getSOBSB(str_buffer, "append"), primitive_array)

**/ public void append(StringBuffer str_buffer, char[] a_char) { append(uSB.getSOBSB(str_buffer, sAPPEND), a_char); } /**

Append a list of the ints onto the provided StringBuffer.

Equal to append([UtilStringBuffer].getSOBSB(a_int, "append"), primitive_array)

**/ public void append(StringBuffer str_buffer, int[] a_int) { append(uSB.getSOBSB(str_buffer, sAPPEND), a_int); } /**

Append a list of the strings onto the provided StringBuffer.

Equal to append([UtilStringBuffer].getSOBSB(a_string, "append"), primitive_array)

**/ public void append(StringBuffer str_buffer, String[] a_string) { append(uSB.getSOBSB(str_buffer, sAPPEND), a_string); } /**

Append a list of the StringBuffers onto the provided StringBuffer.

Equal to append([UtilStringBuffer].getSOBSB(a_stringBuffer, "append"), primitive_array)

**/ public void append(StringBuffer str_buffer, StringBuffer[] a_stringBuffer) { append(uSB.getSOBSB(str_buffer, sAPPEND), a_stringBuffer); } /**

Append a list of the StringOrBuffers onto the provided StringBuffer.

Equal to append([UtilStringBuffer].getSOBSB(a_strOrBfr, "append"), primitive_array)

**/ public void append(StringBuffer str_buffer, StringOrBuffer[] a_strOrBfr) { append(uSB.getSOBSB(str_buffer, sAPPEND), a_strOrBfr); } /**

Append a list of the PrimitiveArray values onto the provided StringBuffer.

Equal to append([UtilStringBuffer].getSOBSB(primitive_array, "append"), primitive_array)

**/ public void append(StringBuffer str_buffer, PrimitiveArray primitive_array) { append(uSB.getSOBSB(str_buffer, sAPPEND), primitive_array); } /**

Append a list of characters onto the provided StringOrBuffer.

Equal to append(str_orBfr, (new PACChar(a_char)))

**/ public void append(StringOrBuffer str_orBfr, char[] a_char) { append(str_orBfr, (new PACChar(a_char))); } /**

Append a list of ints onto the provided StringOrBuffer.

Equal to append(str_orBfr, (new PAIInt(a_int)))

**/ public void append(StringOrBuffer str_orBfr, int[] a_int) { append(str_orBfr, (new PAIInt(a_int))); } /**

Append a list of strings onto the provided StringOrBuffer.

Equal to append(str_orBfr, (new PASString(a_string)))

**/ public void append(StringOrBuffer str_orBfr, String[] a_string) { append(str_orBfr, (new PASString(a_string))); } /**

Append a list of StringBuffers onto the provided StringOrBuffer.

Equal to append(str_orBfr, (new PASStringBuffer(a_stringBuffer)))

**/ public void append(StringOrBuffer str_orBfr, StringBuffer[] a_stringBuffer) { append(str_orBfr, (new PASStringBuffer(a_stringBuffer))); } /**

Append a list of StringOrBuffers onto the provided StringOrBuffer.

Equal to append(str_orBfr, (new PASStringOrBuffer(a_strOrBfr)))

**/ public void append(StringOrBuffer str_orBfr, StringOrBuffer[] a_strOrBfr) { append(str_orBfr, (new PASStringOrBuffer(a_strOrBfr))); } /**

Append a list of the PrimitiveArray values onto the provided StringOrBuffer, based on the settings in LPAConfig. See LPAConfig.

**/ public void append(StringOrBuffer str_orBfr, PrimitiveArray primitive_array) { try { if(primitive_array.isNull()) { str_orBfr.append(getLPAConfig().getIfEmpty()); return; } } catch(NullPointerException npx) { throwAXIfNull(str_orBfr, "str_orBfr", sAPPEND); throwAXIfNull(primitive_array, "primitive_array", sAPPEND); } //isNull() equals false. if(primitive_array.getLength() == 0) { str_orBfr.append(getLPAConfig().getIfEmpty()); return; } if(getLPAConfig().getPrefix() != null) { str_orBfr.append(getLPAConfig().getPrefix()); } for(int i = 0; i < primitive_array.getLength(); i++) { String s = primitive_array.getString(i); if(getLPAConfig().doMakeVisible()) { s = uStr.getVisible(s); } str_orBfr.append(s); if(getLPAConfig().getDivider() != null && i < (primitive_array.getLength() - 1)) { str_orBfr.append(getLPAConfig().getDivider()); } } if(getLPAConfig().getPostfix() != null) { str_orBfr.append(getLPAConfig().getPostfix()); } } }