1 11 package org.eclipse.core.internal.indexing; 12 13 public class ObjectAddress implements Insertable { 14 15 public static final int Size = 4; 16 public static ObjectAddress Null = new ObjectAddress(0, 0); 17 private static final int PageNumberOffset = 0; 18 private static final int ObjectNumberOffset = 3; 19 private int pageNumber; 20 private int objectNumber; 21 22 25 public ObjectAddress(byte[] b) throws IllegalArgumentException { 26 if (b.length != Size) 27 throw new IllegalArgumentException (); 28 Buffer buf = new Buffer(b); 29 pageNumber = buf.getUInt(PageNumberOffset, 3); 30 objectNumber = buf.getUInt(ObjectNumberOffset, 1); 31 } 32 33 36 public ObjectAddress(int pageNumber, int objectNumber) throws IllegalArgumentException { 37 if (pageNumber == 0 && objectNumber == 0) { 38 this.pageNumber = 0; 39 this.objectNumber = 0; 40 return; 41 } 42 if (pageNumber < 0 || pageNumber > 0xFFFFFF) 43 throw new IllegalArgumentException (); 44 if (pageNumber % ObjectStorePage.SIZE == 0) 45 throw new IllegalArgumentException (); 46 if (objectNumber < 0 || objectNumber > 0xFF) 47 throw new IllegalArgumentException (); 48 this.pageNumber = pageNumber; 49 this.objectNumber = objectNumber; 50 } 51 52 55 public boolean equals(Object anObject) { 56 if (!(anObject instanceof ObjectAddress)) 57 return false; 58 ObjectAddress address = (ObjectAddress) anObject; 59 if (pageNumber != address.pageNumber) 60 return false; 61 if (objectNumber != address.objectNumber) 62 return false; 63 return true; 64 } 65 66 69 public int getObjectNumber() { 70 return objectNumber; 71 } 72 73 76 public int getPageNumber() { 77 return pageNumber; 78 } 79 80 83 public int hashCode() { 84 return (pageNumber << 8) | objectNumber; 85 } 86 87 90 public boolean isNull() { 91 return (pageNumber == 0 && objectNumber == 0); 92 } 93 94 97 public byte[] toByteArray() { 98 Buffer buf = new Buffer(Size); 99 buf.put(PageNumberOffset, 3, pageNumber); 100 buf.put(ObjectNumberOffset, 1, objectNumber); 101 return buf.get(); 102 } 103 } 104 | Popular Tags |