Added Key.toInt() which returns a function that can be used to extract the

integer primary key from a Key<T> for records whose primary key is a single
integer.
This commit is contained in:
Michael Bayne
2009-07-13 03:09:51 +00:00
parent 8be8037578
commit fb6d6df3ea
+14
View File
@@ -25,6 +25,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import com.google.common.base.Function;
import com.google.common.collect.Maps;
import com.samskivert.depot.clause.WhereClause;
@@ -98,6 +99,19 @@ public class Key<T extends PersistentRecord> extends WhereClause
new Comparable[] { val1, val2, val3 });
}
/**
* Extracts an integer key from a record's {@link Key}. This should only be used on records
* whose primary key is a single integer.
*/
public static <T extends PersistentRecord> Function<Key<T>,Integer> toInt ()
{
return new Function<Key<T>,Integer>() {
public Integer apply (Key<T> key) {
return (Integer)key.getValues()[0];
}
};
}
/**
* Constructs a new multi-column {@code Key} with the given values.
*/