Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
IdentityConversionFactory |
|
| 1.3333333333333333;1.333 | ||||
IdentityConversionFactory$IdentityConversion |
|
| 1.3333333333333333;1.333 |
1 | /* | |
2 | * Copyright 2004 The Apache Software Foundation | |
3 | * | |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | */ | |
16 | package org.apache.commons.convert.conversion; | |
17 | ||
18 | import org.apache.commons.convert.Conversion; | |
19 | import org.apache.commons.convert.ConversionFactory; | |
20 | import org.apache.commons.convert.Converter; | |
21 | ||
22 | /** | |
23 | * Conversion from TimeZone to String using <code>getID()</code>. | |
24 | * | |
25 | * @author Stephen Colebourne | |
26 | * @version $Id: IdentityConversionFactory.java 155441 2005-02-26 13:19:22Z dirkv $ | |
27 | * @since 1.0 | |
28 | */ | |
29 | public class IdentityConversionFactory implements ConversionFactory { | |
30 | ||
31 | /** Singleton instance of this factory */ | |
32 | 0 | public static final ConversionFactory INSTANCE = new IdentityConversionFactory(); |
33 | ||
34 | /** | |
35 | * Restricted constructor. | |
36 | */ | |
37 | protected IdentityConversionFactory() { | |
38 | 0 | super(); |
39 | 0 | } |
40 | ||
41 | //----------------------------------------------------------------------- | |
42 | /** | |
43 | * Checks if the types are equal, if so return 80. | |
44 | * | |
45 | * @param value the value to be converted, read only, may be null | |
46 | * @param fromType the type to convert from, may be null | |
47 | * @param toType the type to convert to, may be null | |
48 | * @return 80 if types are equal | |
49 | */ | |
50 | public int getMatchPercent(Object value, Class fromType, Class toType) { | |
51 | 0 | if (fromType == toType && fromType != null) { |
52 | 0 | return 80; |
53 | } | |
54 | 0 | return 0; |
55 | } | |
56 | ||
57 | /** | |
58 | * Create a new conversion object for the specified from and to types. | |
59 | * <p> | |
60 | * This implementation returns the identity conversion. | |
61 | * | |
62 | * @param value the value to be converted, read only, may be null | |
63 | * @param fromType the type to convert from, may be null | |
64 | * @param toType the type to convert to, may be null | |
65 | * @return a Conversion object for repeatedly performing conversions | |
66 | */ | |
67 | public Conversion getInstance(Object value, Class fromType, Class toType) { | |
68 | 0 | return new IdentityConversion(fromType, toType); |
69 | } | |
70 | ||
71 | /** | |
72 | * Gets a string suitable for debugging. | |
73 | * | |
74 | * @return a debugging string | |
75 | */ | |
76 | public String toString() { | |
77 | 0 | return "ConversionFactory[Identity]"; |
78 | } | |
79 | ||
80 | //----------------------------------------------------------------------- | |
81 | /** | |
82 | * Generic conversion implementation that returns the input value. | |
83 | */ | |
84 | class IdentityConversion extends AbstractConversion { | |
85 | ||
86 | /** | |
87 | * Constructs a Conversion. | |
88 | * | |
89 | * @param fromType the type to convert from | |
90 | * @param toType the type to convert to | |
91 | */ | |
92 | 0 | IdentityConversion(Class fromType, Class toType) { |
93 | 0 | super(fromType, toType); |
94 | 0 | } |
95 | ||
96 | /** | |
97 | * Converts the input value by returning it unchanged. | |
98 | * | |
99 | * @param value the input value to be converted, pre-checked to not be null | |
100 | * @param converter the converter being used, not null | |
101 | * @return the input value | |
102 | */ | |
103 | public Object convert(Object value, Converter converter) { | |
104 | 0 | return value; |
105 | } | |
106 | } | |
107 | ||
108 | } |