1 11 package org.eclipse.core.internal.registry; 12 13 17 public abstract class RegistryObject implements KeyedElement { 18 private int objectId = RegistryObjectManager.UNKNOWN; 20 protected int[] children = RegistryObjectManager.EMPTY_INT_ARRAY; 22 23 private int extraDataOffset = EMPTY_MASK; 25 26 static final int EMPTY_MASK = 0x80000000; static final int PERSIST_MASK = 0x40000000; static final int OFFSET_MASK = 0x3FFFFFFF; 35 protected ExtensionRegistry registry; 37 38 protected RegistryObject(ExtensionRegistry registry, boolean persist) { 39 this.registry = registry; 40 setPersist(persist); 41 } 42 43 void setRawChildren(int[] values) { 44 children = values; 45 } 46 47 protected int[] getRawChildren() { 49 return children; 50 } 51 52 void setObjectId(int value) { 53 objectId = value; 54 } 55 56 protected int getObjectId() { 57 return objectId; 58 } 59 60 public int getKeyHashCode() { 62 return objectId; 63 } 64 65 public Object getKey() { 66 return new Integer (objectId); 67 } 68 69 public boolean compare(KeyedElement other) { 70 return objectId == ((RegistryObject) other).objectId; 71 } 72 73 protected boolean shouldPersist() { 74 return (extraDataOffset & PERSIST_MASK) == PERSIST_MASK; 75 } 76 77 private void setPersist(boolean persist) { 78 if (persist) 79 extraDataOffset |= PERSIST_MASK; 80 else 81 extraDataOffset &= ~PERSIST_MASK; 82 } 83 84 protected boolean noExtraData() { 85 return (extraDataOffset & EMPTY_MASK) == EMPTY_MASK; 86 } 87 88 protected int getExtraDataOffset() { 90 if (noExtraData()) 91 return -1; 92 return extraDataOffset & OFFSET_MASK; 93 } 94 95 protected void setExtraDataOffset(int offset) { 97 if (offset == -1) { 98 extraDataOffset &=~OFFSET_MASK; extraDataOffset |= EMPTY_MASK; 100 return; 101 } 102 103 if ((offset & OFFSET_MASK) != offset) 104 throw new IllegalArgumentException ("Registry object: extra data offset is out of range"); 106 extraDataOffset &=~(OFFSET_MASK | EMPTY_MASK) ; extraDataOffset |= (offset & OFFSET_MASK); } 109 } 110 | Popular Tags |