Coverage Report - org.apache.commons.inject.impl.ImmutableBindingSet
 
Classes in this File Line Coverage Branch Coverage Complexity
ImmutableBindingSet
80%
17/21
100%
10/10
0
 
 1  
 /**
 2  
  Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  contributor license agreements.  See the NOTICE file distributed with
 4  
  this work for additional information regarding copyright ownership.
 5  
  The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  (the "License"); you may not use this file except in compliance with
 7  
  the License.  You may obtain a copy of the License at
 8  
 
 9  
       http://www.apache.org/licenses/LICENSE-2.0
 10  
 
 11  
  Unless required by applicable law or agreed to in writing, software
 12  
  distributed under the License is distributed on an "AS IS" BASIS,
 13  
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  See the License for the specific language governing permissions and
 15  
  limitations under the License.
 16  
 */
 17  
 package org.apache.commons.inject.impl;
 18  
 
 19  
 import java.util.ArrayList;
 20  
 import java.util.List;
 21  
 import java.util.Map;
 22  
 
 23  
 import org.apache.commons.inject.api.IBinding;
 24  
 import org.apache.commons.inject.api.IKey;
 25  
 
 26  
 public class ImmutableBindingSet extends AbstractBindingSet {
 27  
         public ImmutableBindingSet(ResolvableBindingSet pResolvableBindings) {
 28  9
                 super(pResolvableBindings.map);
 29  9
         }
 30  
 
 31  
         <T> IBinding<T> getBinding(IKey<T> pKey) {
 32  27
                 final ReducedKey<T> rkey = new ReducedKey<T>(pKey.getType(), pKey.getName());
 33  27
                 final List<BindingAndKey<?>> list = map.get(rkey);
 34  27
                 if (list != null) {
 35  25
                         for (BindingAndKey<?> bak : list) {
 36  25
                                 if (isMatching(pKey, bak.getKey())) {
 37  
                                         @SuppressWarnings("unchecked")
 38  24
                                         final IBinding<T> binding = (IBinding<T>) bak.getBinding();
 39  24
                                         return binding;
 40  
                                 }
 41  
                         }
 42  
                 }
 43  3
                 return null;
 44  
         }
 45  
 
 46  
         <T> void add(ReducedKey<T> pRKey, MappedKey<T> pMKey, IBinding<T> pBinding) {
 47  0
                 final List<BindingAndKey<?>> list = findOrCreateList(pRKey);
 48  0
                 final BindingAndKey<T> bak = new BindingAndKey<T>(pBinding, pMKey);
 49  0
                 list.add(bak);
 50  0
         }
 51  
 
 52  
         Iterable<IBinding<?>> getAllBindings() {
 53  9
                 final List<IBinding<?>> list = new ArrayList<IBinding<?>>();
 54  9
                 for (Map.Entry<ReducedKey<?>,List<BindingAndKey<?>>> en : map.entrySet()) {
 55  45
                         final List<BindingAndKey<?>> baklist = en.getValue();
 56  45
                         for (BindingAndKey<?> bak : baklist) {
 57  59
                                 list.add(bak.getBinding());
 58  
                         }
 59  45
                 }
 60  9
                 return list;
 61  
         }
 62  
 }