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