@Test public void fetch() { AdRequest adRequest = new TestAdRequest.Builder(AdsType.Banner) .setAuctionId("test_banner_id_1") .setAuctionPrice(0.001) .build(); Map<String, String> params = BidMachineFetcher.fetch(adRequest); assertNotNull(params); assertEquals("test_banner_id_1", params.get(BidMachineFetcher.KEY_ID)); assertEquals(BidMachineFetcher.roundPrice(0.001), params.get(BidMachineFetcher.KEY_PRICE)); assertEquals(1, BidMachineFetcher.cachedRequests.size()); Map<String, AdRequest> requestMap = BidMachineFetcher.cachedRequests.get(AdsType.Banner); assertNotNull(requestMap); assertEquals(1, requestMap.size()); adRequest = new TestAdRequest.Builder(AdsType.Banner) .setAuctionId("test_banner_id_2") .setAuctionPrice(0.002) .build(); params = BidMachineFetcher.fetch(adRequest); assertNotNull(params); assertEquals("test_banner_id_2", params.get(BidMachineFetcher.KEY_ID)); assertEquals(BidMachineFetcher.roundPrice(0.002), params.get(BidMachineFetcher.KEY_PRICE)); assertEquals(1, BidMachineFetcher.cachedRequests.size()); requestMap = BidMachineFetcher.cachedRequests.get(AdsType.Banner); assertNotNull(requestMap); assertEquals(2, requestMap.size()); adRequest = new TestAdRequest.Builder(AdsType.Interstitial) .setAuctionId("test_interstitial_id_1") .setAuctionPrice(0.003) .build(); params = BidMachineFetcher.fetch(adRequest); assertNotNull(params); assertEquals("test_interstitial_id_1", params.get(BidMachineFetcher.KEY_ID)); assertEquals(BidMachineFetcher.roundPrice(0.003), params.get(BidMachineFetcher.KEY_PRICE)); assertEquals(2, BidMachineFetcher.cachedRequests.size()); requestMap = BidMachineFetcher.cachedRequests.get(AdsType.Interstitial); assertNotNull(requestMap); assertEquals(1, requestMap.size()); }
@Nullable @SuppressWarnings({"unchecked"}) public static Map<String, String> fetch(@NonNull AdRequest adRequest) { final Map<String, String> result = toMap(adRequest); final String id = result.get(KEY_ID); if (TextUtils.isEmpty(id)) { return null; } assert id != null; final AdsType adsType = adRequest.getType(); adRequest.addListener(new AdRequestListener() { @Override public void onRequestSuccess(@NonNull AdRequest adRequest, @NonNull AuctionResult auctionResult) { } @Override public void onRequestFailed(@NonNull AdRequest adRequest, @NonNull BMError bmError) { } @Override public void onRequestExpired(@NonNull AdRequest adRequest) { release(adRequest); } }); synchronized (BidMachineFetcher.class) { Map<String, AdRequest> cached = cachedRequests.get(adsType); if (cached == null) { cached = new HashMap<>(); cachedRequests.put(adsType, cached); } cached.put(id, adRequest); } return result; }
BidMachineFetcher { @Nullable @SuppressWarnings({"unchecked"}) public static Map<String, String> fetch(@NonNull AdRequest adRequest) { final Map<String, String> result = toMap(adRequest); final String id = result.get(KEY_ID); if (TextUtils.isEmpty(id)) { return null; } assert id != null; final AdsType adsType = adRequest.getType(); adRequest.addListener(new AdRequestListener() { @Override public void onRequestSuccess(@NonNull AdRequest adRequest, @NonNull AuctionResult auctionResult) { } @Override public void onRequestFailed(@NonNull AdRequest adRequest, @NonNull BMError bmError) { } @Override public void onRequestExpired(@NonNull AdRequest adRequest) { release(adRequest); } }); synchronized (BidMachineFetcher.class) { Map<String, AdRequest> cached = cachedRequests.get(adsType); if (cached == null) { cached = new HashMap<>(); cachedRequests.put(adsType, cached); } cached.put(id, adRequest); } return result; } }
BidMachineFetcher { @Nullable @SuppressWarnings({"unchecked"}) public static Map<String, String> fetch(@NonNull AdRequest adRequest) { final Map<String, String> result = toMap(adRequest); final String id = result.get(KEY_ID); if (TextUtils.isEmpty(id)) { return null; } assert id != null; final AdsType adsType = adRequest.getType(); adRequest.addListener(new AdRequestListener() { @Override public void onRequestSuccess(@NonNull AdRequest adRequest, @NonNull AuctionResult auctionResult) { } @Override public void onRequestFailed(@NonNull AdRequest adRequest, @NonNull BMError bmError) { } @Override public void onRequestExpired(@NonNull AdRequest adRequest) { release(adRequest); } }); synchronized (BidMachineFetcher.class) { Map<String, AdRequest> cached = cachedRequests.get(adsType); if (cached == null) { cached = new HashMap<>(); cachedRequests.put(adsType, cached); } cached.put(id, adRequest); } return result; }  }
BidMachineFetcher { @Nullable @SuppressWarnings({"unchecked"}) public static Map<String, String> fetch(@NonNull AdRequest adRequest) { final Map<String, String> result = toMap(adRequest); final String id = result.get(KEY_ID); if (TextUtils.isEmpty(id)) { return null; } assert id != null; final AdsType adsType = adRequest.getType(); adRequest.addListener(new AdRequestListener() { @Override public void onRequestSuccess(@NonNull AdRequest adRequest, @NonNull AuctionResult auctionResult) { } @Override public void onRequestFailed(@NonNull AdRequest adRequest, @NonNull BMError bmError) { } @Override public void onRequestExpired(@NonNull AdRequest adRequest) { release(adRequest); } }); synchronized (BidMachineFetcher.class) { Map<String, AdRequest> cached = cachedRequests.get(adsType); if (cached == null) { cached = new HashMap<>(); cachedRequests.put(adsType, cached); } cached.put(id, adRequest); } return result; }  static void setPriceRounding(double rounding); static void setPriceRounding(double rounding, RoundingMode roundingMode); @Nullable @SuppressWarnings({"unchecked"}) static Map<String, String> fetch(@NonNull AdRequest adRequest); @Nullable static T release(@NonNull T adRequest); @Nullable static T release(@NonNull AdsType adsType,
                                                  @NonNull Map<String, String> fetchedParams); @Nullable @SuppressWarnings("unchecked") static T release(@NonNull AdsType adsType,
                                                  @Nullable String requestId); static String roundPrice(double price); static void resetPriceRounding(); }
BidMachineFetcher { @Nullable @SuppressWarnings({"unchecked"}) public static Map<String, String> fetch(@NonNull AdRequest adRequest) { final Map<String, String> result = toMap(adRequest); final String id = result.get(KEY_ID); if (TextUtils.isEmpty(id)) { return null; } assert id != null; final AdsType adsType = adRequest.getType(); adRequest.addListener(new AdRequestListener() { @Override public void onRequestSuccess(@NonNull AdRequest adRequest, @NonNull AuctionResult auctionResult) { } @Override public void onRequestFailed(@NonNull AdRequest adRequest, @NonNull BMError bmError) { } @Override public void onRequestExpired(@NonNull AdRequest adRequest) { release(adRequest); } }); synchronized (BidMachineFetcher.class) { Map<String, AdRequest> cached = cachedRequests.get(adsType); if (cached == null) { cached = new HashMap<>(); cachedRequests.put(adsType, cached); } cached.put(id, adRequest); } return result; }  static void setPriceRounding(double rounding); static void setPriceRounding(double rounding, RoundingMode roundingMode); @Nullable @SuppressWarnings({"unchecked"}) static Map<String, String> fetch(@NonNull AdRequest adRequest); @Nullable static T release(@NonNull T adRequest); @Nullable static T release(@NonNull AdsType adsType,
                                                  @NonNull Map<String, String> fetchedParams); @Nullable @SuppressWarnings("unchecked") static T release(@NonNull AdsType adsType,
                                                  @Nullable String requestId); static String roundPrice(double price); static void resetPriceRounding(); static final String KEY_ID; static final String KEY_PRICE; static final String KEY_AD_TYPE; static final String KEY_NETWORK_KEY; static final String AD_TYPE_DISPLAY; static final String AD_TYPE_VIDEO; static final String AD_TYPE_NATIVE; }