Package com.google.openrtb.util
Class ProtoUtils
- java.lang.Object
-
- com.google.openrtb.util.ProtoUtils
-
public final class ProtoUtils extends Object
Some conveniences for protoc-generated classes.
-
-
Field Summary
Fields Modifier and Type Field Description static Predicate<com.google.protobuf.Descriptors.FieldDescriptor>NOT_EXTENSION
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <I extends com.google.protobuf.MessageLiteOrBuilder,O extends com.google.protobuf.MessageLite.Builder>
Obuilder(I msg)Given a message-or-builder, return a builder, invoking toBuilder() if necessary.static <I extends com.google.protobuf.MessageLiteOrBuilder,O extends com.google.protobuf.MessageLite>
Obuilt(I msg)Given a message-or-builder, returns a message, invoking the builder if necessary.static <M extends com.google.protobuf.MessageLiteOrBuilder>
List<M>filter(List<M> objs, Predicate<M> filter)Runs a filter through a sequence of objects.static <M extends com.google.protobuf.Message>
Mfilter(M msg, boolean clearEmpty, Predicate<com.google.protobuf.Descriptors.FieldDescriptor> filter)Returns a copy of aMessagethat contains only fields that pass a filter.protected static booleanfilterValue(boolean clearEmpty, Predicate<com.google.protobuf.Descriptors.FieldDescriptor> filter, com.google.protobuf.Message.Builder builder, Map.Entry<com.google.protobuf.Descriptors.FieldDescriptor,Object> entry)static <B extends com.google.protobuf.MessageLite.Builder>
booleanupdate(Iterable<B> objs, Function<B,Boolean> updater)Updates every builder from a sequence.
-
-
-
Field Detail
-
NOT_EXTENSION
public static final Predicate<com.google.protobuf.Descriptors.FieldDescriptor> NOT_EXTENSION
-
-
Method Detail
-
built
public static <I extends com.google.protobuf.MessageLiteOrBuilder,O extends com.google.protobuf.MessageLite> O built(@Nullable I msg)
Given a message-or-builder, returns a message, invoking the builder if necessary.
-
builder
public static <I extends com.google.protobuf.MessageLiteOrBuilder,O extends com.google.protobuf.MessageLite.Builder> O builder(@Nullable I msg)
Given a message-or-builder, return a builder, invoking toBuilder() if necessary.
-
update
public static <B extends com.google.protobuf.MessageLite.Builder> boolean update(Iterable<B> objs, Function<B,Boolean> updater)
Updates every builder from a sequence.- Parameters:
objs- List of builders to updateupdater- Update function. Theapply()method can decide or not to update each object, and it's expected to returntrueif some update was made- Returns:
trueif at least one object was updated
-
filter
public static <M extends com.google.protobuf.MessageLiteOrBuilder> List<M> filter(List<M> objs, Predicate<M> filter)
Runs a filter through a sequence of objects.- Parameters:
objs- Message-or-builder objectsfilter- Function that returnstrueto retain an object,falseto discard- Returns:
- Retained objects. If some elements are retained and others are discarded,
this will be a new, mutable
Listthat contains only the retained elements. If all elements are retained, returns the same, unmodified input sequence. If all elements are discarded, returns an immutable, empty sequence
-
filter
@Nullable public static <M extends com.google.protobuf.Message> M filter(M msg, boolean clearEmpty, Predicate<com.google.protobuf.Descriptors.FieldDescriptor> filter)
Returns a copy of aMessagethat contains only fields that pass a filter. This will be executed recursively for fields which are child messages.- Parameters:
msg- Message objectclearEmpty-truewill causenullto be returned if all fields frommsgare removed;falsewill return an "empty" message in that casefilter- Function that returnstrueto retain a field,falseto discard- Returns:
- Message with the retained fieldsfrom
msg. If some fields are retained and others discarded, returns a new message object. If all fields are retained, returns the samemsgobject. If all fields are discarded, returnsnullifclearEmpty==trueor a default instance ofmsg's message type ifclearEmpty==false
-
-