/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.pdfbox.cos;

/**
 * Object representing the physical reference to an indirect pdf object.
 *
 * @author Michael Traut
 * @version $Revision: 1.5 $
 */
public class COSObjectKey implements Comparable<COSObjectKey>
{
    private long number;
    private long generation;

    /**
     * PDFObjectKey constructor comment.
     *
     * @param object The object that this key will represent.
     */
    public COSObjectKey(COSObject object)
    {
        this( object.getObjectNumber().longValue(), object.getGenerationNumber().longValue() );
    }

    /**
     * PDFObjectKey constructor comment.
     *
     * @param num The object number.
     * @param gen The object generation number.
     */
    public COSObjectKey(long num, long gen)
    {
        number = num;
        generation = gen;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean equals(Object obj)
    {
        return (obj instanceof COSObjectKey) &&
               ((COSObjectKey)obj).getNumber() == getNumber() &&
               ((COSObjectKey)obj).getGeneration() == getGeneration();
    }

    /**
     * This will get the generation number.
     *
     * @return The objects generation number.
     */
    public long getGeneration()
    {
        return generation;
    }
    /**
     * This will get the objects id.
     *
     * @return The object's id.
     */
    public long getNumber()
    {
        return number;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int hashCode()
    {
        return (int)(number + generation);
    }
    /**
     * This will set the objects generation number.
     *
     * @param newGeneration The objects generation number.
     */
    public void setGeneration(long newGeneration)
    {
        generation = newGeneration;
    }
    /**
     * This will set the objects id.
     *
     * @param newNumber The objects number.
     */
    public void setNumber(long newNumber)
    {
        number = newNumber;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString()
    {
        return "" + getNumber() + " " + getGeneration() + " R";
    }

    /** {@inheritDoc} */
    @Override
    public int compareTo(COSObjectKey other)
    {
        if (getNumber() < other.getNumber())
        {
            return -1;
        }
        else if (getNumber() > other.getNumber())
        {
            return 1;
        }
        else
        {
            if (getGeneration() < other.getGeneration())
            {
                return -1;
            }
            else if (getGeneration() > other.getGeneration())
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
    }

}

@@ -3053,103 +3053,39 @@
    i
-f (getNumber() %3C other.getNumber())%0A        %7B%0A            return -1;%0A        %7D%0A        else if 
+nt compareNumber = Long.compare
 (get
@@ -3092,18 +3092,17 @@
 Number()
- %3E
+,
  other.g
@@ -3116,129 +3116,40 @@
 r())
-%0A        %7B%0A            return 1;%0A        %7D%0A        else%0A        %7B%0A            if (getGeneration() %3C other.getGeneration()
+;%0A        if (compareNumber == 0
 )%0A  
@@ -3150,32 +3150,26 @@
  0)%0A        
-    %7B%0A  
+%7B%0A
             
@@ -3172,55 +3172,27 @@
     
-  
 return 
--1;%0A            %7D%0A            else if 
+Long.compare
 (get
@@ -3207,10 +3207,9 @@
 on()
- %3E
+,
  oth
@@ -3227,16 +3227,17 @@
 ation())
+;
 %0A       
@@ -3229,37 +3229,33 @@
 ion());%0A        
-    %7B
+%7D
 %0A               
@@ -3251,120 +3251,29 @@
     
-        return 1;%0A            %7D%0A            else%0A            %7B%0A                return 0;%0A            %7D%0A        %7D
+return compareNumber;
 %0A   

simplify compare, as suggested by Andrea Vacondio