1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.pdfbox.persistence.util; 18 19 import org.apache.pdfbox.cos.COSObject; 20 21 /** 22 * Object representing the physical reference to an indirect pdf object. 23 * 24 * @author Michael Traut 25 * @version $Revision: 1.5 $ 26 */ 27 public class COSObjectKey 28 { 29 private long number; 30 private long generation; 31 32 /** 33 * PDFObjectKey constructor comment. 34 * 35 * @param object The object that this key will represent. 36 */ 37 public COSObjectKey(COSObject object) 38 { 39 this( object.getObjectNumber().longValue(), object.getGenerationNumber().longValue() ); 40 } 41 42 /** 43 * PDFObjectKey constructor comment. 44 * 45 * @param num The object number. 46 * @param gen The object generation number. 47 */ 48 public COSObjectKey(long num, long gen) 49 { 50 setNumber(num); 51 setGeneration(gen); 52 } 53 54 /** 55 * {@inheritDoc} 56 */ 57 public boolean equals(Object obj) 58 { 59 return (obj instanceof COSObjectKey) && 60 ((COSObjectKey)obj).getNumber() == getNumber() && 61 ((COSObjectKey)obj).getGeneration() == getGeneration(); 62 } 63 64 /** 65 * This will get the generation number. 66 * 67 * @return The objects generation number. 68 */ 69 public long getGeneration() 70 { 71 return generation; 72 } 73 /** 74 * This will get the objects id. 75 * 76 * @return The object's id. 77 */ 78 public long getNumber() 79 { 80 return number; 81 } 82 83 /** 84 * {@inheritDoc} 85 */ 86 public int hashCode() 87 { 88 return (int)(number + generation); 89 } 90 /** 91 * This will set the objects generation number. 92 * 93 * @param newGeneration The objects generation number. 94 */ 95 public void setGeneration(long newGeneration) 96 { 97 generation = newGeneration; 98 } 99 /** 100 * This will set the objects id. 101 * 102 * @param newNumber The objects number. 103 */ 104 public void setNumber(long newNumber) 105 { 106 number = newNumber; 107 } 108 109 /** 110 * {@inheritDoc} 111 */ 112 public String toString() 113 { 114 return "" + getNumber() + " " + getGeneration() + " R"; 115 } 116 }