Clover coverage report - JBind Project
Coverage timestamp: Fr Mai 28 2004 11:17:36 CEST
file stats: LOC: 131   Methods: 6
NCLOC: 111   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
EqualsVisitor.java 62,5% 79,4% 100% 74,6%
 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.core.bridge;
 11   
 
 12   
 import java.util.Collections;
 13   
 import java.util.Iterator;
 14   
 
 15   
 import org.jbind.util.collection.UnsynchronizedStack;
 16   
 import org.jbind.xml.base.INamespaces;
 17   
 import org.jbind.xml.core.data.IAnySimpleTypeData;
 18   
 import org.jbind.xml.core.data.IAnyTypeData;
 19   
 import org.jbind.xml.core.data.ISimpleData;
 20   
 import org.jbind.xml.msg.XmlException;
 21   
 
 22   
 public class EqualsVisitor implements IDataImplVisitor {
 23   
 
 24   
   private UnsynchronizedStack myIters = null;
 25   
   private boolean myEquals = true;
 26   
 
 27  5
   public EqualsVisitor() {}
 28   
 
 29  39
   public void visitElementImplStart(IElementImpl anImpl) {
 30  39
     if (!myEquals) {
 31  0
       return;
 32   
     }
 33  39
     Iterator i = (Iterator)myIters.peek();
 34  39
     if (!i.hasNext()) {
 35  0
       myEquals = false;
 36  0
       return;
 37   
     }
 38  39
     Object o = i.next();
 39  39
     myEquals = o instanceof IElementImpl;
 40  39
     if (!myEquals) {
 41  0
       return;
 42   
     }
 43  39
     IElementImpl impl2 = (IElementImpl)o;
 44  39
     myEquals = anImpl.getNamespace().equals(impl2.getNamespace()) && anImpl.getPartName().equals(impl2.getPartName());
 45  39
     myEquals &= attributesEquals(anImpl, impl2);
 46  39
     myEquals &= attributesEquals(impl2, anImpl);
 47  39
     if (!myEquals) {
 48  0
       return;
 49   
     }
 50  39
     IAnyTypeData d1 = anImpl.getData();
 51  39
     IAnyTypeData d2 = impl2.getData();
 52  39
     if ((d1 == null) && (d2 == null)) {
 53  5
       myEquals = anImpl.getTextContent().equals(impl2.getTextContent());
 54  34
     } else if ((d1 != null) && (d2 != null)) {
 55  34
       if (d1.getType_().isSimple()) {
 56  24
         myEquals = ((ISimpleData)d1).simpleStorageValueEquals(d2);
 57  10
       } else if (d2.getType_().isSimple()) {
 58  0
         myEquals = false;
 59   
       }
 60   
     } else {
 61  0
       myEquals = false;
 62   
     }
 63  39
     if (!myEquals) {
 64  0
       return;
 65   
     }
 66  39
     myIters.push(anImpl.iterChildren());
 67   
   }
 68   
 
 69  39
   public void visitElementImplEnd(IElementImpl anImpl) {
 70  39
     if (!myEquals) {
 71  0
       return;
 72   
     }
 73  39
     Iterator i = (Iterator)myIters.pop();
 74  39
     myEquals = !i.hasNext();
 75   
   }
 76   
 
 77  29
   public void visitTextImpl(ITextImpl anImpl) {
 78  29
     if (!myEquals) {
 79  0
       return;
 80   
     }
 81  29
     Iterator i = (Iterator)myIters.peek();
 82  29
     myEquals = i.hasNext();
 83  29
     if (myEquals) {
 84  29
       Object o = i.next();
 85  29
       myEquals = o instanceof ITextImpl;
 86  29
       if (myEquals) {
 87  29
         ITextImpl impl2 = (ITextImpl)o;
 88  29
         myEquals = anImpl.getTextContent().equals(impl2.getTextContent());
 89   
       }
 90   
     }
 91   
   }
 92   
 
 93  78
   private boolean attributesEquals(IElementImpl anImpl1, IElementImpl anImpl2) {
 94  78
     for (Iterator i = anImpl1.iterAttributeImpls(); i.hasNext(); ) {
 95  30
       IAttributeImpl a1 = (IAttributeImpl)i.next();
 96  30
       if (INamespaces.XML_SCHEMA_INSTANCE.equals(a1.getNamespace())) {
 97  6
         continue;
 98   
       }
 99  24
       IAttributeImpl a2 = anImpl2.getAttributeImpl(a1.getNamespace(), a1.getPartName());
 100  24
       if (null == a2) {
 101  0
         return false;
 102   
       }
 103  24
       IAnySimpleTypeData d1 = (IAnySimpleTypeData)a1.getData();
 104  24
       IAnySimpleTypeData d2 = (IAnySimpleTypeData)a2.getData();
 105  24
       if ((d1 == null) && (d2 == null)) {
 106  8
         String t1 = a1.getTextContent();
 107  8
         String t2 = a2.getTextContent();
 108  8
         if (!t1.equals(t2)) {
 109  0
           return false;
 110   
         }
 111  16
       } else if ((d1 != null) && (d2 != null)) {
 112  16
         if (!d1.simpleStorageValueEquals(d2)) {
 113  0
           return false;
 114   
         }
 115   
       } else {
 116  0
         return false;
 117   
       }
 118   
     }
 119  78
     return true;
 120   
   }
 121   
 
 122  5
   public boolean equals(IElementImpl anImpl1, IElementImpl anImpl2) throws XmlException {
 123  5
     myIters = new UnsynchronizedStack();
 124  5
     myIters.push(Collections.singletonList(anImpl2).iterator());
 125  5
     myEquals = true;
 126  5
     anImpl1.accept(this);
 127  5
     myIters = null;
 128  5
     return myEquals;
 129   
   }
 130   
 }
 131