From 1f3b968a009b01457c785f060bbf8eee6aa344fe Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Tue, 16 Sep 2008 22:32:48 +0000 Subject: [PATCH] Use google's Predicate class instead of samskivert's. - It's probably "more" standard, and maybe when they finally add Predicate to java.util, it will be based on google's implementation. - Unfortunately this is a little less efficient at runtime. The samskivert Predicate can filter into a new Collection that knows its size, google's code just returns an Iterable that is a *view* on the Iterable passed in, so it doesn't know how many elements are in it. When we copy it into an array, a List is first created to receive all the filtered elements from this view, then that List is turned into an array. Oh well, it's less lines of code here in this class thanks to Google's fun libs. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5375 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- src/java/com/threerings/io/Streamer.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/java/com/threerings/io/Streamer.java b/src/java/com/threerings/io/Streamer.java index c6e151ccc..286754842 100644 --- a/src/java/com/threerings/io/Streamer.java +++ b/src/java/com/threerings/io/Streamer.java @@ -36,10 +36,11 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.samskivert.util.ClassUtil; -import com.samskivert.util.Predicate; import static com.threerings.NaryaLog.log; @@ -461,10 +462,9 @@ public class Streamer } // reflect on all the object's fields and remove all marked with NotStreamable - List fieldList = Lists.newArrayList(); - ClassUtil.getFields(target, fieldList); - _isStreamableFieldPred.filter(fieldList); - _fields = fieldList.toArray(new Field[fieldList.size()]); + List fields = Lists.newArrayList(); + ClassUtil.getFields(target, fields); + _fields = Iterables.newArray(Iterables.filter(fields, _isStreamableFieldPred), Field.class); int fcount = _fields.length; // obtain field marshallers for all of our fields @@ -521,7 +521,7 @@ public class Streamer /** A simple predicate to filter "NotStreamable" members from a Streamable object's fields. */ protected static final Predicate _isStreamableFieldPred = new Predicate() { - @Override public boolean isMatch (Field obj) { + @Override public boolean apply (Field obj) { return (obj.getAnnotation(NotStreamable.class) == null); } };