org.apache.commons.codec_1.3.0.v201101211617

16:40:58.997 INFO  jd.cli.Main - Decompiling org.apache.commons.codec_1.3.0.v201101211617.jar
package org.apache.commons.codec;

public abstract interface BinaryDecoder
  extends Decoder
{
  public abstract byte[] decode(byte[] paramArrayOfByte)
    throws DecoderException;
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.BinaryDecoder
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec;

public abstract interface BinaryEncoder
  extends Encoder
{
  public abstract byte[] encode(byte[] paramArrayOfByte)
    throws EncoderException;
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.BinaryEncoder
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec;

public abstract interface Decoder
{
  public abstract Object decode(Object paramObject)
    throws DecoderException;
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.Decoder
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec;

public class DecoderException
  extends Exception
{
  public DecoderException(String pMessage)
  {
    super(pMessage);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.DecoderException
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec;

public abstract interface Encoder
{
  public abstract Object encode(Object paramObject)
    throws EncoderException;
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.Encoder
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec;

public class EncoderException
  extends Exception
{
  public EncoderException(String pMessage)
  {
    super(pMessage);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.EncoderException
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec;

public abstract interface StringDecoder
  extends Decoder
{
  public abstract String decode(String paramString)
    throws DecoderException;
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.StringDecoder
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec;

public abstract interface StringEncoder
  extends Encoder
{
  public abstract String encode(String paramString)
    throws EncoderException;
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.StringEncoder
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec;

import java.util.Comparator;

public class StringEncoderComparator
  implements Comparator
{
  private StringEncoder stringEncoder;
  
  public StringEncoderComparator() {}
  
  public StringEncoderComparator(StringEncoder stringEncoder)
  {
    this.stringEncoder = stringEncoder;
  }
  
  public int compare(Object o1, Object o2)
  {
    int compareCode = 0;
    try
    {
      Comparable s1 = (Comparable)stringEncoder.encode(o1);
      Comparable s2 = (Comparable)stringEncoder.encode(o2);
      compareCode = s1.compareTo(s2);
    }
    catch (EncoderException ee)
    {
      compareCode = 0;
    }
    return compareCode;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.StringEncoderComparator
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec.binary;

import org.apache.commons.codec.BinaryDecoder;
import org.apache.commons.codec.BinaryEncoder;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.EncoderException;

public class Base64
  implements BinaryEncoder, BinaryDecoder
{
  static final int CHUNK_SIZE = 76;
  static final byte[] CHUNK_SEPARATOR = "\r\n".getBytes();
  static final int BASELENGTH = 255;
  static final int LOOKUPLENGTH = 64;
  static final int EIGHTBIT = 8;
  static final int SIXTEENBIT = 16;
  static final int TWENTYFOURBITGROUP = 24;
  static final int FOURBYTE = 4;
  static final int SIGN = -128;
  static final byte PAD = 61;
  private static byte[] base64Alphabet = new byte['�'];
  private static byte[] lookUpBase64Alphabet = new byte[64];
  
  static
  {
    for (int i = 0; i < 255; i++) {
      base64Alphabet[i] = -1;
    }
    for (int i = 90; i >= 65; i--) {
      base64Alphabet[i] = ((byte)(i - 65));
    }
    for (int i = 122; i >= 97; i--) {
      base64Alphabet[i] = ((byte)(i - 97 + 26));
    }
    for (int i = 57; i >= 48; i--) {
      base64Alphabet[i] = ((byte)(i - 48 + 52));
    }
    base64Alphabet[43] = 62;
    base64Alphabet[47] = 63;
    for (int i = 0; i <= 25; i++) {
      lookUpBase64Alphabet[i] = ((byte)(65 + i));
    }
    int i = 26;
    for (int j = 0; i <= 51; j++)
    {
      lookUpBase64Alphabet[i] = ((byte)(97 + j));i++;
    }
    int i = 52;
    for (int j = 0; i <= 61; j++)
    {
      lookUpBase64Alphabet[i] = ((byte)(48 + j));i++;
    }
    lookUpBase64Alphabet[62] = 43;
    lookUpBase64Alphabet[63] = 47;
  }
  
  private static boolean isBase64(byte octect)
  {
    if (octect == 61) {
      return true;
    }
    if (base64Alphabet[octect] == -1) {
      return false;
    }
    return true;
  }
  
  public static boolean isArrayByteBase64(byte[] arrayOctect)
  {
    arrayOctect = discardWhitespace(arrayOctect);
    
    int length = arrayOctect.length;
    if (length == 0) {
      return true;
    }
    for (int i = 0; i < length; i++) {
      if (!isBase64(arrayOctect[i])) {
        return false;
      }
    }
    return true;
  }
  
  public static byte[] encodeBase64(byte[] binaryData)
  {
    return encodeBase64(binaryData, false);
  }
  
  public static byte[] encodeBase64Chunked(byte[] binaryData)
  {
    return encodeBase64(binaryData, true);
  }
  
  public Object decode(Object pObject)
    throws DecoderException
  {
    if (!(pObject instanceof byte[])) {
      throw new DecoderException("Parameter supplied to Base64 decode is not a byte[]");
    }
    return decode((byte[])pObject);
  }
  
  public byte[] decode(byte[] pArray)
  {
    return decodeBase64(pArray);
  }
  
  public static byte[] encodeBase64(byte[] binaryData, boolean isChunked)
  {
    int lengthDataBits = binaryData.length * 8;
    int fewerThan24bits = lengthDataBits % 24;
    int numberTriplets = lengthDataBits / 24;
    byte[] encodedData = null;
    int encodedDataLength = 0;
    int nbrChunks = 0;
    if (fewerThan24bits != 0) {
      encodedDataLength = (numberTriplets + 1) * 4;
    } else {
      encodedDataLength = numberTriplets * 4;
    }
    if (isChunked)
    {
      nbrChunks = CHUNK_SEPARATOR.length == 0 ? 0 : (int)Math.ceil(encodedDataLength / 76.0F);
      
      encodedDataLength += nbrChunks * CHUNK_SEPARATOR.length;
    }
    encodedData = new byte[encodedDataLength];
    
    byte k = 0;byte l = 0;byte b1 = 0;byte b2 = 0;byte b3 = 0;
    
    int encodedIndex = 0;
    int dataIndex = 0;
    int i = 0;
    int nextSeparatorIndex = 76;
    int chunksSoFar = 0;
    for (i = 0; i < numberTriplets; i++)
    {
      dataIndex = i * 3;
      b1 = binaryData[dataIndex];
      b2 = binaryData[(dataIndex + 1)];
      b3 = binaryData[(dataIndex + 2)];
      
      l = (byte)(b2 & 0xF);
      k = (byte)(b1 & 0x3);
      
      byte val1 = (b1 & 0xFFFFFF80) == 0 ? (byte)(b1 >> 2) : (byte)(b1 >> 2 ^ 0xC0);
      
      byte val2 = (b2 & 0xFFFFFF80) == 0 ? (byte)(b2 >> 4) : (byte)(b2 >> 4 ^ 0xF0);
      
      byte val3 = (b3 & 0xFFFFFF80) == 0 ? (byte)(b3 >> 6) : (byte)(b3 >> 6 ^ 0xFC);
      
      encodedData[encodedIndex] = lookUpBase64Alphabet[val1];
      
      encodedData[(encodedIndex + 1)] = lookUpBase64Alphabet[(val2 | k << 4)];
      
      encodedData[(encodedIndex + 2)] = lookUpBase64Alphabet[(l << 2 | val3)];
      
      encodedData[(encodedIndex + 3)] = lookUpBase64Alphabet[(b3 & 0x3F)];
      
      encodedIndex += 4;
      if (isChunked) {
        if (encodedIndex == nextSeparatorIndex)
        {
          System.arraycopy(CHUNK_SEPARATOR, 0, encodedData, encodedIndex, CHUNK_SEPARATOR.length);
          
          chunksSoFar++;
          nextSeparatorIndex = 76 * (chunksSoFar + 1) + chunksSoFar * CHUNK_SEPARATOR.length;
          
          encodedIndex += CHUNK_SEPARATOR.length;
        }
      }
    }
    dataIndex = i * 3;
    if (fewerThan24bits == 8)
    {
      b1 = binaryData[dataIndex];
      k = (byte)(b1 & 0x3);
      
      byte val1 = (b1 & 0xFFFFFF80) == 0 ? (byte)(b1 >> 2) : (byte)(b1 >> 2 ^ 0xC0);
      
      encodedData[encodedIndex] = lookUpBase64Alphabet[val1];
      encodedData[(encodedIndex + 1)] = lookUpBase64Alphabet[(k << 4)];
      encodedData[(encodedIndex + 2)] = 61;
      encodedData[(encodedIndex + 3)] = 61;
    }
    else if (fewerThan24bits == 16)
    {
      b1 = binaryData[dataIndex];
      b2 = binaryData[(dataIndex + 1)];
      l = (byte)(b2 & 0xF);
      k = (byte)(b1 & 0x3);
      
      byte val1 = (b1 & 0xFFFFFF80) == 0 ? (byte)(b1 >> 2) : (byte)(b1 >> 2 ^ 0xC0);
      
      byte val2 = (b2 & 0xFFFFFF80) == 0 ? (byte)(b2 >> 4) : (byte)(b2 >> 4 ^ 0xF0);
      
      encodedData[encodedIndex] = lookUpBase64Alphabet[val1];
      encodedData[(encodedIndex + 1)] = lookUpBase64Alphabet[(val2 | k << 4)];
      
      encodedData[(encodedIndex + 2)] = lookUpBase64Alphabet[(l << 2)];
      encodedData[(encodedIndex + 3)] = 61;
    }
    if (isChunked) {
      if (chunksSoFar < nbrChunks) {
        System.arraycopy(CHUNK_SEPARATOR, 0, encodedData, encodedDataLength - CHUNK_SEPARATOR.length, CHUNK_SEPARATOR.length);
      }
    }
    return encodedData;
  }
  
  public static byte[] decodeBase64(byte[] base64Data)
  {
    base64Data = discardNonBase64(base64Data);
    if (base64Data.length == 0) {
      return new byte[0];
    }
    int numberQuadruple = base64Data.length / 4;
    byte[] decodedData = null;
    byte b1 = 0;byte b2 = 0;byte b3 = 0;byte b4 = 0;byte marker0 = 0;byte marker1 = 0;
    
    int encodedIndex = 0;
    int dataIndex = 0;
    
    int lastData = base64Data.length;
    while (base64Data[(lastData - 1)] == 61)
    {
      lastData--;
      if (lastData == 0) {
        return new byte[0];
      }
    }
    decodedData = new byte[lastData - numberQuadruple];
    for (int i = 0; i < numberQuadruple; i++)
    {
      dataIndex = i * 4;
      marker0 = base64Data[(dataIndex + 2)];
      marker1 = base64Data[(dataIndex + 3)];
      
      b1 = base64Alphabet[base64Data[dataIndex]];
      b2 = base64Alphabet[base64Data[(dataIndex + 1)]];
      if ((marker0 != 61) && (marker1 != 61))
      {
        b3 = base64Alphabet[marker0];
        b4 = base64Alphabet[marker1];
        
        decodedData[encodedIndex] = ((byte)(b1 << 2 | b2 >> 4));
        decodedData[(encodedIndex + 1)] = ((byte)((b2 & 0xF) << 4 | b3 >> 2 & 0xF));
        
        decodedData[(encodedIndex + 2)] = ((byte)(b3 << 6 | b4));
      }
      else if (marker0 == 61)
      {
        decodedData[encodedIndex] = ((byte)(b1 << 2 | b2 >> 4));
      }
      else if (marker1 == 61)
      {
        b3 = base64Alphabet[marker0];
        
        decodedData[encodedIndex] = ((byte)(b1 << 2 | b2 >> 4));
        decodedData[(encodedIndex + 1)] = ((byte)((b2 & 0xF) << 4 | b3 >> 2 & 0xF));
      }
      encodedIndex += 3;
    }
    return decodedData;
  }
  
  static byte[] discardWhitespace(byte[] data)
  {
    byte[] groomedData = new byte[data.length];
    int bytesCopied = 0;
    for (int i = 0; i < data.length; i++) {
      switch (data[i])
      {
      case 9: 
      case 10: 
      case 13: 
      case 32: 
        break;
      default: 
        groomedData[(bytesCopied++)] = data[i];
      }
    }
    byte[] packedData = new byte[bytesCopied];
    
    System.arraycopy(groomedData, 0, packedData, 0, bytesCopied);
    
    return packedData;
  }
  
  static byte[] discardNonBase64(byte[] data)
  {
    byte[] groomedData = new byte[data.length];
    int bytesCopied = 0;
    for (int i = 0; i < data.length; i++) {
      if (isBase64(data[i])) {
        groomedData[(bytesCopied++)] = data[i];
      }
    }
    byte[] packedData = new byte[bytesCopied];
    
    System.arraycopy(groomedData, 0, packedData, 0, bytesCopied);
    
    return packedData;
  }
  
  public Object encode(Object pObject)
    throws EncoderException
  {
    if (!(pObject instanceof byte[])) {
      throw new EncoderException("Parameter supplied to Base64 encode is not a byte[]");
    }
    return encode((byte[])pObject);
  }
  
  public byte[] encode(byte[] pArray)
  {
    return encodeBase64(pArray, false);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.binary.Base64
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec.binary;

import org.apache.commons.codec.BinaryDecoder;
import org.apache.commons.codec.BinaryEncoder;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.EncoderException;

public class BinaryCodec
  implements BinaryDecoder, BinaryEncoder
{
  private static final char[] EMPTY_CHAR_ARRAY = new char[0];
  private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
  private static final int BIT_0 = 1;
  private static final int BIT_1 = 2;
  private static final int BIT_2 = 4;
  private static final int BIT_3 = 8;
  private static final int BIT_4 = 16;
  private static final int BIT_5 = 32;
  private static final int BIT_6 = 64;
  private static final int BIT_7 = 128;
  private static final int[] BITS = { 1, 2, 4, 8, 16, 32, 64, 128 };
  
  public byte[] encode(byte[] raw)
  {
    return toAsciiBytes(raw);
  }
  
  public Object encode(Object raw)
    throws EncoderException
  {
    if (!(raw instanceof byte[])) {
      throw new EncoderException("argument not a byte array");
    }
    return toAsciiChars((byte[])raw);
  }
  
  public Object decode(Object ascii)
    throws DecoderException
  {
    if (ascii == null) {
      return EMPTY_BYTE_ARRAY;
    }
    if ((ascii instanceof byte[])) {
      return fromAscii((byte[])ascii);
    }
    if ((ascii instanceof char[])) {
      return fromAscii((char[])ascii);
    }
    if ((ascii instanceof String)) {
      return fromAscii(((String)ascii).toCharArray());
    }
    throw new DecoderException("argument not a byte array");
  }
  
  public byte[] decode(byte[] ascii)
  {
    return fromAscii(ascii);
  }
  
  public byte[] toByteArray(String ascii)
  {
    if (ascii == null) {
      return EMPTY_BYTE_ARRAY;
    }
    return fromAscii(ascii.toCharArray());
  }
  
  public static byte[] fromAscii(char[] ascii)
  {
    if ((ascii == null) || (ascii.length == 0)) {
      return EMPTY_BYTE_ARRAY;
    }
    byte[] l_raw = new byte[ascii.length >> 3];
    
    int ii = 0;
    for (int jj = ascii.length - 1; ii < l_raw.length; jj -= 8)
    {
      for (int bits = 0; bits < BITS.length; bits++) {
        if (ascii[(jj - bits)] == '1')
        {
          int tmp58_57 = ii; byte[] tmp58_56 = l_raw;tmp58_56[tmp58_57] = ((byte)(tmp58_56[tmp58_57] | BITS[bits]));
        }
      }
      ii++;
    }
    return l_raw;
  }
  
  public static byte[] fromAscii(byte[] ascii)
  {
    if ((ascii == null) || (ascii.length == 0)) {
      return EMPTY_BYTE_ARRAY;
    }
    byte[] l_raw = new byte[ascii.length >> 3];
    
    int ii = 0;
    for (int jj = ascii.length - 1; ii < l_raw.length; jj -= 8)
    {
      for (int bits = 0; bits < BITS.length; bits++) {
        if (ascii[(jj - bits)] == 49)
        {
          int tmp58_57 = ii; byte[] tmp58_56 = l_raw;tmp58_56[tmp58_57] = ((byte)(tmp58_56[tmp58_57] | BITS[bits]));
        }
      }
      ii++;
    }
    return l_raw;
  }
  
  public static byte[] toAsciiBytes(byte[] raw)
  {
    if ((raw == null) || (raw.length == 0)) {
      return EMPTY_BYTE_ARRAY;
    }
    byte[] l_ascii = new byte[raw.length << 3];
    
    int ii = 0;
    for (int jj = l_ascii.length - 1; ii < raw.length; jj -= 8)
    {
      for (int bits = 0; bits < BITS.length; bits++) {
        if ((raw[ii] & BITS[bits]) == 0) {
          l_ascii[(jj - bits)] = 48;
        } else {
          l_ascii[(jj - bits)] = 49;
        }
      }
      ii++;
    }
    return l_ascii;
  }
  
  public static char[] toAsciiChars(byte[] raw)
  {
    if ((raw == null) || (raw.length == 0)) {
      return EMPTY_CHAR_ARRAY;
    }
    char[] l_ascii = new char[raw.length << 3];
    
    int ii = 0;
    for (int jj = l_ascii.length - 1; ii < raw.length; jj -= 8)
    {
      for (int bits = 0; bits < BITS.length; bits++) {
        if ((raw[ii] & BITS[bits]) == 0) {
          l_ascii[(jj - bits)] = '0';
        } else {
          l_ascii[(jj - bits)] = '1';
        }
      }
      ii++;
    }
    return l_ascii;
  }
  
  public static String toAsciiString(byte[] raw)
  {
    return new String(toAsciiChars(raw));
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.binary.BinaryCodec
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec.binary;

import org.apache.commons.codec.BinaryDecoder;
import org.apache.commons.codec.BinaryEncoder;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.EncoderException;

public class Hex
  implements BinaryEncoder, BinaryDecoder
{
  private static final char[] DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
  
  public static byte[] decodeHex(char[] data)
    throws DecoderException
  {
    int len = data.length;
    if ((len & 0x1) != 0) {
      throw new DecoderException("Odd number of characters.");
    }
    byte[] out = new byte[len >> 1];
    
    int i = 0;
    for (int j = 0; j < len; i++)
    {
      int f = toDigit(data[j], j) << 4;
      j++;
      f |= toDigit(data[j], j);
      j++;
      out[i] = ((byte)(f & 0xFF));
    }
    return out;
  }
  
  protected static int toDigit(char ch, int index)
    throws DecoderException
  {
    int digit = Character.digit(ch, 16);
    if (digit == -1) {
      throw new DecoderException("Illegal hexadecimal charcter " + ch + " at index " + index);
    }
    return digit;
  }
  
  public static char[] encodeHex(byte[] data)
  {
    int l = data.length;
    
    char[] out = new char[l << 1];
    
    int i = 0;
    for (int j = 0; i < l; i++)
    {
      out[(j++)] = DIGITS[((0xF0 & data[i]) >>> 4)];
      out[(j++)] = DIGITS[(0xF & data[i])];
    }
    return out;
  }
  
  public byte[] decode(byte[] array)
    throws DecoderException
  {
    return decodeHex(new String(array).toCharArray());
  }
  
  public Object decode(Object object)
    throws DecoderException
  {
    try
    {
      char[] charArray = (object instanceof String) ? ((String)object).toCharArray() : (char[])object;
      return decodeHex(charArray);
    }
    catch (ClassCastException e)
    {
      throw new DecoderException(e.getMessage());
    }
  }
  
  public byte[] encode(byte[] array)
  {
    return new String(encodeHex(array)).getBytes();
  }
  
  public Object encode(Object object)
    throws EncoderException
  {
    try
    {
      byte[] byteArray = (object instanceof String) ? ((String)object).getBytes() : (byte[])object;
      return encodeHex(byteArray);
    }
    catch (ClassCastException e)
    {
      throw new EncoderException(e.getMessage());
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.binary.Hex
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec.digest;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import org.apache.commons.codec.binary.Hex;

public class DigestUtils
{
  static MessageDigest getDigest(String algorithm)
  {
    try
    {
      return MessageDigest.getInstance(algorithm);
    }
    catch (NoSuchAlgorithmException e)
    {
      throw new RuntimeException(e.getMessage());
    }
  }
  
  private static MessageDigest getMd5Digest()
  {
    return getDigest("MD5");
  }
  
  private static MessageDigest getShaDigest()
  {
    return getDigest("SHA");
  }
  
  public static byte[] md5(byte[] data)
  {
    return getMd5Digest().digest(data);
  }
  
  public static byte[] md5(String data)
  {
    return md5(data.getBytes());
  }
  
  public static String md5Hex(byte[] data)
  {
    return new String(Hex.encodeHex(md5(data)));
  }
  
  public static String md5Hex(String data)
  {
    return new String(Hex.encodeHex(md5(data)));
  }
  
  public static byte[] sha(byte[] data)
  {
    return getShaDigest().digest(data);
  }
  
  public static byte[] sha(String data)
  {
    return sha(data.getBytes());
  }
  
  public static String shaHex(byte[] data)
  {
    return new String(Hex.encodeHex(sha(data)));
  }
  
  public static String shaHex(String data)
  {
    return new String(Hex.encodeHex(sha(data)));
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.digest.DigestUtils
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec.language;

public class DoubleMetaphone$DoubleMetaphoneResult
{
  private StringBuffer primary;
  private StringBuffer alternate;
  private int maxLength;
  private final DoubleMetaphone this$0;
  
  public DoubleMetaphone$DoubleMetaphoneResult(DoubleMetaphone this$0, int maxLength)
  {
    this.this$0 = this$0;primary = new StringBuffer(this.this$0.getMaxCodeLen());alternate = new StringBuffer(this.this$0.getMaxCodeLen());
    this.maxLength = maxLength;
  }
  
  public void append(char value)
  {
    appendPrimary(value);
    appendAlternate(value);
  }
  
  public void append(char primary, char alternate)
  {
    appendPrimary(primary);
    appendAlternate(alternate);
  }
  
  public void appendPrimary(char value)
  {
    if (primary.length() < maxLength) {
      primary.append(value);
    }
  }
  
  public void appendAlternate(char value)
  {
    if (alternate.length() < maxLength) {
      alternate.append(value);
    }
  }
  
  public void append(String value)
  {
    appendPrimary(value);
    appendAlternate(value);
  }
  
  public void append(String primary, String alternate)
  {
    appendPrimary(primary);
    appendAlternate(alternate);
  }
  
  public void appendPrimary(String value)
  {
    int addChars = maxLength - primary.length();
    if (value.length() <= addChars) {
      primary.append(value);
    } else {
      primary.append(value.substring(0, addChars));
    }
  }
  
  public void appendAlternate(String value)
  {
    int addChars = maxLength - alternate.length();
    if (value.length() <= addChars) {
      alternate.append(value);
    } else {
      alternate.append(value.substring(0, addChars));
    }
  }
  
  public String getPrimary()
  {
    return primary.toString();
  }
  
  public String getAlternate()
  {
    return alternate.toString();
  }
  
  public boolean isComplete()
  {
    return (primary.length() >= maxLength) && (alternate.length() >= maxLength);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.codec.language.DoubleMetaphone.DoubleMetaphoneResult
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.codec.language;

import org.apache.commons.codec.EncoderException;
import org.apache.commons.codec.StringEncoder;

public class DoubleMetaphone
  implements StringEncoder
{
  private static final String VOWELS = "AEIOUY";
  private static final String[] SILENT_START = { "GN", "KN", "PN", "WR", "PS" };
  private static final String[] L_R_N_M_B_H_F_V_W_SPACE = { "L", "R", "N", "M", "B", "H", "F", "V", "W", " " };
  private static final String[] ES_EP_EB_EL_EY_IB_IL_IN_IE_EI_ER = { "ES", "EP", "EB", "EL", "EY", "IB", "IL", "IN", "IE", "EI", "ER" };
  private static final String[] L_T_K_S_N_M_B_Z = { "L", "T", "K", "S", "N", "M", "B", "Z" };
  protected int maxCodeLen = 4;
  
  public String doubleMetaphone(String value)
  {
    return doubleMetaphone(value, false);
  }
  
  public String doubleMetaphone(String value, boolean alternate)
  {
    value = cleanInput(value);
    if (value == null) {
      return null;
    }
    boolean slavoGermanic = isSlavoGermanic(value);
    int index = isSilentStart(value) ? 1 : 0;
    
    DoubleMetaphoneResult result = new DoubleMetaphoneResult(getMaxCodeLen());
    while ((!result.isComplete()) && (index <= value.length() - 1)) {
      switch (value.charAt(index))
      {
      case 'A': 
      case 'E': 
      case 'I': 
      case 'O': 
      case 'U': 
      case 'Y': 
        index = handleAEIOUY(value, result, index);
        break;
      case 'B': 
        result.append('P');
        index = charAt(value, index + 1) == 'B' ? index + 2 : index + 1;
        break;
      case '�': 
        result.append('S');
        index++;
        break;
      case 'C': 
        index = handleC(value, result, index);
        break;
      case 'D': 
        index = handleD(value, result, index);
        break;
      case 'F': 
        result.append('F');
        index = charAt(value, index + 1) == 'F' ? index + 2 : index + 1;
        break;
      case 'G': 
        index = handleG(value, result, index, slavoGermanic);
        break;
      case 'H': 
        index = handleH(value, result, index);
        break;
      case 'J': 
        index = handleJ(value, result, index, slavoGermanic);
        break;
      case 'K': 
        result.append('K');
        index = charAt(value, index + 1) == 'K' ? index + 2 : index + 1;
        break;
      case 'L': 
        index = handleL(value, result, index);
        break;
      case 'M': 
        result.append('M');
        index = conditionM0(value, index) ? index + 2 : index + 1;
        break;
      case 'N': 
        result.append('N');
        index = charAt(value, index + 1) == 'N' ? index + 2 : index + 1;
        break;
      case '�': 
        result.append('N');
        index++;
        break;
      case 'P': 
        index = handleP(value, result, index);
        break;
      case 'Q': 
        result.append('K');
        index = charAt(value, index + 1) == 'Q' ? index + 2 : index + 1;
        break;
      case 'R': 
        index = handleR(value, result, index, slavoGermanic);
        break;
      case 'S': 
        index = handleS(value, result, index, slavoGermanic);
        break;
      case 'T': 
        index = handleT(value, result, index);
        break;
      case 'V': 
        result.append('F');
        index = charAt(value, index + 1) == 'V' ? index + 2 : index + 1;
        break;
      case 'W': 
        index = handleW(value, result, index);
        break;
      case 'X': 
        index = handleX(value, result, index);
        break;
      case 'Z': 
        index = handleZ(value, result, index, slavoGermanic);
        break;
      default: 
        index++;
      }
    }
    return alternate ? result.getAlternate() : result.getPrimary();
  }
  
  public Object encode(Object obj)
    throws EncoderException
  {
    if (!(obj instanceof String)) {
      throw new EncoderException("DoubleMetaphone encode parameter is not of type String");
    }
    return doubleMetaphone((String)obj);
  }
  
  public String encode(String value)
  {
    return doubleMetaphone(value);
  }
  
  public boolean isDoubleMetaphoneEqual(String value1, String value2)
  {
    return isDoubleMetaphoneEqual(value1, value2, false);
  }
  
  public boolean isDoubleMetaphoneEqual(String value1, String value2, boolean alternate)
  {
    return doubleMetaphone(value1, alternate).equals(doubleMetaphone(value2, alternate));
  }
  
  public int getMaxCodeLen()
  {
    return maxCodeLen;
  }
  
  public void setMaxCodeLen(int maxCodeLen)
  {
    this.maxCodeLen = maxCodeLen;
  }
  
  private int handleAEIOUY(String value, DoubleMetaphoneResult result, int index)
  {
    if (index == 0) {
      result.append('A');
    }
    return index + 1;
  }
  
  private int handleC(String value, DoubleMetaphoneResult result, int index)
  {
    if (conditionC0(value, index))
    {
      result.append('K');
      index += 2;
    }
    else if ((index == 0) && (contains(value, index, 6, "CAESAR")))
    {
      result.append('S');
      index += 2;
    }
    else if (contains(value, index, 2, "CH"))
    {
      index = handleCH(value, result, index);
    }
    else if ((contains(value, index, 2, "CZ")) && (!contains(value, index - 2, 4, "WICZ")))
    {
      result.append('S', 'X');
      index += 2;
    }
    else if (contains(value, index + 1, 3, "CIA"))
    {
      result.append('X');
      index += 3;
    }
    else
    {
      if ((contains(value, index, 2, "CC")) && ((index != 1) || (charAt(value, 0) != 'M'))) {
        return handleCC(value, result, index);
      }
      if (contains(value, index, 2, "CK", "CG", "CQ"))
      {
        result.append('K');
        index += 2;
      }
      else if (contains(value, index, 2, "CI", "CE", "CY"))
      {
        if (contains(value, index, 3, "CIO", "CIE", "CIA")) {
          result.append('S', 'X');
        } else {
          result.append('S');
        }
        index += 2;
      }
      else
      {
        result.append('K');
        if (contains(value, index + 1, 2, " C", " Q", " G")) {
          index += 3;
        } else if ((contains(value, index + 1, 1, "C", "K", "Q")) && (!contains(value, index + 1, 2, "CE", "CI"))) {
          index += 2;
        } else {
          index++;
        }
      }
    }
    return index;
  }
  
  private int handleCC(String value, DoubleMetaphoneResult result, int index)
  {
    if ((contains(value, index + 2, 1, "I", "E", "H")) && (!contains(value, index + 2, 2, "HU")))
    {
      if (((index == 1) && (charAt(value, index - 1) == 'A')) || (contains(value, index - 1, 5, "UCCEE", "UCCES"))) {
        result.append("KS");
      } else {
        result.append('X');
      }
      index += 3;
    }
    else
    {
      result.append('K');
      index += 2;
    }
    return index;
  }
  
  private int handleCH(String value, DoubleMetaphoneResult result, int index)
  {
    if ((index > 0) && (contains(value, index, 4, "CHAE")))
    {
      result.append('K', 'X');
      return index + 2;
    }
    if (conditionCH0(value, index))
    {
      result.append('K');
      return index + 2;
    }
    if (conditionCH1(value, index))
    {
      result.append('K');
      return index + 2;
    }
    if (index > 0)
    {
      if (contains(value, 0, 2, "MC")) {
        result.append('K');
      } else {
        result.append('X', 'K');
      }
    }
    else {
      result.append('X');
    }
    return index + 2;
  }
  
  private int handleD(String value, DoubleMetaphoneResult result, int index)
  {
    if (contains(value, index, 2, "DG"))
    {
      if (contains(value, index + 2, 1, "I", "E", "Y"))
      {
        result.append('J');
        index += 3;
      }
      else
      {
        result.append("TK");
        index += 2;
      }
    }
    else if (contains(value, index, 2, "DT", "DD"))
    {
      result.append('T');
      index += 2;
    }
    else
    {
      result.append('T');
      index++;
    }
    return index;
  }
  
  private int handleG(String value, DoubleMetaphoneResult result, int index, boolean slavoGermanic)
  {
    if (charAt(value, index + 1) == 'H')
    {
      index = handleGH(value, result, index);
    }
    else if (charAt(value, index + 1) == 'N')
    {
      if ((index == 1) && (isVowel(charAt(value, 0))) && (!slavoGermanic)) {
        result.append("KN", "N");
      } else if ((!contains(value, index + 2, 2, "EY")) && (charAt(value, index + 1) != 'Y') && (!slavoGermanic)) {
        result.append("N", "KN");
      } else {
        result.append("KN");
      }
      index += 2;
    }
    else if ((contains(value, index + 1, 2, "LI")) && (!slavoGermanic))
    {
      result.append("KL", "L");
      index += 2;
    }
    else if ((index == 0) && ((charAt(value, index + 1) == 'Y') || (contains(value, index + 1, 2, ES_EP_EB_EL_EY_IB_IL_IN_IE_EI_ER))))
    {
      result.append('K', 'J');
      index += 2;
    }
    else if (((contains(value, index + 1, 2, "ER")) || (charAt(value, index + 1) == 'Y')) && (!contains(value, 0, 6, "DANGER", "RANGER", "MANGER")) && (!contains(value, index - 1, 1, "E", "I")) && (!contains(value, index - 1, 3, "RGY", "OGY")))
    {
      result.append('K', 'J');
      index += 2;
    }
    else if ((contains(value, index + 1, 1, "E", "I", "Y")) || (contains(value, index - 1, 4, "AGGI", "OGGI")))
    {
      if ((contains(value, 0, 4, "VAN ", "VON ")) || (contains(value, 0, 3, "SCH")) || (contains(value, index + 1, 2, "ET"))) {
        result.append('K');
      } else if (contains(value, index + 1, 4, "IER")) {
        result.append('J');
      } else {
        result.append('J', 'K');
      }
      index += 2;
    }
    else if (charAt(value, index + 1) == 'G')
    {
      index += 2;
      result.append('K');
    }
    else
    {
      index++;
      result.append('K');
    }
    return index;
  }
  
  private int handleGH(String value, DoubleMetaphoneResult result, int index)
  {
    if ((index > 0) && (!isVowel(charAt(value, index - 1))))
    {
      result.append('K');
      index += 2;
    }
    else if (index == 0)
    {
      if (charAt(value, index + 2) == 'I') {
        result.append('J');
      } else {
        result.append('K');
      }
      index += 2;
    }
    else if (((index > 1) && (contains(value, index - 2, 1, "B", "H", "D"))) || ((index > 2) && (contains(value, index - 3, 1, "B", "H", "D"))) || ((index > 3) && (contains(value, index - 4, 1, "B", "H"))))
    {
      index += 2;
    }
    else
    {
      if ((index > 2) && (charAt(value, index - 1) == 'U') && (contains(value, index - 3, 1, "C", "G", "L", "R", "T"))) {
        result.append('F');
      } else if ((index > 0) && (charAt(value, index - 1) != 'I')) {
        result.append('K');
      }
      index += 2;
    }
    return index;
  }
  
  private int handleH(String value, DoubleMetaphoneResult result, int index)
  {
    if (((index == 0) || (isVowel(charAt(value, index - 1)))) && (isVowel(charAt(value, index + 1))))
    {
      result.append('H');
      index += 2;
    }
    else
    {
      index++;
    }
    return index;
  }
  
  private int handleJ(String value, DoubleMetaphoneResult result, int index, boolean slavoGermanic)
  {
    if ((contains(value, index, 4, "JOSE")) || (contains(value, 0, 4, "SAN ")))
    {
      if (((index == 0) && (charAt(value, index + 4) == ' ')) || (value.length() == 4) || (contains(value, 0, 4, "SAN "))) {
        result.append('H');
      } else {
        result.append('J', 'H');
      }
      index++;
    }
    else
    {
      if ((index == 0) && (!contains(value, index, 4, "JOSE"))) {
        result.append('J', 'A');
      } else if ((isVowel(charAt(value, index - 1))) && (!slavoGermanic) && ((charAt(value, index + 1) == 'A') || (charAt(value, index + 1) == 'O'))) {
        result.append('J', 'H');
      } else if (index == value.length() - 1) {
        result.append('J', ' ');
      } else if ((!contains(value, index + 1, 1, L_T_K_S_N_M_B_Z)) && (!contains(value, index - 1, 1, "S", "K", "L"))) {
        result.append('J');
      }
      if (charAt(value, index + 1) == 'J') {
        index += 2;
      } else {
        index++;
      }
    }
    return index;
  }
  
  private int handleL(String value, DoubleMetaphoneResult result, int index)
  {
    result.append('L');
    if (charAt(value, index + 1) == 'L')
    {
      if (conditionL0(value, index)) {
        result.appendAlternate(' ');
      }
      index += 2;
    }
    else
    {
      index++;
    }
    return index;
  }
  
  private int handleP(String value, DoubleMetaphoneResult result, int index)
  {
    if (charAt(value, index + 1) == 'H')
    {
      result.append('F');
      index += 2;
    }
    else
    {
      result.append('P');
      index = contains(value, index + 1, 1, "P", "B") ? index + 2 : index + 1;
    }
    return index;
  }
  
  private int handleR(String value, DoubleMetaphoneResult result, int index, boolean slavoGermanic)
  {
    if ((index == value.length() - 1) && (!slavoGermanic) && (contains(value, index - 2, 2, "IE")) && (!contains(value, index - 4, 2, "ME", "MA"))) {
      result.appendAlternate('R');
    } else {
      result.append('R');
    }
    return charAt(value, index + 1) == 'R' ? index + 2 : index + 1;
  }
  
  private int handleS(String value, DoubleMetaphoneResult result, int index, boolean slavoGermanic)
  {
    if (contains(value, index - 1, 3, "ISL", "YSL"))
    {
      index++;
    }
    else if ((index == 0) && (contains(value, index, 5, "SUGAR")))
    {
      result.append('X', 'S');
      index++;
    }
    else if (contains(value, index, 2, "SH"))
    {
      if (contains(value, index + 1, 4, "HEIM", "HOEK", "HOLM", "HOLZ")) {
        result.append('S');
      } else {
        result.append('X');
      }
      index += 2;
    }
    else if ((contains(value, index, 3, "SIO", "SIA")) || (contains(value, index, 4, "SIAN")))
    {
      if (slavoGermanic) {
        result.append('S');
      } else {
        result.append('S', 'X');
      }
      index += 3;
    }
    else if (((index == 0) && (contains(value, index + 1, 1, "M", "N", "L", "W"))) || (contains(value, index + 1, 1, "Z")))
    {
      result.append('S', 'X');
      index = contains(value, index + 1, 1, "Z") ? index + 2 : index + 1;
    }
    else if (contains(value, index, 2, "SC"))
    {
      index = handleSC(value, result, index);
    }
    else
    {
      if ((index == value.length() - 1) && (contains(value, index - 2, 2, "AI", "OI"))) {
        result.appendAlternate('S');
      } else {
        result.append('S');
      }
      index = contains(value, index + 1, 1, "S", "Z") ? index + 2 : index + 1;
    }
    return index;
  }
  
  private int handleSC(String value, DoubleMetaphoneResult result, int index)
  {
    if (charAt(value, index + 2) == 'H')
    {
      if (contains(value, index + 3, 2, "OO", "ER", "EN", "UY", "ED", "EM"))
      {
        if (contains(value, index + 3, 2, "ER", "EN")) {
          result.append("X", "SK");
        } else {
          result.append("SK");
        }
      }
      else if ((index == 0) && (!isVowel(charAt(value, 3))) && (charAt(value, 3) != 'W')) {
        result.append('X', 'S');
      } else {
        result.append('X');
      }
    }
    else if (contains(value, index + 2, 1, "I", "E", "Y")) {
      result.append('S');
    } else {
      result.append("SK");
    }
    return index + 3;
  }
  
  private int handleT(String value, DoubleMetaphoneResult result, int index)
  {
    if (contains(value, index, 4, "TION"))
    {
      result.append('X');
      index += 3;
    }
    else if (contains(value, index, 3, "TIA", "TCH"))
    {
      result.append('X');
      index += 3;
    }
    else if ((contains(value, index, 2, "TH")) || (contains(value, index, 3, "TTH")))
    {
      if ((contains(value, index + 2, 2, "OM", "AM")) || (contains(value, 0, 4, "VAN ", "VON ")) || (contains(value, 0, 3, "SCH"))) {
        result.append('T');
      } else {
        result.append('0', 'T');
      }
      index += 2;
    }
    else
    {
      result.append('T');
      index = contains(value, index + 1, 1, "T", "D") ? index + 2 : index + 1;
    }
    return index;
  }
  
  private int handleW(String value, DoubleMetaphoneResult result, int index)
  {
    if (contains(value, index, 2, "WR"))
    {
      result.append('R');
      index += 2;
    }
    else if ((index == 0) && ((isVowel(charAt(value, index + 1))) || (contains(value, index, 2, "WH"))))
    {
      if (isVowel(charAt(value, index + 1))) {
        result.append('A', 'F');
      } else {
        result.append('A');
      }
      index++;
    }
    else if (((index == value.length() - 1) && (isVowel(charAt(value, index - 1)))) || (contains(value, index - 1, 5, "EWSKI", "EWSKY", "OWSKI", "OWSKY")) || (contains(value, 0, 3, "SCH")))
    {
      result.appendAlternate('F');
      index++;
    }
    else if (contains(value, index, 4, "WICZ", "WITZ"))
    {
      result.append("TS", "FX");
      index += 4;
    }
    else
    {
      index++;
    }
    return index;
  }
  
  priva
1 2 3

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd