View Javadoc

1   /* ==============================================================================
2    *   JDBCAdmin, data management software.
3    *   Copyright (C) 2005  Norsys S.A
4    *
5    *   This library is free software; you can redistribute it and/or
6    *   modify it under the terms of the GNU Lesser General Public
7    *   License as published by the Free Software Foundation; either
8    *   version 2.1 of the License, or (at your option) any later version.
9    *
10   *   This library is distributed in the hope that it will be useful,
11   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   *   Lesser General Public License for more details.
14   *
15   *   You should have received a copy of the GNU Lesser General Public
16   *   License along with this library; if not, write to the Free Software
17   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   * ==============================================================================
19   */
20  package jdbcadmin.core.util;
21  
22  /***
23   * Strings utility
24   */
25  public class StringUtil {
26  
27      /*** Default size. */
28      private static final int DEFAULT_SIZE = 4;
29  
30      /*** Constructor.*/
31      protected StringUtil() {
32      }
33  
34      /***
35       * Adds a String in a buffer.
36       * @param aBuff the buffer
37       * @param aPrefix string to add before the value
38       * @param aSufix  string to add after the value
39       * @param aVal value to append
40       * @param aTaille size of the string to append
41       * @param aSep separator
42       * @param aBouchon filler
43       */
44      public static void append(StringBuffer aBuff, String aPrefix, String aSufix, String aVal, int aTaille, String aSep,
45              char aBouchon) {
46          if (aPrefix != null) {
47              aBuff.append(aPrefix);
48          }
49          aBuff.append(aVal);
50          if (aSufix != null) {
51              aBuff.append(aSufix);
52          }
53          int tailleVal = DEFAULT_SIZE;
54          if (aVal != null) {
55              tailleVal = aVal.length();
56          }
57          for (int diff = aTaille - tailleVal; diff > 0; diff--) {
58              aBuff.append(aBouchon);
59          }
60          aBuff.append(aSep);
61      }
62  }