Coverage Report - org.webslinger.bsf.ApplyKey
 
Classes in this File Line Coverage Branch Coverage Complexity
ApplyKey
66%
29/44
71%
12/17
0
 
 1  
 package org.webslinger.bsf;
 2  
 
 3  
 import org.apache.bsf.BSFException;
 4  
 
 5  
 public class ApplyKey<C> extends Key<C> {
 6  
     private final String[] names;
 7  
     private final Class[] types;
 8  
 
 9  
     public ApplyKey(Object id, String[] names, Class[] types) {
 10  1467
         super(id);
 11  1466
         this.names = names;
 12  1471
         this.types = types;
 13  1469
     }
 14  
 
 15  
     protected ApplyKey(Object id) {
 16  0
         this(id, null, null);
 17  0
     }
 18  
 
 19  
     public String[] getNames() {
 20  4137
         return names;
 21  
     }
 22  
 
 23  
     public Class[] getTypes() {
 24  3940
         return types;
 25  
     }
 26  
 
 27  
     public static String getLastPart(String name) {
 28  0
         int period = name.lastIndexOf(".");
 29  0
         if (period == -1) return name;
 30  0
         return name.substring(period + 1);
 31  
     }
 32  
 
 33  
     public String toString() {
 34  0
         StringBuilder sb = new StringBuilder();
 35  0
         sb.append("ApplyKey<").append(getId()).append(", [");
 36  0
         for (int i = 0; i < names.length; i++) {
 37  0
             if (i != 0) sb.append(", ");
 38  0
             sb.append(names[i]);
 39  
         }
 40  0
         sb.append("], [");
 41  0
         for (int i = 0; i < types.length; i++) {
 42  0
             if (i != 0) sb.append(", ");
 43  0
             sb.append(getLastPart(types[i].getName()));
 44  
         }
 45  0
         return sb.append("]>").toString();
 46  
     }
 47  
 
 48  
     protected int computeHashCode() {
 49  1470
         int tmpHashCode = super.computeHashCode();
 50  1468
         if (this instanceof ApplyKeyDynamic) return tmpHashCode;
 51  6894
         for (String name: getNames()) {
 52  5418
             tmpHashCode ^= name.hashCode();
 53  
         }
 54  6888
         for (Class type: getTypes()) {
 55  5418
             tmpHashCode ^= type.hashCode();
 56  
         }
 57  1472
         return tmpHashCode;
 58  
     }
 59  
 
 60  
     protected boolean keyEquals(Key key) {
 61  1190
         if (!super.keyEquals(key)) return false;
 62  1193
         if (this instanceof ApplyKeyDynamic) return true;
 63  1191
         if (key instanceof ApplyKeyDynamic) return key.equals(this);
 64  1192
         ApplyKey other = (ApplyKey) key;
 65  1195
         String[] myNames = getNames();
 66  1192
         String[] otherNames = other.getNames();
 67  1190
         if (myNames.length != otherNames.length) return false;
 68  5398
         for (int i = 0; i < myNames.length; i++) {
 69  4200
             if (!myNames[i].equals(otherNames[i])) return false;
 70  
         }
 71  1196
         Class[] myTypes = getTypes();
 72  1194
         Class[] otherTypes = other.getTypes();
 73  1194
         if (myTypes.length != otherTypes.length) return false;
 74  5395
         for (int i = 0; i < myTypes.length; i++) {
 75  4199
             if (!myTypes[i].equals(otherTypes[i])) return false;
 76  
         }
 77  1195
         return true;
 78  
     }
 79  
 
 80  
     public <V> C compile(Compiler<V, C> compiler, Compiler<V, C>.CompilerContext context) throws BSFException {
 81  278
         return compiler.compileKey(this, context);
 82  
     }
 83  
 }