diff --git a/src/java/com/samskivert/depot/Key.java b/src/java/com/samskivert/depot/Key.java index 818ced6..7da1ba4 100644 --- a/src/java/com/samskivert/depot/Key.java +++ b/src/java/com/samskivert/depot/Key.java @@ -100,14 +100,25 @@ public class Key extends WhereClause } /** - * Extracts an integer key from a record's {@link Key}. This should only be used on records - * whose primary key is a single integer. + * Returns a function that extracts an integer from a record's {@link Key}. This should only be + * used on records whose primary key is a single integer. */ - public static Function,Integer> toInt () + public static Function, Integer> toInt () { - return new Function,Integer>() { - public Integer apply (Key key) { - return (Integer)key.getValues()[0]; + return extract(0); + } + + /** + * Returns a function that extracts an element key from a record's {@link Key}. + * + * @param index the index in the key of the element to be extracted. + */ + public static Function, E> extract (final int index) + { + return new Function, E>() { + public E apply (Key key) { + @SuppressWarnings("unchecked") E value = (E)key.getValues()[index]; + return value; } }; }