EMMA Coverage Report (generated Tue Jun 21 05:51:52 EDT 2011)
[all classes][org.jclouds.compute.domain.internal]

COVERAGE SUMMARY FOR SOURCE FILE [HardwareImpl.java]

nameclass, %method, %block, %line, %
HardwareImpl.java100% (1/1)56%  (5/9)33%  (81/245)21%  (10/47)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class HardwareImpl100% (1/1)56%  (5/9)33%  (81/245)21%  (10/47)
compareTo (ResourceMetadata): int 0%   (0/1)0%   (0/30)0%   (0/4)
equals (Object): boolean 0%   (0/1)0%   (0/78)0%   (0/25)
getVolumes (): List 0%   (0/1)0%   (0/3)0%   (0/1)
hashCode (): int 0%   (0/1)0%   (0/53)0%   (0/7)
HardwareImpl (String, String, String, Location, URI, Map, Iterable, int, Iter... 100% (1/1)100% (30/30)100% (6/6)
getProcessors (): List 100% (1/1)100% (3/3)100% (1/1)
getRam (): int 100% (1/1)100% (3/3)100% (1/1)
supportsImage (): Predicate 100% (1/1)100% (3/3)100% (1/1)
toString (): String 100% (1/1)100% (42/42)100% (1/1)

1/**
2 *
3 * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
4 *
5 * ====================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * 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, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ====================================================================
18 */
19package org.jclouds.compute.domain.internal;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22import static org.jclouds.compute.util.ComputeServiceUtils.getCoresAndSpeed;
23import static org.jclouds.compute.util.ComputeServiceUtils.getSpace;
24 
25import java.net.URI;
26import java.util.List;
27import java.util.Map;
28 
29import javax.annotation.Nullable;
30 
31import org.jclouds.compute.domain.ComputeType;
32import org.jclouds.compute.domain.Hardware;
33import org.jclouds.compute.domain.Image;
34import org.jclouds.compute.domain.Processor;
35import org.jclouds.compute.domain.Volume;
36import org.jclouds.domain.Location;
37import org.jclouds.domain.ResourceMetadata;
38 
39import com.google.common.base.Predicate;
40import com.google.common.collect.ComparisonChain;
41import com.google.common.collect.ImmutableList;
42 
43/**
44 * @author Adrian Cole
45 */
46public class HardwareImpl extends ComputeMetadataImpl implements Hardware {
47 
48   /** The serialVersionUID */
49   private static final long serialVersionUID = 8994255275911717567L;
50   private final List<Processor> processors;
51   private final int ram;
52   private final List<Volume> volumes;
53   private final Predicate<Image> supportsImage;
54 
55   public HardwareImpl(String providerId, String name, String id, @Nullable Location location, URI uri,
56         Map<String, String> userMetadata, Iterable<? extends Processor> processors, int ram,
57         Iterable<? extends Volume> volumes, Predicate<Image> supportsImage) {
58      super(ComputeType.HARDWARE, providerId, name, id, location, uri, userMetadata);
59      this.processors = ImmutableList.copyOf(checkNotNull(processors, "processors"));
60      this.ram = ram;
61      this.volumes = ImmutableList.copyOf(checkNotNull(volumes, "volumes"));
62      this.supportsImage = supportsImage;
63   }
64 
65   /**
66    * {@inheritDoc}
67    */
68   @Override
69   public List<? extends Processor> getProcessors() {
70      return processors;
71   }
72 
73   /**
74    * {@inheritDoc}
75    */
76   @Override
77   public int getRam() {
78      return ram;
79   }
80 
81   /**
82    * {@inheritDoc}
83    */
84   @Override
85   public List<? extends Volume> getVolumes() {
86      return volumes;
87   }
88 
89   /**
90    * {@inheritDoc}
91    */
92   @Override
93   public int compareTo(ResourceMetadata<ComputeType> that) {
94      if (that instanceof Hardware) {
95         Hardware thatHardware = Hardware.class.cast(that);
96         return ComparisonChain.start().compare(getCoresAndSpeed(this), getCoresAndSpeed(thatHardware))
97               .compare(this.getRam(), thatHardware.getRam()).compare(getSpace(this), getSpace(thatHardware)).result();
98      } else {
99         return super.compareTo(that);
100      }
101   }
102 
103   /**
104    * {@inheritDoc}
105    */
106   @Override
107   public String toString() {
108      return "[id=" + getId() + ", providerId=" + getProviderId() + ", name=" + getName() + ", processors="
109            + processors + ", ram=" + ram + ", volumes=" + volumes + ", supportsImage=" + supportsImage + "]";
110   }
111 
112   /**
113    * {@inheritDoc}
114    */
115   @Override
116   public Predicate<Image> supportsImage() {
117      return supportsImage;
118   }
119 
120   @Override
121   public int hashCode() {
122      final int prime = 31;
123      int result = super.hashCode();
124      result = prime * result + ((processors == null) ? 0 : processors.hashCode());
125      result = prime * result + ram;
126      result = prime * result + ((supportsImage == null) ? 0 : supportsImage.hashCode());
127      result = prime * result + ((volumes == null) ? 0 : volumes.hashCode());
128      return result;
129   }
130 
131   @Override
132   public boolean equals(Object obj) {
133      if (this == obj)
134         return true;
135      if (!super.equals(obj))
136         return false;
137      if (getClass() != obj.getClass())
138         return false;
139      HardwareImpl other = (HardwareImpl) obj;
140      if (processors == null) {
141         if (other.processors != null)
142            return false;
143      } else if (!processors.equals(other.processors))
144         return false;
145      if (ram != other.ram)
146         return false;
147      if (supportsImage == null) {
148         if (other.supportsImage != null)
149            return false;
150      } else if (!supportsImage.equals(other.supportsImage))
151         return false;
152      if (volumes == null) {
153         if (other.volumes != null)
154            return false;
155      } else if (!volumes.equals(other.volumes))
156         return false;
157      return true;
158   }
159}

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