From ff98c0ae1376b089742313066188f796c96040a9 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Fri, 5 May 2017 10:13:34 +0200 Subject: [PATCH] Added Demo. --- src/fr/devinsy/util/strings/demo/Demo.java | 85 ++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 src/fr/devinsy/util/strings/demo/Demo.java diff --git a/src/fr/devinsy/util/strings/demo/Demo.java b/src/fr/devinsy/util/strings/demo/Demo.java new file mode 100644 index 0000000..8136752 --- /dev/null +++ b/src/fr/devinsy/util/strings/demo/Demo.java @@ -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 + */ +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 buffer = new ArrayList(); + buffer.add("aa"); + buffer.add("bb"); + buffer.add("cc"); + strings.append("Collections: ").appendln(buffer); + + System.out.println(strings.toString()); + } + } +}