EMMA Coverage Report (generated Wed Aug 10 12:30:04 EDT 2011)
[all classes][org.jclouds.collect]

COVERAGE SUMMARY FOR SOURCE FILE [InputSupplierMap.java]

nameclass, %method, %block, %line, %
InputSupplierMap.java25%  (1/4)29%  (6/21)31%  (72/231)23%  (11.9/52)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class InputSupplierMap$EntrySet0%   (0/1)0%   (0/6)0%   (0/83)0%   (0/21)
InputSupplierMap$EntrySet (InputSupplierMap): void 0%   (0/1)0%   (0/6)0%   (0/1)
clear (): void 0%   (0/1)0%   (0/5)0%   (0/2)
contains (Object): boolean 0%   (0/1)0%   (0/36)0%   (0/9)
iterator (): Iterator 0%   (0/1)0%   (0/12)0%   (0/2)
remove (Object): boolean 0%   (0/1)0%   (0/20)0%   (0/6)
size (): int 0%   (0/1)0%   (0/4)0%   (0/1)
     
class InputSupplierMap$EntrySet$10%   (0/1)0%   (0/4)0%   (0/28)0%   (0/6)
InputSupplierMap$EntrySet$1 (InputSupplierMap$EntrySet, Iterator): void 0%   (0/1)0%   (0/9)0%   (0/1)
hasNext (): boolean 0%   (0/1)0%   (0/4)0%   (0/1)
next (): Map$Entry 0%   (0/1)0%   (0/11)0%   (0/2)
remove (): void 0%   (0/1)0%   (0/4)0%   (0/2)
     
class InputSupplierMap$EntrySet$1$10%   (0/1)0%   (0/3)0%   (0/25)0%   (0/6)
InputSupplierMap$EntrySet$1$1 (InputSupplierMap$EntrySet$1, Map$Entry): void 0%   (0/1)0%   (0/9)0%   (0/1)
getKey (): Object 0%   (0/1)0%   (0/4)0%   (0/1)
getValue (): Object 0%   (0/1)0%   (0/12)0%   (0/4)
     
class InputSupplierMap100% (1/1)75%  (6/8)76%  (72/95)57%  (11.9/21)
clear (): void 0%   (0/1)0%   (0/4)0%   (0/2)
entrySet (): Set 0%   (0/1)0%   (0/5)0%   (0/1)
remove (Object): Object 100% (1/1)65%  (13/20)23%  (0.9/4)
get (Object): Object 100% (1/1)75%  (18/24)40%  (2/5)
put (Object, Object): Object 100% (1/1)95%  (19/20)98%  (3/3)
InputSupplierMap (Map, Function): void 100% (1/1)100% (13/13)100% (4/4)
containsKey (Object): boolean 100% (1/1)100% (5/5)100% (1/1)
size (): int 100% (1/1)100% (4/4)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 */
19/**
20 *
21 * Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
22 *
23 * ====================================================================
24 * Licensed under the Apache License, Version 2.0 (the "License");
25 * you may not use this file except in compliance with the License.
26 * You may obtain a copy of the License at
27 *
28 * http://www.apache.org/licenses/LICENSE-2.0
29 *
30 * Unless required by applicable law or agreed to in writing, software
31 * distributed under the License is distributed on an "AS IS" BASIS,
32 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33 * See the License for the specific language governing permissions and
34 * limitations under the License.
35 * ====================================================================
36 */
37 
38 
39package org.jclouds.collect;
40 
41import static com.google.common.base.Preconditions.checkNotNull;
42 
43import java.io.IOException;
44import java.util.AbstractMap;
45import java.util.AbstractSet;
46import java.util.Iterator;
47import java.util.Map;
48import java.util.Set;
49 
50import com.google.common.base.Function;
51import com.google.common.base.Throwables;
52import com.google.common.io.InputSupplier;
53 
54/**
55 * 
56 * 
57 * @author Adrian Cole
58 * 
59 */
60public class InputSupplierMap<K, V> extends AbstractMap<K, V> {
61   final Map<K, InputSupplier<V>> toMap;
62   final Function<V, InputSupplier<V>> putFunction;
63 
64   public InputSupplierMap(Map<K, InputSupplier<V>> toMap, Function<V, InputSupplier<V>> putFunction) {
65      this.toMap = checkNotNull(toMap);
66      this.putFunction = checkNotNull(putFunction);
67   }
68 
69   @Override
70   public int size() {
71      return toMap.size();
72   }
73 
74   @Override
75   public V put(K key, V value) {
76      V old = get(key);
77      toMap.put(key, value != null ? putFunction.apply(value) : null);
78      return old;
79   }
80 
81   @Override
82   public boolean containsKey(Object key) {
83      return toMap.containsKey(key);
84   }
85 
86   @Override
87   public V get(Object key) {
88      InputSupplier<V> value = toMap.get(key);
89      try {
90         return (value != null || toMap.containsKey(key)) ? value.getInput() : null;
91      } catch (IOException e) {
92         Throwables.propagate(e);
93         return null;
94      }
95   }
96 
97   @Override
98   public V remove(Object key) {
99      try {
100         return toMap.containsKey(key) ? toMap.remove(key).getInput() : null;
101      } catch (IOException e) {
102         Throwables.propagate(e);
103         return null;
104      }
105   }
106 
107   @Override
108   public void clear() {
109      toMap.clear();
110   }
111 
112   @Override
113   public Set<Entry<K, V>> entrySet() {
114      return new EntrySet();
115 
116   }
117 
118   class EntrySet extends AbstractSet<Entry<K, V>> {
119      @Override
120      public int size() {
121         return InputSupplierMap.this.size();
122      }
123 
124      @Override
125      public Iterator<Entry<K, V>> iterator() {
126         final Iterator<java.util.Map.Entry<K, InputSupplier<V>>> mapIterator = toMap.entrySet().iterator();
127 
128         return new Iterator<Entry<K, V>>() {
129            public boolean hasNext() {
130               return mapIterator.hasNext();
131            }
132 
133            public Entry<K, V> next() {
134               final java.util.Map.Entry<K, InputSupplier<V>> entry = mapIterator.next();
135               return new AbstractMapEntry<K, V>() {
136                  @Override
137                  public K getKey() {
138                     return entry.getKey();
139                  }
140 
141                  @Override
142                  public V getValue() {
143                     try {
144                        return entry.getValue().getInput();
145                     } catch (IOException e) {
146                        Throwables.propagate(e);
147                        return null;
148                     }
149                  }
150               };
151            }
152 
153            public void remove() {
154               mapIterator.remove();
155            }
156         };
157      }
158 
159      @Override
160      public void clear() {
161         toMap.clear();
162      }
163 
164      @Override
165      public boolean contains(Object o) {
166         if (!(o instanceof Entry)) {
167            return false;
168         }
169         Entry<?, ?> entry = (Entry<?, ?>) o;
170         Object entryKey = entry.getKey();
171         Object entryValue = entry.getValue();
172         V mapValue = InputSupplierMap.this.get(entryKey);
173         if (mapValue != null) {
174            return mapValue.equals(entryValue);
175         }
176         return entryValue == null && containsKey(entryKey);
177      }
178 
179      @Override
180      public boolean remove(Object o) {
181         if (contains(o)) {
182            Entry<?, ?> entry = (Entry<?, ?>) o;
183            Object key = entry.getKey();
184            toMap.remove(key);
185            return true;
186         }
187         return false;
188      }
189   }
190}

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