Added Demo.
This commit is contained in:
parent
f07a364934
commit
ff98c0ae13
1 changed files with 85 additions and 0 deletions
85
src/fr/devinsy/util/strings/demo/Demo.java
Normal file
85
src/fr/devinsy/util/strings/demo/Demo.java
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2017 Christian Pierre MOMON
|
||||||
|
*
|
||||||
|
* This file is part of Devinsy-strings.
|
||||||
|
*
|
||||||
|
* Devinsy-strings is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Devinsy-strings 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 Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Devinsy-strings. If not, see <http://www.gnu.org/licenses/>
|
||||||
|
*/
|
||||||
|
package fr.devinsy.util.strings.demo;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import fr.devinsy.util.strings.StringList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class Demo.
|
||||||
|
*/
|
||||||
|
public class Demo
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The main method.
|
||||||
|
*
|
||||||
|
* @param args
|
||||||
|
* the arguments
|
||||||
|
*/
|
||||||
|
public static void main(final String[] args)
|
||||||
|
{
|
||||||
|
// #1
|
||||||
|
{
|
||||||
|
StringList strings = new StringList();
|
||||||
|
|
||||||
|
strings.appendln("========== DEMO #1;");
|
||||||
|
strings.appendln();
|
||||||
|
strings.appendln("Need to concatenate arbitrary number of string?");
|
||||||
|
strings.appendln("Don't know what will be the final size?");
|
||||||
|
strings.appendln("So StringBuilder and StringBuffer are not efficient.");
|
||||||
|
strings.appendln("Choose StringList!");
|
||||||
|
|
||||||
|
System.out.println(strings.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
// #2
|
||||||
|
{
|
||||||
|
StringList strings = new StringList();
|
||||||
|
|
||||||
|
strings.appendln("========== DEMO #2;");
|
||||||
|
strings.appendln();
|
||||||
|
strings.appendln("Easy to concatenate different types.");
|
||||||
|
strings.append("Boolean: ").append(true).append(" ").appendln(new Boolean(false));
|
||||||
|
strings.append("Char: ").append('e').append(" ").appendln(new Character('e'));
|
||||||
|
strings.append("Byte : ").append((byte) 5).append(" ").appendln(new Byte((byte) 5));
|
||||||
|
strings.append("Short: ").append((short) 55).append(" ").appendln(new Short((short) 55));
|
||||||
|
strings.append("Integer: ").append(555).append(" ").appendln(new Integer(555));
|
||||||
|
strings.append("Long: ").append(5555L).append(" ").appendln(new Long(5555));
|
||||||
|
strings.append("Float: ").append((float) 5555.5).append(" ").appendln(new Float(5555.5));
|
||||||
|
strings.append("Double: ").append(5555.55).append(" ").appendln(new Double(5555.55));
|
||||||
|
strings.append("String: ").append("abcde").append(" ").appendln(new String("edcba"));
|
||||||
|
strings.append("Object: ").appendln(new Date());
|
||||||
|
strings.append("Array of boolean:").appendln(new boolean[] { true, false, true });
|
||||||
|
strings.append("Array of char: ").appendln(new char[] { 'a', 'b', 'c' });
|
||||||
|
strings.append("Array of byte: ").appendln(new byte[] { (byte) 1, (byte) 2, (byte) 3 });
|
||||||
|
strings.append("Array of short: ").appendln(new short[] { (short) 1, (short) 2, (short) 3 });
|
||||||
|
strings.append("Array of string: ").appendln(new String[] { "a", "b", "c" });
|
||||||
|
ArrayList<String> buffer = new ArrayList<String>();
|
||||||
|
buffer.add("aa");
|
||||||
|
buffer.add("bb");
|
||||||
|
buffer.add("cc");
|
||||||
|
strings.append("Collections: ").appendln(buffer);
|
||||||
|
|
||||||
|
System.out.println(strings.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue