From fb6d6df3eaa139e75a3ffa42f1a0ccbad375bc17 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Mon, 13 Jul 2009 03:09:51 +0000 Subject: [PATCH] Added Key.toInt() which returns a function that can be used to extract the integer primary key from a Key for records whose primary key is a single integer. --- src/java/com/samskivert/depot/Key.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/java/com/samskivert/depot/Key.java b/src/java/com/samskivert/depot/Key.java index 42afafe..d8cde03 100644 --- a/src/java/com/samskivert/depot/Key.java +++ b/src/java/com/samskivert/depot/Key.java @@ -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 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 Function,Integer> toInt () + { + return new Function,Integer>() { + public Integer apply (Key key) { + return (Integer)key.getValues()[0]; + } + }; + } + /** * Constructs a new multi-column {@code Key} with the given values. */