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

COVERAGE SUMMARY FOR SOURCE FILE [OperatingSystemPredicates.java]

nameclass, %method, %block, %line, %
OperatingSystemPredicates.java71%  (5/7)46%  (11/24)74%  (222/299)63%  (29.8/47)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class OperatingSystemPredicates$10%   (0/1)0%   (0/3)0%   (0/40)0%   (0/9)
OperatingSystemPredicates$1 (): void 0%   (0/1)0%   (0/3)0%   (0/1)
apply (OperatingSystem): boolean 0%   (0/1)0%   (0/35)0%   (0/7)
toString (): String 0%   (0/1)0%   (0/2)0%   (0/1)
     
class OperatingSystemPredicates$50%   (0/1)0%   (0/3)0%   (0/8)0%   (0/3)
OperatingSystemPredicates$5 (): void 0%   (0/1)0%   (0/3)0%   (0/1)
apply (OperatingSystem): boolean 0%   (0/1)0%   (0/3)0%   (0/1)
toString (): String 0%   (0/1)0%   (0/2)0%   (0/1)
     
class OperatingSystemPredicates100% (1/1)50%  (4/8)71%  (32/45)64%  (9/14)
OperatingSystemPredicates (): void 0%   (0/1)0%   (0/3)0%   (0/2)
any (): Predicate 0%   (0/1)0%   (0/2)0%   (0/1)
is64Bit (): Predicate 0%   (0/1)0%   (0/4)0%   (0/1)
isUnix (): Predicate 0%   (0/1)0%   (0/4)0%   (0/1)
searchStrings (OperatingSystem): Iterable 100% (1/1)100% (20/20)100% (6/6)
supportsApt (): Predicate 100% (1/1)100% (4/4)100% (1/1)
supportsYum (): Predicate 100% (1/1)100% (4/4)100% (1/1)
supportsZypper (): Predicate 100% (1/1)100% (4/4)100% (1/1)
     
class OperatingSystemPredicates$6100% (1/1)100% (1/1)87%  (53/61)86%  (0.9/1)
<static initializer> 100% (1/1)87%  (53/61)86%  (0.9/1)
     
class OperatingSystemPredicates$4100% (1/1)67%  (2/3)90%  (36/40)78%  (7/9)
toString (): String 0%   (0/1)0%   (0/2)0%   (0/1)
apply (OperatingSystem): boolean 100% (1/1)94%  (33/35)86%  (6/7)
OperatingSystemPredicates$4 (): void 100% (1/1)100% (3/3)100% (1/1)
     
class OperatingSystemPredicates$2100% (1/1)67%  (2/3)96%  (44/46)89%  (8/9)
toString (): String 0%   (0/1)0%   (0/2)0%   (0/1)
OperatingSystemPredicates$2 (): void 100% (1/1)100% (3/3)100% (1/1)
apply (OperatingSystem): boolean 100% (1/1)100% (41/41)100% (7/7)
     
class OperatingSystemPredicates$3100% (1/1)67%  (2/3)97%  (57/59)89%  (8/9)
toString (): String 0%   (0/1)0%   (0/2)0%   (0/1)
OperatingSystemPredicates$3 (): void 100% (1/1)100% (3/3)100% (1/1)
apply (OperatingSystem): boolean 100% (1/1)100% (54/54)100% (7/7)

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 java.util.Set;
22 
23import org.jclouds.compute.domain.OperatingSystem;
24 
25import com.google.common.base.Predicate;
26import com.google.common.base.Predicates;
27import com.google.common.collect.Sets;
28 
29/**
30 * Container for operating system filters (predicates).
31 * 
32 * This class has static methods that create customized predicates to use with
33 * {@link org.jclouds.compute.ComputeService}.
34 * 
35 * @author Adrian Cole
36 */
37public class OperatingSystemPredicates {
38   /**
39    * evaluates true if the OperatingSystem is unix like
40    * 
41    */
42   public static Predicate<OperatingSystem> isUnix() {
43      return new Predicate<OperatingSystem>() {
44         @Override
45         public boolean apply(OperatingSystem os) {
46            if (os.getFamily() != null) {
47               switch (os.getFamily()) {
48                  case WINDOWS:
49                     return false;
50               }
51            }
52            for (String toMatch : searchStrings(os))
53               if (toMatch != null && toMatch.toLowerCase().indexOf("windows") != -1)
54                  return false;
55            return true;
56         }
57 
58         @Override
59         public String toString() {
60            return "isUnix()";
61         }
62      };
63   }
64 
65   /**
66    * evaluates true if the OperatingSystem supports the apt installer
67    * 
68    */
69   public static Predicate<OperatingSystem> supportsApt() {
70      return new Predicate<OperatingSystem>() {
71         @Override
72         public boolean apply(OperatingSystem os) {
73            if (os.getFamily() != null) {
74               switch (os.getFamily()) {
75                  case DEBIAN:
76                  case UBUNTU:
77                     return true;
78               }
79            }
80            for (String toMatch : searchStrings(os))
81               if (toMatch != null && toMatch.toLowerCase().indexOf("ubuntu") != -1
82                        || toMatch.toLowerCase().indexOf("debian") != -1)
83                  return true;
84            return false;
85         }
86 
87         @Override
88         public String toString() {
89            return "supportsApt()";
90         }
91      };
92   }
93 
94   /**
95    * evaluates true if the OperatingSystem supports the yum installer
96    * 
97    */
98   public static Predicate<OperatingSystem> supportsYum() {
99      return new Predicate<OperatingSystem>() {
100         @Override
101         public boolean apply(OperatingSystem os) {
102            if (os.getFamily() != null) {
103               switch (os.getFamily()) {
104                  case CENTOS:
105                  case AMZN_LINUX:
106                  case FEDORA:
107                  case RHEL:
108                     return true;
109               }
110            }
111 
112            for (String toMatch : searchStrings(os))
113               if (toMatch.toLowerCase().indexOf("centos") != -1 || toMatch.toLowerCase().indexOf("rhel") != -1
114                        || toMatch.toLowerCase().replace(" ", "").indexOf("redhate") != -1
115                        || toMatch.toLowerCase().indexOf("fedora") != -1)
116                  return true;
117            return false;
118         }
119 
120         @Override
121         public String toString() {
122            return "supportsYum()";
123         }
124      };
125   }
126 
127   /**
128    * evaluates true if the OperatingSystem supports the zypper installer
129    * 
130    */
131   public static Predicate<OperatingSystem> supportsZypper() {
132      return new Predicate<OperatingSystem>() {
133         @Override
134         public boolean apply(OperatingSystem os) {
135            if (os.getFamily() != null) {
136               switch (os.getFamily()) {
137                  case SUSE:
138                     return true;
139               }
140            }
141            for (String toMatch : searchStrings(os))
142               if (toMatch != null && toMatch.toLowerCase().indexOf("suse") != -1)
143                  return true;
144            return false;
145         }
146 
147         @Override
148         public String toString() {
149            return "supportsZypper()";
150         }
151      };
152   }
153 
154   /**
155    * return everything.
156    */
157   public static Predicate<OperatingSystem> any() {
158      return Predicates.<OperatingSystem> alwaysTrue();
159   }
160 
161   /**
162    * return true if this is a 64bit os.
163    */
164   public static Predicate<OperatingSystem> is64Bit() {
165      return new Predicate<OperatingSystem>() {
166         @Override
167         public boolean apply(OperatingSystem os) {
168            return os.is64Bit();
169         }
170 
171         @Override
172         public String toString() {
173            return "is64Bit()";
174         }
175      };
176   }
177 
178   static Iterable<String> searchStrings(OperatingSystem os) {
179      Set<String> search = Sets.newLinkedHashSet();
180      if (os.getName() != null)
181         search.add(os.getName());
182      if (os.getDescription() != null)
183         search.add(os.getDescription());
184      return search;
185   }
186 
187}

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