From 73c111c20ba1578f75b524e682f6a68f930e5b8a Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Thu, 5 Jan 2012 20:34:14 +0000 Subject: [PATCH] Update to Guava 11, change MapMaker/ConcurrentMap -> CacheBuilder/LoadingCache. --- pom.xml | 2 +- .../com/samskivert/depot/impl/DepotUtil.java | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 75197aa..04ff48a 100644 --- a/pom.xml +++ b/pom.xml @@ -51,7 +51,7 @@ com.google.guava guava - 10.0 + 11.0 compile diff --git a/src/main/java/com/samskivert/depot/impl/DepotUtil.java b/src/main/java/com/samskivert/depot/impl/DepotUtil.java index 6afd1ef..a50469b 100644 --- a/src/main/java/com/samskivert/depot/impl/DepotUtil.java +++ b/src/main/java/com/samskivert/depot/impl/DepotUtil.java @@ -6,11 +6,11 @@ package com.samskivert.depot.impl; import java.lang.reflect.Field; import java.util.List; -import java.util.concurrent.ConcurrentMap; -import com.google.common.base.Function; +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; import com.google.common.collect.Lists; -import com.google.common.collect.MapMaker; import com.samskivert.depot.PersistentRecord; import com.samskivert.depot.annotation.Id; @@ -27,7 +27,7 @@ public class DepotUtil */ public static ColumnExp[] getKeyFields (Class pClass) { - return _keyFields.get(pClass); + return _keyFields.getUnchecked(pClass); } /** @@ -40,7 +40,7 @@ public class DepotUtil { // TODO: Checks? For example: Validate all exps from same class? // Make a defensive copy of the array? Hide this method from public consumption? - _keyFields.putIfAbsent(fields[0].getPersistentClass(), fields); + _keyFields.asMap().putIfAbsent(fields[0].getPersistentClass(), fields); } /** @@ -53,13 +53,13 @@ public class DepotUtil /** A (never expiring) cache of primary key field names for all persistent classes (of which * there are merely dozens, so we don't need to worry about expiring). */ - protected static ConcurrentMap, ColumnExp[]> _keyFields = - new MapMaker() + protected static LoadingCache, ColumnExp[]> _keyFields = + CacheBuilder.newBuilder() // newly generated PersistentRecord classes will register their key fields via // registerKeyFields, which will return an ordering determined at genrecord time. // We fall back to computing the fields at runtime for older PersistentRecord classes. - .makeComputingMap(new Function, ColumnExp[]>() { - public ColumnExp[] apply (Class pClass) { + .build(new CacheLoader, ColumnExp[]>() { + public ColumnExp[] load (Class pClass) { List> kflist = Lists.newArrayList(); for (Field field : pClass.getFields()) { // look for @Id fields