public class PersonClassExtractor extends ClassExtractor { @Override public Class<?> extractClassFromRow(Record databaseRow, Session session) { if (databaseRow.containsKey("CLIENT_SPECIFIC")) { return Client.class; } else if (databaseRow.containsKey("AFFILIATE_SPECIFIC")) { return Affiliate.class; } else { return Person.class; // this should never happen } } }
/** * Returns the {@code String} value associated with the given key, or * {@code defaultValue} if the key does not exist. * * @param key The key of the value being retrieved. * @param defaultValue The value to return if the key does not exist. * @return The value associated with the given key, or {@code defaultValue} * if the key does not exist. */ String getString(String key, String defaultValue) { if (!containsKey(key)) return defaultValue; return get(key).toString(); }
/** {@inheritDoc} */ public boolean containsKey(Object key) { return getContent().containsKey(key); }
/** * Returns the {@code String[]} value associated with the given key, or * {@code defaultValue} if the key does not exist. * * @param key The key of the value being retrieved. * @param defaultValue The value to return if the key does not exist. * @return The value associated with the given key, or {@code defaultValue} * if the key does not exist. */ String[] getStringArray(String key, String[] defaultValue) { if (!containsKey(key)) return defaultValue; return getStringArray(key); }
/** * Returns the value associated with the given key, or {@code defaultValue} * if the key does not exist, cast to the given type parameter. * * @param key The key of the value being retrieved. * @param defaultValue The value to return if the key does not exist. * @param <T> The type to cast the return value to. * @return The value associated with the given key, or {@code defautlValue} * if the key does not exist. */ <T> T getValue(String key, T defaultValue) { if (!containsKey(key)) return defaultValue; return (T)get(key); } }
/** * Returns the {@code Boolean} value associated with the given key, or the * {@code defaultValue} if the key does not exist. * * @param key The key of the value being retrieved. * @param defaultValue The value to return if the key does not exist. * @return The value associated with the given key, or {@code defaultValue} * if the key does not exist. */ boolean getBoolean(String key, boolean defaultValue) { if (!containsKey(key)) return defaultValue; return Value.toBoolean(getString(key)); }
/** * Returns the {@code Date} value associated with the given key, or * {@code defaultValue} if the key does not exist. * * @param key The key of the value being retrieved. * @param defaultValue The value to return if the key does not exist. * @return The value associated with the given key, or {@code defaultValue} * if the key does not exist. */ Date getDate(String key, Date defaultValue) { if (!containsKey(key)) return defaultValue; return Value.toDate(getString(key)); }
/** * Returns the {@code long} byte count value associated with the given key, * or {@code defaultValue} if the key does not exist. * * @param key The key of the value being retrieved. * @param defaultValue The value to return if the key does not exist. * @return The value associated with the given key, or {@code defaultValue} * if the key does not exist. */ long getByteCount(String key, long defaultValue) { if (!containsKey(key)) return defaultValue; return Value.toByteCount(getString(key)); }
/** * Returns the {@code int} value associated with the given key, or * {@code defaultValue} if the key does not exist. * * @param key The key of the value being retrieved. * @param defaultValue The value to return if the key does not exist. * @return The value associated with the given key, or {@code defaultValue} * if the key does not exist. */ int getInteger(String key, int defaultValue) { if (!containsKey(key)) return defaultValue; return Value.toInteger(getString(key)); }
/** * Returns the {@code long} value associated with the given key, or * {@code defaultValue} if the key does not exist. * * @param key The key of the value being retrieved. * @param defaultValue The value to return if the key does not exist. * @return The value associated with the given key, or {@code defaultValue} * if the key does not exist. */ long getLong(String key, int defaultValue) { if (!containsKey(key)) return defaultValue; return Value.toLong(getString(key)); }
/** * Returns a date value associated with the specified key. Date values can * be converted from standard UTC time formats. * * @param key The key to look up. * @return The date value associated with the specified key. */ Date getDate(String key) { if (toUpdate.containsKey(key)) return Value.toDate(toUpdate.get(key).toString()); if (getContent().containsKey(key)) { return getContent().getDate(key); } else { return null; } }