EMMA Coverage Report (generated Mon Oct 17 05:41:20 EDT 2011)
[all classes][org.jclouds.softlayer.compute.functions]

COVERAGE SUMMARY FOR SOURCE FILE [ProductItems.java]

nameclass, %method, %block, %line, %
ProductItems.java100% (5/5)92%  (12/13)96%  (81/84)94%  (15/16)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ProductItems100% (1/1)80%  (4/5)84%  (16/19)80%  (4/5)
ProductItems (): void 0%   (0/1)0%   (0/3)0%   (0/1)
capacity (): Function 100% (1/1)100% (4/4)100% (1/1)
description (): Function 100% (1/1)100% (4/4)100% (1/1)
item (): Function 100% (1/1)100% (4/4)100% (1/1)
price (): Function 100% (1/1)100% (4/4)100% (1/1)
     
class ProductItems$1100% (1/1)100% (2/2)100% (6/6)100% (2/2)
ProductItems$1 (): void 100% (1/1)100% (3/3)100% (1/1)
apply (ProductItem): Float 100% (1/1)100% (3/3)100% (1/1)
     
class ProductItems$2100% (1/1)100% (2/2)100% (6/6)100% (2/2)
ProductItems$2 (): void 100% (1/1)100% (3/3)100% (1/1)
apply (ProductItem): String 100% (1/1)100% (3/3)100% (1/1)
     
class ProductItems$3100% (1/1)100% (2/2)100% (26/26)100% (4/4)
ProductItems$3 (): void 100% (1/1)100% (3/3)100% (1/1)
apply (ProductItem): ProductItemPrice 100% (1/1)100% (23/23)100% (3/3)
     
class ProductItems$4100% (1/1)100% (2/2)100% (27/27)100% (7/7)
ProductItems$4 (): void 100% (1/1)100% (3/3)100% (1/1)
apply (ProductItemPrice): ProductItem 100% (1/1)100% (24/24)100% (6/6)

1/**
2 * Licensed to jclouds, Inc. (jclouds) under one or more
3 * contributor license agreements.  See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership.  jclouds licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License.  You may obtain a copy of the License at
9 *
10 *   http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied.  See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19package org.jclouds.softlayer.compute.functions;
20 
21import com.google.common.base.Function;
22import com.google.common.collect.Iterables;
23import org.jclouds.softlayer.domain.ProductItem;
24import org.jclouds.softlayer.domain.ProductItemCategory;
25import org.jclouds.softlayer.domain.ProductItemPrice;
26 
27import java.util.NoSuchElementException;
28import java.util.Set;
29 
30public class ProductItems {
31 
32   /**
33    * Creates a function to get the capacity from a product item.
34    */
35   public static Function<ProductItem, Float> capacity() {
36      return new Function<ProductItem, Float>() {
37         @Override
38         public Float apply(ProductItem productItem) {
39            return productItem.getCapacity();
40         }
41      };
42   }
43 
44   /**
45    * Creates a function to get the description from a product item.
46    */
47   public static Function<ProductItem, String> description() {
48      return new Function<ProductItem, String>() {
49         @Override
50         public String apply(ProductItem productItem) {
51            return productItem.getDescription();
52         }
53      };
54   }
55 
56   /**
57    * Creates a function to get the ProductItemPrice for the ProductItem. Currently returns the
58    * first price. This will need to be changed if more than one price is returned.
59    */
60   public static Function<ProductItem, ProductItemPrice> price() {
61      return new Function<ProductItem, ProductItemPrice>() {
62         @Override
63         public ProductItemPrice apply(ProductItem productItem) {
64            if (productItem.getPrices().size() < 1)
65               throw new NoSuchElementException("ProductItem has no prices:" + productItem);
66            return Iterables.get(productItem.getPrices(), 0);
67         }
68      };
69   }
70 
71   /**
72    * Creates a function to get the ProductItem for the ProductItemPrice. Copies the category
73    * information from the price to the item if necessary The ProductItemPrices must have
74    * ProductItems.
75    */
76   public static Function<ProductItemPrice, ProductItem> item() {
77      return new Function<ProductItemPrice, ProductItem>() {
78         @Override
79         public ProductItem apply(ProductItemPrice productItemPrice) {
80            Set<ProductItemCategory> categories = productItemPrice.getCategories();
81            ProductItem item = productItemPrice.getItem();
82            ProductItem.Builder builder = ProductItem.Builder.fromProductItem(productItemPrice.getItem());
83            if (item.getCategories().size() == 0 && categories.size() != 0) {
84               builder.categories(categories);
85            }
86 
87            return builder.build();
88         }
89      };
90   }
91}

[all classes][org.jclouds.softlayer.compute.functions]
EMMA 2.0.5312 (C) Vladimir Roubtsov