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

COVERAGE SUMMARY FOR SOURCE FILE [BaseEnvelope.java]

nameclass, %method, %block, %line, %
BaseEnvelope.java100% (2/2)30%  (6/20)22%  (71/320)25%  (17/68)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BaseEnvelope100% (1/1)20%  (2/10)15%  (33/220)15%  (7/48)
builder (): BaseEnvelope$Builder 0%   (0/1)0%   (0/4)0%   (0/1)
equals (Object): boolean 0%   (0/1)0%   (0/85)0%   (0/28)
getAdditionalSections (): Multimap 0%   (0/1)0%   (0/3)0%   (0/1)
getDiskSections (): Set 0%   (0/1)0%   (0/3)0%   (0/1)
getNetworkSections (): Set 0%   (0/1)0%   (0/3)0%   (0/1)
hashCode (): int 0%   (0/1)0%   (0/58)0%   (0/7)
toBuilder (): BaseEnvelope$Builder 0%   (0/1)0%   (0/6)0%   (0/1)
toString (): String 0%   (0/1)0%   (0/25)0%   (0/1)
BaseEnvelope (Iterable, Iterable, Multimap, BaseVirtualSystem): void 100% (1/1)100% (30/30)100% (6/6)
getVirtualSystem (): BaseVirtualSystem 100% (1/1)100% (3/3)100% (1/1)
     
class BaseEnvelope$Builder100% (1/1)40%  (4/10)38%  (38/100)50%  (10/20)
additionalSections (Multimap): BaseEnvelope$Builder 0%   (0/1)0%   (0/9)0%   (0/2)
build (): BaseEnvelope 0%   (0/1)0%   (0/12)0%   (0/1)
diskSection (DiskSection): BaseEnvelope$Builder 0%   (0/1)0%   (0/9)0%   (0/2)
diskSections (Iterable): BaseEnvelope$Builder 0%   (0/1)0%   (0/9)0%   (0/2)
fromEnvelope (BaseEnvelope): BaseEnvelope$Builder 0%   (0/1)0%   (0/14)0%   (0/1)
networkSections (Iterable): BaseEnvelope$Builder 0%   (0/1)0%   (0/9)0%   (0/2)
BaseEnvelope$Builder (): void 100% (1/1)100% (12/12)100% (4/4)
additionalSection (String, Section): BaseEnvelope$Builder 100% (1/1)100% (12/12)100% (2/2)
networkSection (NetworkSection): BaseEnvelope$Builder 100% (1/1)100% (9/9)100% (2/2)
virtualSystem (BaseVirtualSystem): BaseEnvelope$Builder 100% (1/1)100% (5/5)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.ovf.internal;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22 
23import java.util.Set;
24 
25import org.jclouds.ovf.DiskSection;
26import org.jclouds.ovf.NetworkSection;
27import org.jclouds.ovf.Section;
28 
29import com.google.common.collect.ImmutableMultimap;
30import com.google.common.collect.ImmutableSet;
31import com.google.common.collect.LinkedHashMultimap;
32import com.google.common.collect.Multimap;
33import com.google.common.collect.Sets;
34 
35/**
36 * @author Adrian Cole
37 */
38public class BaseEnvelope<V extends BaseVirtualSystem<V>, E extends BaseEnvelope<V, E>> {
39 
40   public static <V extends BaseVirtualSystem<V>, E extends BaseEnvelope<V, E>> Builder<V, E> builder() {
41      return new Builder<V, E>();
42   }
43 
44   /**
45    * {@inheritDoc}
46    */
47   public Builder<V, E> toBuilder() {
48      return new Builder<V, E>().fromEnvelope(this);
49   }
50 
51   public static class Builder<V extends BaseVirtualSystem<V>, E extends BaseEnvelope<V, E>> {
52      protected Set<DiskSection> diskSections = Sets.newLinkedHashSet();
53      protected Set<NetworkSection> networkSections = Sets.newLinkedHashSet();
54      @SuppressWarnings("unchecked")
55      protected Multimap<String, Section> additionalSections = LinkedHashMultimap.create();
56      protected V virtualSystem;
57 
58      /**
59       * @see BaseEnvelope#getDiskSections
60       */
61      public Builder<V, E> diskSection(DiskSection diskSection) {
62         this.diskSections.add(checkNotNull(diskSection, "diskSection"));
63         return this;
64      }
65 
66      /**
67       * @see BaseEnvelope#getDiskSections
68       */
69      public Builder<V, E> diskSections(Iterable<? extends DiskSection> diskSections) {
70         this.diskSections = ImmutableSet.<DiskSection> copyOf(checkNotNull(diskSections, "diskSections"));
71         return this;
72      }
73 
74      /**
75       * @see BaseEnvelope#getNetworkSections
76       */
77      public Builder<V, E> networkSection(NetworkSection networkSection) {
78         this.networkSections.add(checkNotNull(networkSection, "networkSection"));
79         return this;
80      }
81 
82      /**
83       * @see BaseEnvelope#getNetworkSections
84       */
85      public Builder<V, E> networkSections(Iterable<? extends NetworkSection> networkSections) {
86         this.networkSections = ImmutableSet.<NetworkSection> copyOf(checkNotNull(networkSections, "networkSections"));
87         return this;
88      }
89 
90      /**
91       * @see BaseEnvelope#getAdditionalSections
92       */
93      @SuppressWarnings("unchecked")
94      public Builder<V, E> additionalSection(String name, Section additionalSection) {
95         this.additionalSections.put(checkNotNull(name, "name"), checkNotNull(additionalSection, "additionalSection"));
96         return this;
97      }
98 
99      /**
100       * @see BaseEnvelope#getAdditionalSections
101       */
102      @SuppressWarnings("unchecked")
103      public Builder<V, E> additionalSections(Multimap<String, Section> additionalSections) {
104         this.additionalSections = ImmutableMultimap.<String, Section> copyOf(checkNotNull(additionalSections,
105                  "additionalSections"));
106         return this;
107      }
108 
109      /**
110       * @see BaseEnvelope#getVirtualSystem
111       */
112      public Builder<V, E> virtualSystem(V virtualSystem) {
113         this.virtualSystem = virtualSystem;
114         return this;
115      }
116 
117      /**
118       * {@inheritDoc}
119       */
120      @SuppressWarnings("unchecked")
121      public E build() {
122         return (E) new BaseEnvelope<V, E>(diskSections, networkSections, additionalSections, virtualSystem);
123      }
124 
125      public Builder<V, E> fromEnvelope(BaseEnvelope<V, E> in) {
126         return virtualSystem(in.getVirtualSystem()).diskSections(in.getDiskSections())
127                  .networkSections(networkSections).additionalSections(in.getAdditionalSections());
128      }
129 
130   }
131 
132   private final Set<DiskSection> diskSections;
133   private final Set<NetworkSection> networkSections;
134   @SuppressWarnings("unchecked")
135   private final Multimap<String, Section> additionalSections;
136   private final V virtualSystem;
137 
138   @SuppressWarnings("unchecked")
139   public BaseEnvelope(Iterable<? extends DiskSection> diskSections, Iterable<? extends NetworkSection> networkSections,
140            Multimap<String, Section> additionalSections, V virtualSystem) {
141      this.diskSections = ImmutableSet.copyOf(checkNotNull(diskSections, "diskSections"));
142      this.networkSections = ImmutableSet.copyOf(checkNotNull(networkSections, "networkSections"));
143      this.additionalSections = ImmutableMultimap.copyOf(checkNotNull(additionalSections, "additionalSections"));
144      this.virtualSystem = checkNotNull(virtualSystem, "virtualSystem");
145   }
146 
147   public V getVirtualSystem() {
148      return virtualSystem;
149   }
150 
151   public Set<? extends DiskSection> getDiskSections() {
152      return diskSections;
153   }
154 
155   @SuppressWarnings("unchecked")
156   public Multimap<String, Section> getAdditionalSections() {
157      return additionalSections;
158   }
159 
160   @Override
161   public int hashCode() {
162      final int prime = 31;
163      int result = 1;
164      result = prime * result + ((additionalSections == null) ? 0 : additionalSections.hashCode());
165      result = prime * result + ((diskSections == null) ? 0 : diskSections.hashCode());
166      result = prime * result + ((networkSections == null) ? 0 : networkSections.hashCode());
167      result = prime * result + ((virtualSystem == null) ? 0 : virtualSystem.hashCode());
168      return result;
169   }
170 
171   @Override
172   public boolean equals(Object obj) {
173      if (this == obj)
174         return true;
175      if (obj == null)
176         return false;
177      if (getClass() != obj.getClass())
178         return false;
179      BaseEnvelope<?, ?> other = (BaseEnvelope<?, ?>) obj;
180      if (additionalSections == null) {
181         if (other.additionalSections != null)
182            return false;
183      } else if (!additionalSections.equals(other.additionalSections))
184         return false;
185      if (diskSections == null) {
186         if (other.diskSections != null)
187            return false;
188      } else if (!diskSections.equals(other.diskSections))
189         return false;
190      if (networkSections == null) {
191         if (other.networkSections != null)
192            return false;
193      } else if (!networkSections.equals(other.networkSections))
194         return false;
195      if (virtualSystem == null) {
196         if (other.virtualSystem != null)
197            return false;
198      } else if (!virtualSystem.equals(other.virtualSystem))
199         return false;
200      return true;
201   }
202 
203   @Override
204   public String toString() {
205      return String.format("[diskSections=%s, networkSections=%s, additionalSections=%s, virtualSystem=%s]",
206               diskSections, networkSections, additionalSections, virtualSystem);
207   }
208 
209   public Set<NetworkSection> getNetworkSections() {
210      return networkSections;
211   }
212}

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