@Override public Object encode(final Object object) throws EncoderException { if (!(object instanceof String)) { throw new EncoderException("This method's parameter was expected to be of the type " + String.class.getName() + ". But actually it was of the type " + object.getClass().getName() + "."); } return encode((String) object); }
@Override public Object encode(final Object source) throws EncoderException { if (!(source instanceof String)) { throw new EncoderException("BeiderMorseEncoder encode parameter is not of type String"); } return encode((String) source); }
/** * Encode the value using DoubleMetaphone. It will only work if * <code>obj</code> is a <code>String</code> (like <code>Metaphone</code>). * * @param obj Object to encode (should be of type String) * @return An encoded Object (will be of type String) * @throws EncoderException encode parameter is not of type String */ @Override public Object encode(final Object obj) throws EncoderException { if (!(obj instanceof String)) { throw new EncoderException("DoubleMetaphone encode parameter is not of type String"); } return doubleMetaphone((String) obj); }
/** * Converts an array of raw binary data into an array of ASCII 0 and 1 chars. * * @param raw * the raw binary data to convert * @return 0 and 1 ASCII character chars one for each bit of the argument * @throws EncoderException * if the argument is not a byte[] * @see org.apache.commons.codec.Encoder#encode(Object) */ @Override public Object encode(final Object raw) throws EncoderException { if (!(raw instanceof byte[])) { throw new EncoderException("argument not a byte array"); } return toAsciiChars((byte[]) raw); }
/** * Encodes an Object using the Base-N algorithm. This method is provided in order to satisfy the requirements of * the Encoder interface, and will throw an EncoderException if the supplied object is not of type byte[]. * * @param obj * Object to encode * @return An object (of type byte[]) containing the Base-N encoded data which corresponds to the byte[] supplied. * @throws EncoderException * if the parameter supplied is not of type byte[] */ @Override public Object encode(final Object obj) throws EncoderException { if (!(obj instanceof byte[])) { throw new EncoderException("Parameter supplied to Base-N encode is not a byte[]"); } return encode((byte[]) obj); }
/** * Encodes an Object using the caverphone algorithm. This method is provided in order to satisfy the requirements of * the Encoder interface, and will throw an EncoderException if the supplied object is not of type java.lang.String. * * @param obj * Object to encode * @return An object (or type java.lang.String) containing the caverphone code which corresponds to the String * supplied. * @throws EncoderException * if the parameter supplied is not of type java.lang.String */ @Override public Object encode(final Object obj) throws EncoderException { if (!(obj instanceof String)) { throw new EncoderException("Parameter supplied to Caverphone encode is not of type java.lang.String"); } return this.caverphone((String) obj); }
/** * Encodes an Object using the caverphone algorithm. This method is provided in order to satisfy the requirements of * the Encoder interface, and will throw an EncoderException if the supplied object is not of type java.lang.String. * * @param source * Object to encode * @return An object (or type java.lang.String) containing the caverphone code which corresponds to the String * supplied. * @throws EncoderException * if the parameter supplied is not of type java.lang.String */ @Override public Object encode(final Object source) throws EncoderException { if (!(source instanceof String)) { throw new EncoderException("Parameter supplied to Caverphone encode is not of type java.lang.String"); } return this.encode((String) source); }
/** * Encodes an Object using the Match Rating Approach algorithm. Method is here to satisfy the requirements of the * Encoder interface Throws an EncoderException if input object is not of type java.lang.String. * * @param pObject * Object to encode * @return An object (or type java.lang.String) containing the Match Rating Approach code which corresponds to the * String supplied. * @throws EncoderException * if the parameter supplied is not of type java.lang.String */ @Override public final Object encode(final Object pObject) throws EncoderException { if (!(pObject instanceof String)) { throw new EncoderException( "Parameter supplied to Match Rating Approach encoder is not of type java.lang.String"); } return encode((String) pObject); }
/** * Encodes an Object using the metaphone algorithm. This method * is provided in order to satisfy the requirements of the * Encoder interface, and will throw an EncoderException if the * supplied object is not of type java.lang.String. * * @param obj Object to encode * @return An object (or type java.lang.String) containing the * metaphone code which corresponds to the String supplied. * @throws EncoderException if the parameter supplied is not * of type java.lang.String */ @Override public Object encode(final Object obj) throws EncoderException { if (!(obj instanceof String)) { throw new EncoderException("Parameter supplied to Metaphone encode is not of type java.lang.String"); } return metaphone((String) obj); }
/** * Encodes an Object using the soundex algorithm. This method is provided in order to satisfy the requirements of * the Encoder interface, and will throw an EncoderException if the supplied object is not of type java.lang.String. * * @param obj * Object to encode * @return An object (or type java.lang.String) containing the soundex code which corresponds to the String * supplied. * @throws EncoderException * if the parameter supplied is not of type java.lang.String * @throws IllegalArgumentException * if a character is not mapped */ @Override public Object encode(final Object obj) throws EncoderException { if (!(obj instanceof String)) { throw new EncoderException("Parameter supplied to Soundex encode is not of type java.lang.String"); } return soundex((String) obj); }
/** * Encodes an Object using the refined soundex algorithm. This method is * provided in order to satisfy the requirements of the Encoder interface, * and will throw an EncoderException if the supplied object is not of type * java.lang.String. * * @param obj * Object to encode * @return An object (or type java.lang.String) containing the refined * soundex code which corresponds to the String supplied. * @throws EncoderException * if the parameter supplied is not of type java.lang.String */ @Override public Object encode(final Object obj) throws EncoderException { if (!(obj instanceof String)) { throw new EncoderException("Parameter supplied to RefinedSoundex encode is not of type java.lang.String"); } return soundex((String) obj); }
/** * Encodes an Object using the NYSIIS algorithm. This method is provided in order to satisfy the requirements of the * Encoder interface, and will throw an {@link EncoderException} if the supplied object is not of type * {@link String}. * * @param obj * Object to encode * @return An object (or a {@link String}) containing the NYSIIS code which corresponds to the given String. * @throws EncoderException * if the parameter supplied is not of a {@link String} * @throws IllegalArgumentException * if a character is not mapped */ @Override public Object encode(final Object obj) throws EncoderException { if (!(obj instanceof String)) { throw new EncoderException("Parameter supplied to Nysiis encode is not of type java.lang.String"); } return this.nysiis((String) obj); }
/** * Encodes an object into its Base64 form using the default charset. Unsafe characters are escaped. * * @param value * object to convert to Base64 form * @return Base64 object * @throws EncoderException * thrown if a failure condition is encountered during the encoding process. */ @Override public Object encode(final Object value) throws EncoderException { if (value == null) { return null; } else if (value instanceof String) { return encode((String) value); } else { throw new EncoderException("Objects of type " + value.getClass().getName() + " cannot be encoded using BCodec"); } }
/** * Encodes an object into its quoted-printable form using the default charset. Unsafe characters are escaped. * * @param obj * object to convert to quoted-printable form * @return quoted-printable object * @throws EncoderException * thrown if a failure condition is encountered during the encoding process. */ @Override public Object encode(final Object obj) throws EncoderException { if (obj == null) { return null; } else if (obj instanceof String) { return encode((String) obj); } else { throw new EncoderException("Objects of type " + obj.getClass().getName() + " cannot be encoded using Q codec"); } }
/** * Encodes a string into its Base64 form using the specified charset. Unsafe characters are escaped. * * @param value * string to convert to Base64 form * @param charset * the charset for <code>value</code> * @return Base64 string * @throws EncoderException * thrown if a failure condition is encountered during the encoding process. */ public String encode(final String value, final String charset) throws EncoderException { if (value == null) { return null; } try { return this.encodeText(value, charset); } catch (final UnsupportedEncodingException e) { throw new EncoderException(e.getMessage(), e); } }
/** * Encodes an object into its URL safe form. Unsafe characters are escaped. * * @param obj * string to convert to a URL safe form * @return URL safe object * @throws EncoderException * Thrown if URL encoding is not applicable to objects of this type or if encoding is unsuccessful */ @Override public Object encode(final Object obj) throws EncoderException { if (obj == null) { return null; } else if (obj instanceof byte[]) { return encode((byte[])obj); } else if (obj instanceof String) { return encode((String)obj); } else { throw new EncoderException("Objects of type " + obj.getClass().getName() + " cannot be URL encoded"); } }
@Test public void testConstructorThrowable() { final EncoderException e = new EncoderException(t); assertEquals(t.getClass().getName(), e.getMessage()); assertEquals(t, e.getCause()); }
@Test public void testConstructorString() { final EncoderException e = new EncoderException(MSG); assertEquals(MSG, e.getMessage()); assertNull(e.getCause()); }
@Test public void testConstructor0() { final EncoderException e = new EncoderException(); assertNull(e.getMessage()); assertNull(e.getCause()); }
@Test public void testConstructorStringThrowable() { final EncoderException e = new EncoderException(MSG, t); assertEquals(MSG, e.getMessage()); assertEquals(t, e.getCause()); }