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

COVERAGE SUMMARY FOR SOURCE FILE [ProductItemPredicates.java]

nameclass, %method, %block, %line, %
ProductItemPredicates.java100% (6/6)71%  (15/21)71%  (163/228)80%  (28/35)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ProductItemPredicates$4100% (1/1)67%  (2/3)57%  (16/28)75%  (3/4)
toString (): String 0%   (0/1)0%   (0/12)0%   (0/1)
ProductItemPredicates$4 (String): void 100% (1/1)100% (6/6)100% (1/1)
apply (ProductItem): boolean 100% (1/1)100% (10/10)100% (2/2)
     
class ProductItemPredicates$5100% (1/1)67%  (2/3)59%  (17/29)75%  (3/4)
toString (): String 0%   (0/1)0%   (0/12)0%   (0/1)
ProductItemPredicates$5 (Pattern): void 100% (1/1)100% (6/6)100% (1/1)
apply (ProductItem): boolean 100% (1/1)100% (11/11)100% (2/2)
     
class ProductItemPredicates$3100% (1/1)67%  (2/3)59%  (20/34)71%  (5/7)
toString (): String 0%   (0/1)0%   (0/12)0%   (0/1)
apply (ProductItem): boolean 100% (1/1)88%  (14/16)80%  (4/5)
ProductItemPredicates$3 (Float): void 100% (1/1)100% (6/6)100% (1/1)
     
class ProductItemPredicates$1100% (1/1)67%  (2/3)73%  (32/44)86%  (6/7)
toString (): String 0%   (0/1)0%   (0/12)0%   (0/1)
ProductItemPredicates$1 (String): void 100% (1/1)100% (6/6)100% (1/1)
apply (ProductItem): boolean 100% (1/1)100% (26/26)100% (5/5)
     
class ProductItemPredicates$2100% (1/1)67%  (2/3)73%  (33/45)86%  (6/7)
toString (): String 0%   (0/1)0%   (0/12)0%   (0/1)
ProductItemPredicates$2 (Pattern): void 100% (1/1)100% (6/6)100% (1/1)
apply (ProductItem): boolean 100% (1/1)100% (27/27)100% (5/5)
     
class ProductItemPredicates100% (1/1)83%  (5/6)94%  (45/48)91%  (10/11)
ProductItemPredicates (): void 0%   (0/1)0%   (0/3)0%   (0/1)
capacity (Float): Predicate 100% (1/1)100% (9/9)100% (2/2)
categoryCode (String): Predicate 100% (1/1)100% (9/9)100% (2/2)
categoryCodeMatches (Pattern): Predicate 100% (1/1)100% (9/9)100% (2/2)
matches (Pattern): Predicate 100% (1/1)100% (9/9)100% (2/2)
units (String): Predicate 100% (1/1)100% (9/9)100% (2/2)

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.predicates;
20 
21import com.google.common.base.Predicate;
22import org.jclouds.softlayer.domain.ProductItem;
23import org.jclouds.softlayer.domain.ProductItemCategory;
24 
25import java.util.regex.Pattern;
26 
27import static com.google.common.base.Preconditions.checkNotNull;
28 
29public class ProductItemPredicates {
30 
31   /**
32    * Tests if the ProductItem contains the required category.
33    * 
34    * @param category
35    * @return true if it does, otherwise false.
36    */
37   public static Predicate<ProductItem> categoryCode(final String category) {
38      checkNotNull(category, "category cannot be null");
39      return new Predicate<ProductItem>() {
40         @Override
41         public boolean apply(ProductItem productItem) {
42            checkNotNull(productItem, "productItem cannot ne null");
43            for (ProductItemCategory productItemCategory : productItem.getCategories()) {
44               if (category.equals(productItemCategory.getCategoryCode()))
45                  return true;
46            }
47            return false;
48         }
49 
50         @Override
51         public String toString() {
52            return "categoryCode(" + category + ")";
53         }
54      };
55   }
56 
57   /**
58    * Tests if the ProductItem contains a category that matches the supplied Pattern
59    * 
60    * @param category
61    * @return true if it does, otherwise false.
62    */
63   public static Predicate<ProductItem> categoryCodeMatches(final Pattern category) {
64      checkNotNull(category, "category cannot be null");
65      return new Predicate<ProductItem>() {
66         @Override
67         public boolean apply(ProductItem productItem) {
68            checkNotNull(productItem, "productItem cannot ne null");
69            for (ProductItemCategory productItemCategory : productItem.getCategories()) {
70               if (category.matcher(productItemCategory.getCategoryCode()).matches())
71                  return true;
72            }
73            return false;
74         }
75 
76         @Override
77         public String toString() {
78            return "categoryCodeMatches(" + category + ")";
79         }
80      };
81   }
82 
83   /**
84    * Tests if the ProductItem has the required capacity.
85    * 
86    * @param capacity
87    * @return true if it does, otherwise false.
88    */
89   public static Predicate<ProductItem> capacity(final Float capacity) {
90      checkNotNull(capacity, "capacity cannot be null");
91      return new Predicate<ProductItem>() {
92         @Override
93         public boolean apply(ProductItem productItem) {
94            checkNotNull(productItem, "productItem cannot ne null");
95            Float productItemCapacity = productItem.getCapacity();
96            if (productItemCapacity == null)
97               return false;
98            return capacity.equals(productItemCapacity);
99         }
100 
101         @Override
102         public String toString() {
103            return "capacity(" + capacity + ")";
104         }
105      };
106   }
107 
108   /**
109    * Tests if the ProductItem has the required units.
110    * 
111    * @param units
112    * @return true if it does, otherwise false.
113    */
114   public static Predicate<ProductItem> units(final String units) {
115      checkNotNull(units, "units cannot be null");
116      return new Predicate<ProductItem>() {
117         @Override
118         public boolean apply(ProductItem productItem) {
119            checkNotNull(productItem, "productItem cannot ne null");
120            return units.equals(productItem.getUnits());
121         }
122 
123         @Override
124         public String toString() {
125            return "units(" + units + ")";
126         }
127      };
128   }
129 
130   /**
131    * Tests if the ProductItem's description matches the supplied regular expression.
132    * 
133    * @param regex
134    *           a regular expression to match against.
135    * @return true if it does, otherwise false.
136    * @throws java.util.regex.PatternSyntaxException
137    *            if the regex is invalid
138    */
139   public static Predicate<ProductItem> matches(final Pattern regex) {
140      checkNotNull(regex, "regex cannot be null");
141 
142      return new Predicate<ProductItem>() {
143         @Override
144         public boolean apply(ProductItem productItem) {
145            checkNotNull(productItem, "productItem cannot ne null");
146            return regex.matcher(productItem.getDescription()).matches();
147         }
148 
149         @Override
150         public String toString() {
151            return "regex(" + regex + ")";
152         }
153      };
154   }
155}

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