Clover coverage report - JBind Project
Coverage timestamp: Fr Mai 28 2004 11:17:36 CEST
file stats: LOC: 129   Methods: 7
NCLOC: 101   Classes: 1
This license of Clover is provided to support the development of JBind only. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover.
 
 Source file Conditionals Statements Methods TOTAL
KeyStore.java 80% 90,9% 100% 88%
 1   
 /*
 2   
  * JBind
 3   
  *
 4   
  * Copyright (c) by Stefan Wachter. All rights reserved.
 5   
  *
 6   
  * Usage, modification, and redistribution is subject to license terms that are
 7   
  * available at 'http://www.jbind.org'. The JBind license is like the
 8   
  * 'Apache Software License V 1.1'.
 9   
  */
 10   
 package org.jbind.xml.instance.builder;
 11   
 
 12   
 import java.util.Collection;
 13   
 import java.util.HashMap;
 14   
 import java.util.HashSet;
 15   
 import java.util.Iterator;
 16   
 import java.util.Map;
 17   
 import java.util.Set;
 18   
 
 19   
 import org.jbind.xml.base.IRef;
 20   
 import org.jbind.xml.core.base.IKey;
 21   
 import org.jbind.xml.core.base.IKeyStore;
 22   
 
 23   
 public class KeyStore implements IKeyStore {
 24   
 
 25   
   private Map myKeySets = null;
 26   
   private Map myAmbiguousKeySets = null;
 27   
 
 28  2142
   public KeyStore() {}
 29   
 
 30  2049
   public Map getKeySets() {
 31  2049
     return myKeySets;
 32   
   }
 33  42
   public Map getAmbiguousKeySets() {
 34  42
     return myAmbiguousKeySets;
 35   
   }
 36   
 
 37  2049
   public void merge(IKeyStore anElementKeys) {
 38  2049
     Map keySetsToMerge = anElementKeys.getKeySets();
 39   
 
 40  2049
     if (null != keySetsToMerge) {
 41  42
       Map ambiguousKeySetsToMerge = anElementKeys.getAmbiguousKeySets();
 42   
 
 43  42
       if (null == myKeySets) {
 44  34
         myKeySets = keySetsToMerge;
 45  34
         myAmbiguousKeySets = ambiguousKeySetsToMerge;
 46   
 
 47   
       } else {
 48  8
         for (Iterator i = keySetsToMerge.keySet().iterator(); i.hasNext(); ) {
 49  8
           IRef ref = (IRef)i.next();
 50  8
           Set keysToMerge = (Set)keySetsToMerge.get(ref);
 51  8
           Set ambiguousKeysToMerge = (Set)ambiguousKeySetsToMerge.get(ref);
 52  8
           Set s = (Set)myKeySets.get(ref);
 53   
 
 54  8
           if (null == s) {
 55  2
             myKeySets.put(ref, keysToMerge);
 56  2
             myAmbiguousKeySets.put(ref, ambiguousKeysToMerge);
 57   
 
 58   
           } else {
 59  6
             Set a = (Set)myAmbiguousKeySets.get(ref);
 60  6
             for (Iterator j = keysToMerge.iterator(); j.hasNext(); ) {
 61  5
               Object key = j.next();
 62  5
               if (s.contains(key)) {
 63  3
                 a.add(key);
 64  3
                 s.remove(key);
 65   
               } else {
 66  2
                 s.add(key);
 67   
               }
 68   
             }
 69  6
             for (Iterator j = ambiguousKeysToMerge.iterator(); j.hasNext(); ) {
 70  0
               Object key = j.next();
 71  0
               s.remove(key);
 72  0
               a.add(key);
 73   
             }
 74   
 
 75   
           }
 76   
 
 77   
         }
 78   
       }
 79   
 
 80   
     }
 81   
   }
 82   
 
 83  42
   public void addKeys(IRef aRef, Collection aKeys) {
 84  42
     if (null == myKeySets) {
 85  27
       myKeySets = new HashMap();
 86  27
       myAmbiguousKeySets = new HashMap();
 87   
     }
 88  42
     Set s = (Set)myKeySets.get(aRef);
 89  42
     Set a = (Set)myAmbiguousKeySets.get(aRef);
 90  42
     if (null == s) {
 91  39
       s = new HashSet(17);
 92  39
       myKeySets.put(aRef, s);
 93  39
       a = new HashSet(17);
 94  39
       myAmbiguousKeySets.put(aRef, a);
 95   
     }
 96  42
     for (Iterator i = aKeys.iterator(); i.hasNext(); ) {
 97  149
       Object key = i.next();
 98  149
       if (s.contains(key)) {
 99  0
         s.remove(key);
 100  0
         a.add(key);
 101   
       } else {
 102  149
         s.add(key);
 103   
       }
 104   
     }
 105   
   }
 106   
 
 107  43
   public boolean contains(IRef aRef, IKey aKey) {
 108  43
     boolean res = false;
 109  43
     if (null != myKeySets) {
 110  43
       Set s = (Set)myKeySets.get(aRef);
 111  43
       if (null != s) {
 112  43
         res = s.contains(aKey);
 113   
       }
 114   
     }
 115  43
     return res;
 116   
   }
 117   
 
 118  6
   public boolean isAmbiguous(IRef aRef, IKey aKey) {
 119  6
     boolean res = false;
 120  6
     if (null != myAmbiguousKeySets) {
 121  6
       Set s = (Set)myAmbiguousKeySets.get(aRef);
 122  6
       if (null != s) {
 123  6
         res = s.contains(aKey);
 124   
       }
 125   
     }
 126  6
     return res;
 127   
   }
 128   
 }
 129