001: /**
002: * Copyright (c) 2003-2006, www.pdfbox.org
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions are met:
007: *
008: * 1. Redistributions of source code must retain the above copyright notice,
009: * this list of conditions and the following disclaimer.
010: * 2. Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: * 3. Neither the name of pdfbox; nor the names of its
014: * contributors may be used to endorse or promote products derived from this
015: * software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
018: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
019: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
020: * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
021: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
022: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
023: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
024: * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
025: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
026: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027: *
028: * http://www.pdfbox.org
029: *
030: */package org.pdfbox.persistence.util;
031:
032: import org.pdfbox.cos.COSObject;
033:
034: /**
035: * Object representing the physical reference to an indirect pdf object.
036: *
037: * @author Michael Traut
038: * @version $Revision: 1.5 $
039: */
040: public class COSObjectKey {
041: private long number;
042: private long generation;
043:
044: /**
045: * PDFObjectKey constructor comment.
046: *
047: * @param object The object that this key will represent.
048: */
049: public COSObjectKey(COSObject object) {
050: this (object.getObjectNumber().longValue(), object
051: .getGenerationNumber().longValue());
052: }
053:
054: /**
055: * PDFObjectKey constructor comment.
056: *
057: * @param num The object number.
058: * @param gen The object generation number.
059: */
060: public COSObjectKey(long num, long gen) {
061: setNumber(num);
062: setGeneration(gen);
063: }
064:
065: /**
066: * {@inheritDoc}
067: */
068: public boolean equals(Object obj) {
069: return (obj instanceof COSObjectKey)
070: && ((COSObjectKey) obj).getNumber() == getNumber()
071: && ((COSObjectKey) obj).getGeneration() == getGeneration();
072: }
073:
074: /**
075: * This will get the generation number.
076: *
077: * @return The objects generation number.
078: */
079: public long getGeneration() {
080: return generation;
081: }
082:
083: /**
084: * This will get the objects id.
085: *
086: * @return The object's id.
087: */
088: public long getNumber() {
089: return number;
090: }
091:
092: /**
093: * {@inheritDoc}
094: */
095: public int hashCode() {
096: return (int) (number + generation);
097: }
098:
099: /**
100: * This will set the objects generation number.
101: *
102: * @param newGeneration The objects generation number.
103: */
104: public void setGeneration(long newGeneration) {
105: generation = newGeneration;
106: }
107:
108: /**
109: * This will set the objects id.
110: *
111: * @param newNumber The objects number.
112: */
113: public void setNumber(long newNumber) {
114: number = newNumber;
115: }
116:
117: /**
118: * {@inheritDoc}
119: */
120: public String toString() {
121: return "" + getNumber() + " " + getGeneration() + " R";
122: }
123: }
|