Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
Caverphone |
|
| 1.4;1.4 |
1 | /* | |
2 | * Licensed to the Apache Software Foundation (ASF) under one or more | |
3 | * contributor license agreements. See the NOTICE file distributed with | |
4 | * this work for additional information regarding copyright ownership. | |
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 | |
6 | * (the "License"); you may not use this file except in compliance with | |
7 | * the License. You may obtain a copy of the License at | |
8 | * | |
9 | * http://www.apache.org/licenses/LICENSE-2.0 | |
10 | * | |
11 | * Unless required by applicable law or agreed to in writing, software | |
12 | * distributed under the License is distributed on an "AS IS" BASIS, | |
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | * See the License for the specific language governing permissions and | |
15 | * limitations under the License. | |
16 | */ | |
17 | ||
18 | package org.apache.commons.codec.language; | |
19 | ||
20 | import org.apache.commons.codec.EncoderException; | |
21 | import org.apache.commons.codec.StringEncoder; | |
22 | ||
23 | /** | |
24 | * Encodes a string into a Caverphone 2.0 value. Delegate to a {@link Caverphone2} instance. | |
25 | * | |
26 | * This is an algorithm created by the Caversham Project at the University of Otago. It implements the Caverphone 2.0 | |
27 | * algorithm: | |
28 | * | |
29 | * @version $Id$ | |
30 | * @see <a href="http://en.wikipedia.org/wiki/Caverphone">Wikipedia - Caverphone</a> | |
31 | * @see <a href="http://caversham.otago.ac.nz/files/working/ctp150804.pdf">Caverphone 2.0 specification</a> | |
32 | * @since 1.4 | |
33 | * @deprecated 1.5 Replaced by {@link Caverphone2}, will be removed in 2.0. | |
34 | */ | |
35 | @Deprecated | |
36 | public class Caverphone implements StringEncoder { | |
37 | ||
38 | /** | |
39 | * Delegate to a {@link Caverphone2} instance to avoid code duplication. | |
40 | */ | |
41 | 0 | final private Caverphone2 encoder = new Caverphone2(); |
42 | ||
43 | /** | |
44 | * Creates an instance of the Caverphone encoder | |
45 | */ | |
46 | public Caverphone() { | |
47 | 0 | super(); |
48 | 0 | } |
49 | ||
50 | /** | |
51 | * Encodes the given String into a Caverphone value. | |
52 | * | |
53 | * @param source | |
54 | * String the source string | |
55 | * @return A caverphone code for the given String | |
56 | */ | |
57 | public String caverphone(final String source) { | |
58 | 0 | return this.encoder.encode(source); |
59 | } | |
60 | ||
61 | /** | |
62 | * Encodes an Object using the caverphone algorithm. This method is provided in order to satisfy the requirements of | |
63 | * the Encoder interface, and will throw an EncoderException if the supplied object is not of type java.lang.String. | |
64 | * | |
65 | * @param obj | |
66 | * Object to encode | |
67 | * @return An object (or type java.lang.String) containing the caverphone code which corresponds to the String | |
68 | * supplied. | |
69 | * @throws EncoderException | |
70 | * if the parameter supplied is not of type java.lang.String | |
71 | */ | |
72 | @Override | |
73 | public Object encode(final Object obj) throws EncoderException { | |
74 | 0 | if (!(obj instanceof String)) { |
75 | 0 | throw new EncoderException("Parameter supplied to Caverphone encode is not of type java.lang.String"); |
76 | } | |
77 | 0 | return this.caverphone((String) obj); |
78 | } | |
79 | ||
80 | /** | |
81 | * Encodes a String using the Caverphone algorithm. | |
82 | * | |
83 | * @param str | |
84 | * String object to encode | |
85 | * @return The caverphone code corresponding to the String supplied | |
86 | */ | |
87 | @Override | |
88 | public String encode(final String str) { | |
89 | 0 | return this.caverphone(str); |
90 | } | |
91 | ||
92 | /** | |
93 | * Tests if the caverphones of two strings are identical. | |
94 | * | |
95 | * @param str1 | |
96 | * First of two strings to compare | |
97 | * @param str2 | |
98 | * Second of two strings to compare | |
99 | * @return {@code true} if the caverphones of these strings are identical, {@code false} otherwise. | |
100 | */ | |
101 | public boolean isCaverphoneEqual(final String str1, final String str2) { | |
102 | 0 | return this.caverphone(str1).equals(this.caverphone(str2)); |
103 | } | |
104 | ||
105 | } |