1 /*
2 Copyright (c) 2003, Vilmantas Baranauskas
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright notice,
8 this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright notice,
10 this list of conditions and the following disclaimer in the documentation
11 and/or other materials provided with the distribution.
12 * The names of its contributors may not be used to endorse or promote
13 products derived from this software without specific prior written
14 permission.
15
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 POSSIBILITY OF SUCH DAMAGE.
27 */
28 package org.sovt.impl;
29
30 import org.sovt.Transformer;
31
32 /***
33 * This transformer is for trimming string objects. "toString()" method is
34 * invoked on the object first. "null" objects are skipped.
35 *
36 * @author Vilmantas Baranauskas (vilmantas_baranauskas@yahoo.com)
37 */
38 public class TrimTransformer implements Transformer {
39 //-- constants -------------------------------------------------------------
40 //-- variables -------------------------------------------------------------
41 //-- constructors ----------------------------------------------------------
42 /***
43 * Creates instance of TrimTransformer.
44 */
45 public TrimTransformer() {
46 }
47
48 //-- methods ---------------------------------------------------------------
49 /***
50 * Returns itself. This transformer is not configurable and therefore single
51 * instance may be used everywhere.
52 *
53 * @return clone of itself.
54 * @noinspection CloneDoesntCallSuperClone,CloneDoesntDeclareCloneNotSupportedException
55 */
56 public Object clone() {
57 return this;
58 }
59
60 /***
61 * Trims string value. "toString()" method is invoked on the object first.
62 * "null" objects are skipped.
63 *
64 * @param object String value to trim.
65 * @return trimmed string or null if object is null.
66 */
67 public Object transform(Object object) {
68 if (object == null) {
69 return null;
70 }
71 return object.toString().trim();
72 }
73
74 }