EMMA Coverage Report (generated Wed Oct 26 13:47:17 EDT 2011)
[all classes][org.jclouds.compute.predicates]

COVERAGE SUMMARY FOR SOURCE FILE [ImagePredicates.java]

nameclass, %method, %block, %line, %
ImagePredicates.java60%  (3/5)35%  (7/20)38%  (55/143)38%  (8/21)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ImagePredicates$10%   (0/1)0%   (0/3)0%   (0/24)0%   (0/3)
ImagePredicates$1 (Set): void 0%   (0/1)0%   (0/6)0%   (0/1)
apply (Image): boolean 0%   (0/1)0%   (0/6)0%   (0/1)
toString (): String 0%   (0/1)0%   (0/12)0%   (0/1)
     
class ImagePredicates$Is64BitPredicate0%   (0/1)0%   (0/5)0%   (0/15)0%   (0/4)
ImagePredicates$Is64BitPredicate (): void 0%   (0/1)0%   (0/3)0%   (0/1)
ImagePredicates$Is64BitPredicate (ImagePredicates$1): void 0%   (0/1)0%   (0/3)0%   (0/1)
apply (Image): boolean 0%   (0/1)0%   (0/4)0%   (0/1)
equals (Object): boolean 0%   (0/1)0%   (0/3)0%   (0/1)
toString (): String 0%   (0/1)0%   (0/2)0%   (0/1)
     
class ImagePredicates$3100% (1/1)67%  (2/3)50%  (12/24)67%  (2/3)
toString (): String 0%   (0/1)0%   (0/12)0%   (0/1)
ImagePredicates$3 (String): void 100% (1/1)100% (6/6)100% (1/1)
apply (Image): boolean 100% (1/1)100% (6/6)100% (1/1)
     
class ImagePredicates$2100% (1/1)67%  (2/3)51%  (18/35)67%  (2/3)
toString (): String 0%   (0/1)0%   (0/17)0%   (0/1)
ImagePredicates$2 (String, String): void 100% (1/1)100% (9/9)100% (1/1)
apply (Image): boolean 100% (1/1)100% (9/9)100% (1/1)
     
class ImagePredicates100% (1/1)50%  (3/6)56%  (25/45)50%  (6/12)
ImagePredicates (): void 0%   (0/1)0%   (0/3)0%   (0/2)
idIn (Iterable): Predicate 0%   (0/1)0%   (0/12)0%   (0/3)
is64Bit (): Predicate 0%   (0/1)0%   (0/5)0%   (0/1)
any (): Predicate 100% (1/1)100% (2/2)100% (1/1)
idEquals (String): Predicate 100% (1/1)100% (9/9)100% (2/2)
userMetadataContains (String, String): Predicate 100% (1/1)100% (14/14)100% (3/3)

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.compute.predicates;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22 
23import java.util.Set;
24 
25import org.jclouds.javax.annotation.Nullable;
26 
27import org.jclouds.compute.domain.Image;
28 
29import com.google.common.base.Predicate;
30import com.google.common.base.Predicates;
31import com.google.common.collect.Sets;
32 
33/**
34 * Container for image filters (predicates).
35 * 
36 * This class has static methods that create customized predicates to use with
37 * {@link org.jclouds.compute.ComputeService}.
38 * 
39 * @author Adrian Cole
40 */
41public class ImagePredicates {
42   private static final class Is64BitPredicate implements Predicate<Image> {
43      @Override
44      public boolean apply(Image image) {
45         return image.getOperatingSystem().is64Bit();
46      }
47 
48      @Override
49      public String toString() {
50         return "is64Bit()";
51      }
52 
53      @Override
54      public boolean equals(@Nullable Object obj) {
55         return (obj instanceof Is64BitPredicate);
56      }
57 
58   }
59 
60   /**
61    * evaluates true if the Image id is in the supplied set
62    * 
63    * @param ids
64    *           ids of the images
65    * @return predicate
66    */
67   public static Predicate<Image> idIn(Iterable<String> ids) {
68      checkNotNull(ids, "ids must be defined");
69      final Set<String> search = Sets.newHashSet(ids);
70      return new Predicate<Image>() {
71         @Override
72         public boolean apply(Image image) {
73            return search.contains(image.getId());
74         }
75 
76         @Override
77         public String toString() {
78            return "idIn(" + search + ")";
79         }
80      };
81   }
82   
83   /**
84    * evaluates true if the Image metadata contains the following values
85    * 
86    * @param key
87    *           key in Image#getUserMetadata
88    * @param value
89    *           value in Image#getUserMetadata
90     * @return predicate
91    */
92   public static Predicate<Image> userMetadataContains(final String key, final String value) {
93      checkNotNull(key, "key must be defined");
94      checkNotNull(value, "value must be defined");
95      return new Predicate<Image>() {
96         @Override
97         public boolean apply(Image image) {
98            return value.equals(image.getUserMetadata().get(key));
99         }
100 
101         @Override
102         public String toString() {
103            return "metadataContains(" + key +", "+value + ")";
104         }
105      };
106   }
107 
108   /**
109    * evaluates true if the Image
110    * 
111    * @param ids
112    *           ids of the images
113    * @return predicate
114    */
115   public static Predicate<Image> idEquals(final String id) {
116      checkNotNull(id, "id must be defined");
117      return new Predicate<Image>() {
118         @Override
119         public boolean apply(Image image) {
120            return id.equals(image.getId());
121         }
122 
123         @Override
124         public String toString() {
125            return "idEquals(" + id + ")";
126         }
127      };
128   }
129 
130   /**
131    * return true if this is a 64bit image.
132    */
133   public static Predicate<Image> is64Bit() {
134      return new Is64BitPredicate();
135   }
136 
137   /**
138    * return everything.
139    */
140   public static Predicate<Image> any() {
141      return Predicates.<Image> alwaysTrue();
142   }
143 
144}

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