@Override public Price apply(ProductItemPrice productItemPrice) { return new Price(productItemPrice.getId()); } });
@Override public String apply(ProductItem productItem) { checkNotNull(productItem, "productItem"); ProductItemPrice price = ProductItems.price().apply(productItem); return "" + price.getId(); } };
@Override public String apply(List<ProductItem> productItems) { StringBuilder builder = new StringBuilder(); for (ProductItem item : productItems) { ProductItemPrice price = ProductItems.price().apply(item); builder.append(price.getId()).append(","); } return builder.toString().substring(0, builder.lastIndexOf(",")); } };
@Override public Price apply(ProductItemPrice productItemPrice) { return new Price(productItemPrice.getId()); } });
@Override public String apply(List<ProductItem> productItems) { StringBuilder builder = new StringBuilder(); for (ProductItem item : productItems) { ProductItemPrice price = ProductItems.price().apply(item); builder.append(price.getId()).append(","); } return builder.toString().substring(0, builder.lastIndexOf(",")); } };
@Override public String apply(ProductItem productItem) { checkNotNull(productItem, "productItem"); ProductItemPrice price = ProductItems.price().apply(productItem); return "" + price.getId(); } };
@Test public void testGetUbuntuPrice() { Iterable<ProductItem> operatingSystems = Iterables.filter(cloudServerProductPackage.getItems(), categoryCode("os")); Map<String, ProductItem> osToProductItem = Maps.uniqueIndex(operatingSystems, ProductItems.description()); ProductItemPrice price = ProductItems.price().apply( osToProductItem.get("Ubuntu Linux 8 LTS Hardy Heron - Minimal Install (64 bit)")); assert Integer.valueOf(1693).equals(price.getId()); }
@Test public void testGetTwoCPUCoresPrice() { // If use ProductItemPredicates.categoryCode("guest_core") get duplicate // capacities (units = // PRIVATE_CORE and N/A) Iterable<ProductItem> cpuItems = Iterables.filter(cloudServerProductPackage.getItems(), Predicates.and(units("PRIVATE_CORE"), capacity(2.0f))); // number of cores is the key Map<Float, ProductItem> coresToProductItem = Maps.uniqueIndex(cpuItems, ProductItems.capacity()); ProductItemPrice price = ProductItems.price().apply(coresToProductItem.get(2.0f)); assert Integer.valueOf(1963).equals(price.getId()); }
@Test public void testGetOneGBRamPrice() { // Predicate p = // Predicates.and(ProductItemPredicates.categoryCode("ram"),ProductItemPredicates.capacity(1.0f)); Iterable<ProductItem> ramItems = Iterables.filter(cloudServerProductPackage.getItems(), Predicates.and(categoryCode("ram"), capacity(1.0f))); // capacity is key in GB (1Gb = 1.0f) Map<Float, ProductItem> ramToProductItem = Maps.uniqueIndex(ramItems, ProductItems.capacity()); ProductItemPrice price = ProductItems.price().apply(ramToProductItem.get(1.0f)); assert Integer.valueOf(1644).equals(price.getId()); }
private void checkPrice(ProductItemPrice price) { assert price.getId() > 0 : price; assert price.getItemId() > 0 : price; assert price.getRecurringFee() != null || price.getHourlyRecurringFee() != null : price; }
public Builder fromProductItemPrice(ProductItemPrice in) { return this .id(in.getId()) .hourlyRecurringFee(in.getHourlyRecurringFee()) .recurringFee(in.getRecurringFee()) .item(in.getItem()); } }
public Builder fromProductItemPrice(ProductItemPrice in) { return this .id(in.getId()) .hourlyRecurringFee(in.getHourlyRecurringFee()) .recurringFee(in.getRecurringFee()) .item(in.getItem()); } }
public Builder fromProductItemPrice(ProductItemPrice in) { return this .id(in.getId()) .hourlyRecurringFee(in.getHourlyRecurringFee()) .recurringFee(in.getRecurringFee()) .item(in.getItem()); } }
public T fromProductItemPrice(ProductItemPrice in) { return this .id(in.getId()) .itemId(in.getItemId()) .recurringFee(in.getRecurringFee()) .hourlyRecurringFee(in.getHourlyRecurringFee()) .item(in.getItem()) .categories(in.getCategories()); } }
public T fromProductItemPrice(ProductItemPrice in) { return this .id(in.getId()) .itemId(in.getItemId()) .recurringFee(in.getRecurringFee()) .hourlyRecurringFee(in.getHourlyRecurringFee()) .item(in.getItem()) .categories(in.getCategories()); } }