Java XML String Create toXMLString(final boolean[] array)

Here you can find the source of toXMLString(final boolean[] array)

Description

Return an XML encoding String representation of a boolean array.

License

Open Source License

Return

an XML encoding String representation of a boolean array.

Declaration

public static String toXMLString(final boolean[] array) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /** Default string size */
    static final int SIZE = 1024;
    /** Space string */
    static final String SPACE = " ";
    /** Quote string */
    static final String QUOT = "\"";
    /** Quote reference */
    static final String QUOT_REF = """;
    /** Apostrophe string */
    static final String APOS = "\'";
    /** Apostrophe reference */
    static final String APOS_REF = "'";

    /**//from w  w  w  .j a va2 s.  c om
     * Return an XML encoding <code>String</code> representation of a <code>boolean</code> array.
     * @return an XML encoding <code>String</code> representation of a <code>boolean</code> array.
     */
    public static String toXMLString(final boolean[] array) {
        final StringBuffer sb = new StringBuffer(SIZE);
        final int length = array.length;
        final int lastItem = length - 1;
        for (int i = 0; i < length; i++) {
            sb.append(array[i]);
            if (i != lastItem) {
                sb.append(SPACE);
            }
        }
        return (sb.toString());
    }

    /**
     * Return an XML encoding <code>String</code> representation of a <code>String</code> array.
     * @return an XML encoding <code>String</code> representation of a <code>String</code> array.
     */
    public static String toXMLString(final String[] array) {
        final StringBuffer sb = new StringBuffer(SIZE);
        final int length = array.length;
        final int lastItem = length - 1;
        for (int i = 0; i < length; i++) {
            final StringBuffer s = new StringBuffer(array[i]);
            //
            // replace double and single quotation marks
            // with their respective character entities
            for (int j = s.indexOf(QUOT); j != -1; j = s.indexOf(QUOT, j + QUOT_REF.length())) {
                s.replace(j, j + 1, QUOT_REF);
            }
            for (int j = s.indexOf(APOS); j != -1; j = s.indexOf(APOS, j + QUOT_REF.length())) {
                s.replace(j, j + 1, APOS_REF);
            }
            sb.append(QUOT);
            sb.append(s);
            sb.append(QUOT);
            if (i != lastItem) {
                sb.append(SPACE);
            }
        }
        return (sb.toString());
    }

    /**
     * Return a <code>String</code> representation of an <code>int</code> array.
     * @return a <code>String</code> representation of an <code>int</code> array.
     */
    public static String toString(final int[] array) {
        final StringBuffer sb = new StringBuffer(SIZE);
        final int length = array.length;
        final int lastItem = length - 1;
        for (int i = 0; i < length; i++) {
            sb.append(array[i]);
            if (i != lastItem) {
                sb.append(SPACE);
            }
        }
        return (sb.toString());
    }

    /**
     * Return a <code>String</code> representation of a <code>float</code> array.
     * @return a <code>String</code> representation of a <code>float</code> array.
     */
    public static String toString(final float[] array) {
        final StringBuffer sb = new StringBuffer(SIZE);
        final int length = array.length;
        final int lastItem = length - 1;
        for (int i = 0; i < length; i++) {
            sb.append(array[i]);
            if (i != lastItem) {
                sb.append(SPACE);
            }
        }
        return (sb.toString());
    }

    /**
     * Return a <code>String</code> representation of a <code>double</code> array.
     * @return a <code>String</code> representation of a <code>double</code> array.
     */
    public static String toString(final double[] array) {
        final StringBuffer sb = new StringBuffer(SIZE);
        final int length = array.length;
        final int lastItem = length - 1;
        for (int i = 0; i < length; i++) {
            sb.append(array[i]);
            if (i != lastItem) {
                sb.append(SPACE);
            }
        }
        return (sb.toString());
    }
}

Related

  1. toXML(String s)
  2. toXML(String string)
  3. toXML(String valor)
  4. toXmlString(float value)
  5. toXMLString(String in)
  6. toXMLString(String javaString)
  7. toXMLString(String org)