View Javadoc
1 /* 2 QueryJ 3 4 Copyright (C) 2002 Jose San Leandro Armend?riz 5 jsanleandro@yahoo.es 6 chousz@yahoo.com 7 8 This library is free software; you can redistribute it and/or 9 modify it under the terms of the GNU General Public 10 License as published by the Free Software Foundation; either 11 version 2.1 of the License, or (at your option) any later version. 12 13 This library is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 General Public License for more details. 17 18 You should have received a copy of the GNU General Public 19 License along with this library; if not, write to the Free Software 20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 22 Thanks to ACM S.L. for distributing this library under the GPL license. 23 Contact info: jsanleandro@yahoo.es 24 Postal Address: c/Playa de Lagoa, 1 25 Urb. Valdecaba?as 26 Boadilla del monte 27 28660 Madrid 28 Spain 29 30 ****************************************************************************** 31 * 32 * Filename: $RCSfile: QueryUtils.java,v $ 33 * 34 * Author: Jose San Leandro Armend?riz 35 * 36 * Description: Provides some useful methods when working with queries. 37 * 38 * Last modified by: $Author: chous $ at $Date: 2003/08/29 08:15:00 $ 39 * 40 * File version: $Revision: 1.1 $ 41 * 42 * Project version: $Name: $ 43 * 44 * $Id: QueryUtils.java,v 1.1 2003/08/29 08:15:00 chous Exp $ 45 * 46 */ 47 package org.acmsl.queryj; 48 49 /* 50 * Importing ACM-SL classes. 51 */ 52 import org.acmsl.queryj.Query; 53 import org.acmsl.queryj.SelectQuery; 54 55 /* 56 * Importing some JDK classes. 57 */ 58 import java.lang.ref.WeakReference; 59 import java.util.Collection; 60 import java.util.Iterator; 61 62 /*** 63 * Provides some useful methods when working with queries. 64 * @author <a href="mailto:jsanleandro@yahoo.es">Jose San Leandro</a> 65 * @version $Revision: 1.1 $ 66 */ 67 public abstract class QueryUtils 68 { 69 /*** 70 * Singleton implemented as a weak reference. 71 */ 72 private static WeakReference singleton; 73 74 /*** 75 * Protected constructor to avoid accidental instantiation. 76 */ 77 protected QueryUtils() {}; 78 79 /*** 80 * Specifies a new weak reference. 81 * @param utils the utils instance to use. 82 */ 83 protected static void setReference(QueryUtils utils) 84 { 85 singleton = new WeakReference(utils); 86 } 87 88 /*** 89 * Retrieves the weak reference. 90 * @return such reference. 91 */ 92 protected static WeakReference getReference() 93 { 94 return singleton; 95 } 96 97 /*** 98 * Retrieves a QueryUtils instance. 99 * @return such instance. 100 */ 101 public static QueryUtils getInstance() 102 { 103 QueryUtils result = null; 104 105 WeakReference reference = getReference(); 106 107 if (reference != null) 108 { 109 result = (QueryUtils) reference.get(); 110 } 111 112 if (result == null) 113 { 114 result = new QueryUtils() {}; 115 116 setReference(result); 117 } 118 119 return result; 120 } 121 122 /*** 123 * Concatenates all elements of given collection using a separator. 124 * @param items the collection. 125 * @param separator the separator. 126 * @return such concatenation. 127 */ 128 public String concatenate(Collection items, String separator) 129 { 130 StringBuffer t_sbResult = new StringBuffer(); 131 132 if (items != null) 133 { 134 Iterator t_itItems = items.iterator(); 135 136 if (t_itItems.hasNext()) 137 { 138 t_sbResult.append(t_itItems.next()); 139 } 140 141 while ( (t_itItems != null) 142 && (t_itItems.hasNext())) 143 { 144 t_sbResult.append(separator); 145 t_sbResult.append(t_itItems.next()); 146 } 147 } 148 149 return t_sbResult.toString(); 150 } 151 }

This page was automatically generated by Maven