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:
@@ -25,6 +25,7 @@ import java.util.Arrays;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
import com.samskivert.depot.clause.WhereClause;
|
import com.samskivert.depot.clause.WhereClause;
|
||||||
@@ -98,6 +99,19 @@ public class Key<T extends PersistentRecord> extends WhereClause
|
|||||||
new Comparable[] { val1, val2, val3 });
|
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.
|
* Constructs a new multi-column {@code Key} with the given values.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user