1 4 package com.tc.object.dna.api; 5 6 9 public class PhysicalAction { 10 private final String field; 11 private final Object value; 12 private final int index; 13 private final boolean isReference; 14 private final int type; 15 16 private static final int TRUE_PHYSICAL = 1; 17 private static final int ARRAY_ELEMENT = 2; 18 private static final int ENTIRE_ARRAY = 3; 19 private static final int SUB_ARRAY = 4; 20 21 23 public PhysicalAction(Object value) { 24 this(null, -1, value, false, ENTIRE_ARRAY); 25 } 26 27 public PhysicalAction(Object value, int startPos) { 28 this(null, startPos, value, false, SUB_ARRAY); 29 } 30 31 public PhysicalAction(int index, Object value, boolean isReference) { 32 this(null, index, value, isReference, ARRAY_ELEMENT); 33 } 34 35 public PhysicalAction(String field, Object value, boolean isReference) { 36 this(field, -1, value, isReference, TRUE_PHYSICAL); 37 } 38 39 private PhysicalAction(String field, int index, Object value, boolean isReference, int type) { 40 this.field = field; 41 this.index = index; 42 this.value = value; 43 this.isReference = isReference; 44 this.type = type; 45 } 46 47 public String getFieldName() { 48 if (type != TRUE_PHYSICAL) { throw new IllegalStateException (String.valueOf(type)); } 49 50 return this.field; 51 } 52 53 public Object getObject() { 54 return this.value; 55 } 56 57 public boolean isReference() { 58 return isReference; 59 } 60 61 public int getArrayIndex() { 62 if (!((type == ARRAY_ELEMENT) || (type == SUB_ARRAY))) { throw new IllegalStateException (String.valueOf(type)); } 63 return this.index; 64 } 65 66 public boolean isTruePhysical() { 67 return type == TRUE_PHYSICAL; 68 } 69 70 public boolean isArrayElement() { 71 return type == ARRAY_ELEMENT; 72 } 73 74 public boolean isEntireArray() { 75 return type == ENTIRE_ARRAY; 76 } 77 78 public boolean isSubArray() { 79 return type == SUB_ARRAY; 80 } 81 82 } | Popular Tags |