Coverage Report - org.seasar.teeda.core.util.ResourceBundleMap
 
Classes in this File Line Coverage Branch Coverage Complexity
ResourceBundleMap
94%
45/48
68%
15/22
2.067
 
 1  
 /*
 2  
  * Copyright 2004-2011 the Seasar Foundation and the Others.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 15  
  */
 16  
 package org.seasar.teeda.core.util;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.Collection;
 20  
 import java.util.Enumeration;
 21  
 import java.util.HashMap;
 22  
 import java.util.HashSet;
 23  
 import java.util.List;
 24  
 import java.util.Map;
 25  
 import java.util.MissingResourceException;
 26  
 import java.util.ResourceBundle;
 27  
 import java.util.Set;
 28  
 
 29  
 public class ResourceBundleMap implements Map {
 30  
 
 31  
     private final ResourceBundle bundle;
 32  
 
 33  
     private List values;
 34  
 
 35  8
     public ResourceBundleMap(ResourceBundle bundle) {
 36  8
         this.bundle = bundle;
 37  8
     }
 38  
 
 39  
     public void clear() {
 40  1
         throw new UnsupportedOperationException();
 41  
     }
 42  
 
 43  
     public boolean containsKey(Object key) {
 44  1
         boolean result = false;
 45  1
         if (key != null) {
 46  1
             result = (bundle.getObject(key.toString()) != null);
 47  
         }
 48  1
         return result;
 49  
     }
 50  
 
 51  
     public int hashCode() {
 52  2
         return bundle.hashCode();
 53  
     }
 54  
 
 55  
     public boolean isEmpty() {
 56  1
         boolean result = true;
 57  1
         Enumeration keys = bundle.getKeys();
 58  1
         result = !keys.hasMoreElements();
 59  1
         return result;
 60  
     }
 61  
 
 62  
     public Collection values() {
 63  3
         if (values == null) {
 64  1
             values = new ArrayList();
 65  1
             Enumeration keys = bundle.getKeys();
 66  3
             while (keys.hasMoreElements()) {
 67  2
                 values.add(bundle.getString((String) keys.nextElement()));
 68  
             }
 69  
         }
 70  3
         return values;
 71  
     }
 72  
 
 73  
     public int size() {
 74  1
         return values().size();
 75  
     }
 76  
 
 77  
     public boolean containsValue(Object value) {
 78  1
         return values().contains(value);
 79  
     }
 80  
 
 81  
     public Set entrySet() {
 82  4
         HashMap mappings = new HashMap();
 83  4
         Enumeration keys = bundle.getKeys();
 84  12
         while (keys.hasMoreElements()) {
 85  8
             Object key = keys.nextElement();
 86  8
             Object value = bundle.getObject((String) key);
 87  8
             mappings.put(key, value);
 88  
         }
 89  4
         return mappings.entrySet();
 90  
     }
 91  
 
 92  
     public boolean equals(Object obj) {
 93  1
         if ((obj == null) || !(obj instanceof Map)) {
 94  0
             return false;
 95  
         }
 96  1
         if (entrySet().equals(((Map) obj).entrySet())) {
 97  1
             return true;
 98  
         }
 99  0
         return false;
 100  
     }
 101  
 
 102  
     public Object get(Object key) {
 103  9
         if (key == null) {
 104  0
             return null;
 105  
         }
 106  9
         Object result = null;
 107  
         try {
 108  9
             result = bundle.getObject(key.toString());
 109  1
         } catch (MissingResourceException e) {
 110  1
             result = "???" + key + "???";
 111  8
         }
 112  9
         return result;
 113  
     }
 114  
 
 115  
     public Set keySet() {
 116  1
         Set set = new HashSet();
 117  1
         for (Enumeration enumer = bundle.getKeys(); enumer.hasMoreElements();) {
 118  2
             set.add(enumer.nextElement());
 119  
         }
 120  1
         return set;
 121  
     }
 122  
 
 123  
     public Object remove(Object key) {
 124  1
         throw new UnsupportedOperationException();
 125  
     }
 126  
 
 127  
     public void putAll(Map t) {
 128  1
         throw new UnsupportedOperationException();
 129  
     }
 130  
 
 131  
     public Object put(Object key, Object value) {
 132  1
         throw new UnsupportedOperationException();
 133  
     }
 134  
 
 135  
 }