Coverage Report - com.sun.javafx.runtime.Pointer
 
Classes in this File Line Coverage Branch Coverage Complexity
Pointer
82%
32/39
58%
18/31
0
Pointer$1
100%
1/1
N/A
0
Pointer$Type
100%
2/2
N/A
0
 
 1  
 package com.sun.javafx.runtime;
 2  
 
 3  
 import com.sun.javafx.runtime.location.*;
 4  
 import com.sun.javafx.runtime.sequence.Sequence;
 5  
 
 6  
 
 7  
 /**
 8  
  * Pointers
 9  
  *
 10  
  * @author Brian Goetz
 11  
  */
 12  
 public class Pointer {
 13  56
     public enum Type {
 14  8
         INTEGER, DOUBLE, BOOLEAN, SEQUENCE, OBJECT
 15  
     }
 16  
 
 17  
     private final Location location;
 18  
     private final Type type;
 19  
 
 20  
     public static Pointer make(Location location) {
 21  28
       Type type =
 22  
         location instanceof IntLocation ? Type.INTEGER :
 23  
         location instanceof DoubleLocation ? Type.DOUBLE :
 24  
         location instanceof BooleanLocation ? Type.BOOLEAN :
 25  
         location instanceof SequenceLocation ? Type.SEQUENCE :
 26  
         Type.OBJECT;
 27  28
         return new Pointer(location, type);
 28  
     }
 29  
 
 30  
     static Pointer make(IntLocation location) {
 31  11
         return new Pointer(location, Type.INTEGER);
 32  
     }
 33  
 
 34  
     static Pointer make(DoubleLocation location) {
 35  3
         return new Pointer(location, Type.DOUBLE);
 36  
     }
 37  
 
 38  
     static Pointer make(BooleanLocation location) {
 39  1
         return new Pointer(location, Type.BOOLEAN);
 40  
     }
 41  
 
 42  
     static Pointer make(SequenceLocation location) {
 43  3
         return new Pointer(location, Type.SEQUENCE);
 44  
     }
 45  
 
 46  
     static Pointer make(ObjectLocation location) {
 47  2
         return new Pointer(location, Type.OBJECT);
 48  
     }
 49  
 
 50  
     public static boolean equals(Pointer p1, Pointer p2) {
 51  7
         return (p1 == null) ? (p2 == null) : p1.equals(p2);
 52  
     }
 53  
 
 54  48
     private Pointer(Location location, Type type) {
 55  48
         this.location = location;
 56  48
         this.type = type;
 57  48
     }
 58  
 
 59  
     public Type getType() {
 60  0
         return type;
 61  
     }
 62  
 
 63  
     public Pointer unwrap() {
 64  13
         return this;
 65  
     }
 66  
     
 67  
     public Object get() {
 68  8
         switch (type) {
 69  
             case INTEGER:
 70  10
                 return ((IntLocation) location).getAsInt();
 71  
             case DOUBLE:
 72  3
                 return ((DoubleLocation) location).getAsDouble();
 73  
             case BOOLEAN:
 74  0
                 return ((BooleanLocation) location).getAsBoolean();
 75  
             case SEQUENCE:
 76  3
                 return ((SequenceLocation<?>) location).getAsSequence();
 77  
             default:
 78  1
                 return ((ObjectLocation<?>) location).get();
 79  
         }
 80  
     }
 81  
 
 82  
     public void set(Object value) {
 83  110
         switch (type) {
 84  
             case INTEGER:
 85  4
                 ((IntLocation) location).setAsInt(((Number)value).intValue());
 86  4
                 break;
 87  
             case DOUBLE:
 88  103
                 ((DoubleLocation) location).setAsDouble(((Number)value).doubleValue());
 89  103
                 break;
 90  
             case BOOLEAN:
 91  0
                 ((BooleanLocation) location).setAsBoolean((Boolean) value);
 92  0
                 break;
 93  
             case SEQUENCE:
 94  2
                 ((SequenceLocation) location).setAsSequence((Sequence) value);
 95  2
                 break;
 96  
             case OBJECT:
 97  1
                 ((ObjectLocation) location).set(value);
 98  
                 break;
 99  
         }
 100  110
     }
 101  
 
 102  
     public Object getValue() {
 103  0
         return get();
 104  
     }
 105  
 
 106  
     public void setValue(Object o) {
 107  0
         set(o);
 108  0
     }
 109  
 
 110  
     @Override
 111  
     public boolean equals(Object o) {
 112  50
         if (this == o)
 113  7
             return true;
 114  
         else
 115  43
             return (o instanceof Pointer)
 116  
                     && Locations.getUnderlyingLocation(location) == Locations.getUnderlyingLocation(((Pointer) o).location);
 117  
     }
 118  
 
 119  
     @Override
 120  
     public int hashCode() {
 121  14
         Location loc = Locations.getUnderlyingLocation(location);
 122  14
         return loc != null ? loc.hashCode() : 0;
 123  
     }
 124  
 }