31 * This class represents a property map that can be shared among multiple prototype objects, allowing all inheriting 32 * top-level objects to also share one property map. This class is only used for prototype objects, the 33 * top-level objects use ordinary {@link PropertyMap}s with the {@link PropertyMap#sharedProtoMap} field 34 * set to the expected shared prototype map. 35 * 36 * <p>When an instance of this class is evolved because a property is added, removed, or modified in an object 37 * using it, the {@link #invalidateSwitchPoint()} method is invoked to signal to all callsites and inheriting 38 * objects that the assumption of a single shared prototype map is no longer valid. The property map resulting 39 * from the modification will no longer be an instance of this class.</p> 40 */ 41 public final class SharedPropertyMap extends PropertyMap { 42 43 private SwitchPoint switchPoint; 44 45 private static final long serialVersionUID = 2166297719721778876L; 46 47 /** 48 * Create a new shared property map from the given {@code map}. 49 * @param map property map to copy 50 */ 51 public SharedPropertyMap(final PropertyMap map) { 52 super(map); 53 this.switchPoint = new SwitchPoint(); 54 } 55 56 @Override 57 public void propertyAdded(final Property property, final boolean isSelf) { 58 if (isSelf) { 59 invalidateSwitchPoint(); 60 } 61 super.propertyAdded(property, isSelf); 62 } 63 64 @Override 65 public void propertyDeleted(final Property property, final boolean isSelf) { 66 if (isSelf) { 67 invalidateSwitchPoint(); 68 } 69 super.propertyDeleted(property, isSelf); 70 } 71 72 @Override 73 public void propertyModified(final Property oldProperty, final Property newProperty, final boolean isSelf) { 74 if (isSelf) { 75 invalidateSwitchPoint(); 76 } 77 super.propertyModified(oldProperty, newProperty, isSelf); 78 } 79 80 @Override 81 synchronized boolean isValidSharedProtoMap() { 82 return switchPoint != null; 83 } 84 85 @Override 86 synchronized SwitchPoint getSharedProtoSwitchPoint() { 87 return switchPoint; 88 } 89 90 /** 91 * Invalidate the shared prototype switch point if this is a shared prototype map. 92 */ 93 synchronized void invalidateSwitchPoint() { 94 if (switchPoint != null) { 95 assert !switchPoint.hasBeenInvalidated(); 96 SwitchPoint.invalidateAll(new SwitchPoint[]{ switchPoint }); 97 switchPoint = null; | 31 * This class represents a property map that can be shared among multiple prototype objects, allowing all inheriting 32 * top-level objects to also share one property map. This class is only used for prototype objects, the 33 * top-level objects use ordinary {@link PropertyMap}s with the {@link PropertyMap#sharedProtoMap} field 34 * set to the expected shared prototype map. 35 * 36 * <p>When an instance of this class is evolved because a property is added, removed, or modified in an object 37 * using it, the {@link #invalidateSwitchPoint()} method is invoked to signal to all callsites and inheriting 38 * objects that the assumption of a single shared prototype map is no longer valid. The property map resulting 39 * from the modification will no longer be an instance of this class.</p> 40 */ 41 public final class SharedPropertyMap extends PropertyMap { 42 43 private SwitchPoint switchPoint; 44 45 private static final long serialVersionUID = 2166297719721778876L; 46 47 /** 48 * Create a new shared property map from the given {@code map}. 49 * @param map property map to copy 50 */ 51 SharedPropertyMap(final PropertyMap map) { 52 super(map); 53 this.switchPoint = new SwitchPoint(); 54 } 55 56 @Override 57 public void invalidateProperty(final Property property) { 58 invalidateSwitchPoint(); 59 super.invalidateProperty(property); 60 } 61 62 @Override 63 synchronized boolean isValidSharedProtoMap() { 64 return switchPoint != null; 65 } 66 67 @Override 68 synchronized SwitchPoint getSharedProtoSwitchPoint() { 69 return switchPoint; 70 } 71 72 /** 73 * Invalidate the shared prototype switch point if this is a shared prototype map. 74 */ 75 synchronized void invalidateSwitchPoint() { 76 if (switchPoint != null) { 77 assert !switchPoint.hasBeenInvalidated(); 78 SwitchPoint.invalidateAll(new SwitchPoint[]{ switchPoint }); 79 switchPoint = null; |