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
This commit is contained in:
Ray Greenwell
2008-09-16 22:32:48 +00:00
parent 6294b2e955
commit 1f3b968a00
+6 -6
View File
@@ -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<Field> fieldList = Lists.newArrayList();
ClassUtil.getFields(target, fieldList);
_isStreamableFieldPred.filter(fieldList);
_fields = fieldList.toArray(new Field[fieldList.size()]);
List<Field> 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<Field> _isStreamableFieldPred = new Predicate<Field>() {
@Override public boolean isMatch (Field obj) {
@Override public boolean apply (Field obj) {
return (obj.getAnnotation(NotStreamable.class) == null);
}
};