|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
StringToBooleanConverter.java | 0% | 0% | 0% | 0% |
|
1 |
/*
|
|
2 |
* Copyright (C) The Spice Group. All rights reserved.
|
|
3 |
*
|
|
4 |
* This software is published under the terms of the Spice
|
|
5 |
* Software License version 1.1, a copy of which has been included
|
|
6 |
* with this distribution in the LICENSE.txt file.
|
|
7 |
*/
|
|
8 |
package org.codehaus.spice.converter.lib;
|
|
9 |
|
|
10 |
import org.codehaus.spice.converter.AbstractConverter;
|
|
11 |
import org.codehaus.spice.converter.ConverterException;
|
|
12 |
|
|
13 |
/**
|
|
14 |
* String to Boolean converter
|
|
15 |
*
|
|
16 |
* @author Peter Donald
|
|
17 |
* @version $Revision: 1.1 $ $Date: 2003/12/02 08:37:56 $
|
|
18 |
*/
|
|
19 |
public class StringToBooleanConverter |
|
20 |
extends AbstractConverter
|
|
21 |
{ |
|
22 |
/**
|
|
23 |
* Construct the converter.
|
|
24 |
*/
|
|
25 | 0 |
public StringToBooleanConverter()
|
26 |
{ |
|
27 | 0 |
this( null ); |
28 |
} |
|
29 |
|
|
30 |
/**
|
|
31 |
* Construct the converter with a default value.
|
|
32 |
* If the default value is non-null, it will be returned if unable
|
|
33 |
* to convert object to correct type.
|
|
34 |
*
|
|
35 |
* @param defaultValue the default value
|
|
36 |
*/
|
|
37 | 0 |
public StringToBooleanConverter( final Boolean defaultValue )
|
38 |
{ |
|
39 | 0 |
super( String.class, Boolean.class, defaultValue ); |
40 |
} |
|
41 |
|
|
42 |
/**
|
|
43 |
* Converts a String to a Boolean.
|
|
44 |
*
|
|
45 |
* @param object the original object to convert
|
|
46 |
* @param context the context in which to convert object (unused)
|
|
47 |
* @return the converted object
|
|
48 |
* @throws ConverterException if error converting object
|
|
49 |
*/
|
|
50 | 0 |
public Object convert( final Object object, final Object context )
|
51 |
throws ConverterException
|
|
52 |
{ |
|
53 | 0 |
final String string = (String)object; |
54 | 0 |
if( string.equalsIgnoreCase( "1" ) || |
55 |
string.equalsIgnoreCase( "true" ) ||
|
|
56 |
string.equalsIgnoreCase( "yes" ) )
|
|
57 |
{ |
|
58 | 0 |
return Boolean.TRUE;
|
59 |
} |
|
60 | 0 |
else if( string.equalsIgnoreCase( "0" ) || |
61 |
string.equalsIgnoreCase( "false" ) ||
|
|
62 |
string.equalsIgnoreCase( "no" ) )
|
|
63 |
{ |
|
64 | 0 |
return Boolean.FALSE;
|
65 |
} |
|
66 |
else
|
|
67 |
{ |
|
68 | 0 |
return noConvert( object, null ); |
69 |
} |
|
70 |
} |
|
71 |
} |
|
72 |
|
|
73 |
|
|