### Question:
ProtoUtils { public static <M extends MessageLiteOrBuilder> List<M> filter(List<M> objs, Predicate<M> filter) { checkNotNull(filter); for (int i = 0; i < objs.size(); ++i) { if (!filter.test(objs.get(i))) { return filterFrom(objs, filter, i); } } return objs; } private  ProtoUtils(); @SuppressWarnings("unchecked") static O built(@Nullable I msg); @SuppressWarnings("unchecked") static O builder(
      @Nullable I msg); static boolean update(
      Iterable<B> objs, Function<B, Boolean> updater); static List<M> filter(List<M> objs, Predicate<M> filter); @Nullable static M filter(
      M msg, boolean clearEmpty, Predicate<FieldDescriptor> filter); static final Predicate<FieldDescriptor> NOT_EXTENSION; }### Answer:
@Test public void testFilter() { Test1 test1 = Test1.newBuilder().setTest1("test1").build(); Test2 test2 = Test2.newBuilder().setTest2("test2").build(); BidRequest reqExt = BidRequest.newBuilder() .setId("0") .addImp(Imp.newBuilder() .setId("1") .setBanner(Banner.newBuilder() .setExtension(TestExt.testBanner, test1))) .setExtension(TestExt.testRequest1, test1) .setExtension(TestExt.testRequest2, test2) .build(); assertThat(ProtoUtils.filter(reqExt, true, fd -> true)) .isSameInstanceAs(reqExt); assertThat(ProtoUtils.filter(reqExt, true, fd -> false)).isNull(); assertThat(ProtoUtils.filter(reqExt, false, fd -> false)) .isSameInstanceAs(BidRequest.getDefaultInstance()); BidRequest reqPlainClear = BidRequest.newBuilder() .setId("0") .addImp(Imp.newBuilder().setId("1")) .build(); assertThat(ProtoUtils.filter(reqExt, true, ProtoUtils.NOT_EXTENSION)).isEqualTo(reqPlainClear); BidRequest reqPlainNoClear = BidRequest.newBuilder() .setId("0") .addImp(Imp.newBuilder().setId("1") .setBanner(Banner.newBuilder())) .build(); assertThat(ProtoUtils.filter(reqExt, false, ProtoUtils.NOT_EXTENSION)) .isEqualTo(reqPlainNoClear); BidRequest reqExtNoImp = reqExt.toBuilder().clearImp().build(); assertThat(ProtoUtils.filter(reqExt, false, fd -> !"imp".equals(fd.getName()))) .isEqualTo(reqExtNoImp); BidRequest reqDiff = reqPlainClear.toBuilder().setId("1").build(); ImmutableList<BidRequest> list = ImmutableList.of(reqPlainClear, reqDiff); assertThat(ProtoUtils.filter(list, req -> "0".equals(req.getId()))) .containsExactly(reqPlainClear); assertThat(ProtoUtils.filter(list, req -> "0".equals(req.getId()))) .containsExactly(reqPlainClear); assertThat(ProtoUtils.filter(list, req -> true)).isSameInstanceAs(list); assertThat(ProtoUtils.filter(list, req -> false)).isEmpty(); }