Package com.google.openrtb.util
Class OpenRtbUtils
- java.lang.Object
-
- com.google.openrtb.util.OpenRtbUtils
-
public final class OpenRtbUtils extends Object
Utilities to manipulateOpenRtb.BidRequestandOpenRtb.BidResponse.Builder.
-
-
Field Summary
Fields Modifier and Type Field Description static Predicate<OpenRtb.BidRequest.Imp>IMP_ALLSpecial value for forimpFilterparameter of some methods, will be more efficient than an equivalentimp -> truepredicate.static Predicate<OpenRtb.BidRequest.Imp>IMP_NONESpecial value for forimpFilterparameter of some methods, will be more efficient than an equivalentimp -> falsepredicate.static StringSEAT_ANYSpecial value for theseatparameter of some methods.
-
Constructor Summary
Constructors Constructor Description OpenRtbUtils()
-
Method Summary
-
-
-
Field Detail
-
SEAT_ANY
public static final String SEAT_ANY
Special value for theseatparameter of some methods. Notice that you can't pass any string with the same value, you need to pass a reference to this unique object.- See Also:
- Constant Field Values
-
IMP_NONE
public static final Predicate<OpenRtb.BidRequest.Imp> IMP_NONE
Special value for forimpFilterparameter of some methods, will be more efficient than an equivalentimp -> falsepredicate.
-
IMP_ALL
public static final Predicate<OpenRtb.BidRequest.Imp> IMP_ALL
Special value for forimpFilterparameter of some methods, will be more efficient than an equivalentimp -> truepredicate.
-
-
Method Detail
-
categoryFromName
@Nullable public static OpenRtb.ContentCategory categoryFromName(@Nullable String catName)
Get aOpenRtb.ContentCategoryfrom its name (either Java or JSON name).
-
categoryToJsonName
@Nullable public static String categoryToJsonName(@Nullable String catName)
Get aOpenRtb.ContentCategory's JSON name, from its Java name.
-
categoryToJsonName
@Nullable public static String categoryToJsonName(@Nullable OpenRtb.ContentCategory cat)
Get aOpenRtb.ContentCategory's JSON name.
-
seatBid
public static OpenRtb.BidResponse.SeatBid.Builder seatBid(OpenRtb.BidResponse.Builder response, String seat)
- Returns:
- The OpenRTB SeatBid with the specified ID; will be created if not existent. The ID should be present in the request's wseat.
- See Also:
Use for the anonymous seat
-
seatBid
public static OpenRtb.BidResponse.SeatBid.Builder seatBid(OpenRtb.BidResponse.Builder response)
- Returns:
- The anonymous OpenRTB SeatBid, used by non-seat-specific bids (the seat ID is not set). Will be created if not existent.
-
bids
public static Iterable<OpenRtb.BidResponse.SeatBid.Bid.Builder> bids(OpenRtb.BidResponse.Builder response)
Iterates all bids.- Returns:
- Read-only sequence of all bis in the response. May have bids from multiple seats, grouped by seat
-
bids
public static List<OpenRtb.BidResponse.SeatBid.Bid.Builder> bids(OpenRtb.BidResponse.Builder response, @Nullable String seatFilter)
Iterates all bids from a specific seat.- Parameters:
seatFilter- Filter for seatFilter. You can usenullto select the anonymous seat, orSEAT_ANYto not filter by seat- Returns:
- View for the seat's internal sequence of bids; or an empty, read-only view if that seat doesn't exist.
-
bidWithId
@Nullable public static OpenRtb.BidResponse.SeatBid.Bid.Builder bidWithId(OpenRtb.BidResponse.Builder response, String id)
Finds a bid by ID.- Parameters:
id- Bid ID, assumed to be unique within the response- Returns:
- Matching bid's builder, or
nullif not found
-
bidWithId
@Nullable public static OpenRtb.BidResponse.SeatBid.Bid.Builder bidWithId(OpenRtb.BidResponse.Builder response, @Nullable String seatFilter, String id)
Finds a bid by seat and ID.- Parameters:
seatFilter- Filter for seatFilter. You can usenullto select the anonymous seat, orSEAT_ANYto not filter by seatid- Bid ID, assumed to be unique within the filtered seats- Returns:
- Matching bid's builder, or
nullif not found
-
bidStreamWith
public static Stream<OpenRtb.BidResponse.SeatBid.Bid.Builder> bidStreamWith(OpenRtb.BidResponse.Builder response, @Nullable String seatFilter, @Nullable Predicate<OpenRtb.BidResponse.SeatBid.Bid.Builder> bidFilter)
Finds bids by a custom criteria.- Parameters:
bidFilter- Filter for bidsseatFilter- Filter for seat. You can usenullto select the anonymous seat, orSEAT_ANYto not filter by seat- Returns:
- Read-only sequence of bids that satisfy the filter. May have bids from multiple seats, grouped by seat
-
bidsWith
public static Iterable<OpenRtb.BidResponse.SeatBid.Bid.Builder> bidsWith(OpenRtb.BidResponse.Builder response, @Nullable String seatFilter, @Nullable Predicate<OpenRtb.BidResponse.SeatBid.Bid.Builder> bidFilter)
Finds bids by a custom criteria.- Parameters:
bidFilter- Filter for bidsseatFilter- Filter for seat. You can usenullto select the anonymous seat, orSEAT_ANYto not filter by seat- Returns:
- Sequence of all bids that satisfy the filter. May have bids from multiple seats, grouped by seat
-
updateBids
public static boolean updateBids(OpenRtb.BidResponse.Builder response, Function<OpenRtb.BidResponse.SeatBid.Bid.Builder,Boolean> updater)
Updates bids, from all seats.- Parameters:
updater- Update function. Theapply()method can decide or not to update each object, and it's expected to returntruefor objects that were updated- Returns:
trueif at least one bid was updated- See Also:
for more general updating support
-
updateBids
public static boolean updateBids(OpenRtb.BidResponse.Builder response, @Nullable String seatFilter, Function<OpenRtb.BidResponse.SeatBid.Bid.Builder,Boolean> updater)
Updates bids from a given seat.- Parameters:
seatFilter- Seat ID, ornullto select the anonymous seatupdater- Update function. Theapply()method can decide or not to update each object, and it's expected to returntruefor objects that were updated- Returns:
trueif at least one bid was updated- See Also:
for more general updating support
-
removeBids
public static boolean removeBids(OpenRtb.BidResponse.Builder response, Predicate<OpenRtb.BidResponse.SeatBid.Bid.Builder> filter)
Remove bids by bid.- Parameters:
filter- Returnstrueto keep bid,falseto remove- Returns:
trueif any bid was removed- See Also:
for more general filtering support
-
removeBids
public static boolean removeBids(OpenRtb.BidResponse.Builder response, @Nullable String seatFilter, Predicate<OpenRtb.BidResponse.SeatBid.Bid.Builder> bidFilter)
Remove bids by seat and bid.- Parameters:
seatFilter- Seat ID, ornullto select the anonymous seatbidFilter- Returnstrueto keep bid,falseto remove- Returns:
trueif any bid was removed- See Also:
for more general filtering support
-
impWithId
@Nullable public static OpenRtb.BidRequest.Imp impWithId(OpenRtb.BidRequest request, String id)
Finds anOpenRtb.BidRequest.Impby ID.- Returns:
- The
OpenRtb.BidRequest.Imps that has the given id, ornullif not found.
-
bannerImpWithId
@Nullable public static OpenRtb.BidRequest.Imp bannerImpWithId(OpenRtb.BidRequest request, @Nullable String impId, String bannerId)
Find anOpenRtb.BidRequest.Impby its ID and itsOpenRtb.BidRequest.Imp.Banner's ID.- Parameters:
impId- Imp ID; optional if the Banner IDs are unique within the requestbannerId- Banner ID- Returns:
- The
OpenRtb.BidRequest.Impfor a given impression ID x banner ID, ornullif not found
-
impsWith
public static Iterable<OpenRtb.BidRequest.Imp> impsWith(OpenRtb.BidRequest request, Predicate<OpenRtb.BidRequest.Imp> impFilter)
Optimized code for most filtered lookups. This is worth the effort because bidder code may invoke these lookup methods intensely; common cases like everything-filtered or nothing-filtered are very dominant; and simpler code previously used needed lots of temporary collections.- Parameters:
request- Container of impressionsimpFilter- Filters impressions; will be executed exactly once, and only for impressions that pass the banner/video type filters. The constantsIMP_NONEandIMP_ALLallow more efficient execution when you want to filter none/all impressions.- Returns:
- Immutable or unmodifiable view for the filtered impressions
-
impStreamWith
public static Stream<OpenRtb.BidRequest.Imp> impStreamWith(OpenRtb.BidRequest request, Predicate<OpenRtb.BidRequest.Imp> impFilter)
-
addFilters
public static Predicate<OpenRtb.BidRequest.Imp> addFilters(Predicate<OpenRtb.BidRequest.Imp> baseFilter, boolean banner, boolean video, boolean nativ)
Adds "impression type" subfilters to a base filter, to further restricts impressions that contain a banner, video and/or native object.- Parameters:
baseFilter- base filter for impressionsbanner-trueto include impressions withOpenRtb.BidRequest.Imp.Bannersvideo-trueto include impressions withOpenRtb.BidRequest.Imp.Videosnativ-trueto include impressions withOpenRtb.BidRequest.Imp.Natives- Returns:
- A filter in the form:
baseFilter AND (banner OR video OR native)
-
filterSeat
public static boolean filterSeat(OpenRtb.BidResponse.SeatBidOrBuilder seatbid, @Nullable String seatFilter)
Performs a filter by seat.- Parameters:
seatbid- Seat to filterseatFilter- Filter for seat. You can usenullto select the anonymous seat, orSEAT_ANYto not filter by seat- Returns:
trueif the seat passes the filter
-
-