You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2015/03/15 13:47:00 UTC
svn commit: r1666796 - in
/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure:
PDMarkInfo.java PDMarkedContentReference.java PDObjectReference.java
PDUserProperty.java
Author: tilman
Date: Sun Mar 15 12:47:00 2015
New Revision: 1666796
URL: http://svn.apache.org/r1666796
Log:
PDFBOX-2576: add hash and equals, as suggested by Martin Schröder
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDMarkInfo.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDMarkedContentReference.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDObjectReference.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDUserProperty.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDMarkInfo.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDMarkInfo.java?rev=1666796&r1=1666795&r2=1666796&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDMarkInfo.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDMarkInfo.java Sun Mar 15 12:47:00 2015
@@ -54,6 +54,7 @@ public class PDMarkInfo implements COSOb
*
* @return The cos object that matches this Java object.
*/
+ @Override
public COSBase getCOSObject()
{
return dictionary;
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDMarkedContentReference.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDMarkedContentReference.java?rev=1666796&r1=1666795&r2=1666796&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDMarkedContentReference.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDMarkedContentReference.java Sun Mar 15 12:47:00 2015
@@ -1,123 +1,124 @@
-/*
- * 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.pdmodel.documentinterchange.logicalstructure;
-
-import org.apache.pdfbox.cos.COSBase;
-import org.apache.pdfbox.cos.COSDictionary;
-import org.apache.pdfbox.cos.COSName;
-import org.apache.pdfbox.pdmodel.PDPage;
-import org.apache.pdfbox.pdmodel.common.COSObjectable;
-
-/**
- * A marked-content reference.
- *
- * @author Johannes Koch
- */
-public class PDMarkedContentReference implements COSObjectable
-{
-
- public static final String TYPE = "MCR";
-
- private COSDictionary dictionary;
-
- protected COSDictionary getCOSDictionary()
- {
- return this.dictionary;
- }
-
- /**
- * Default constructor
- */
- public PDMarkedContentReference()
- {
- this.dictionary = new COSDictionary();
- this.dictionary.setName(COSName.TYPE, TYPE);
- }
-
- /**
- * Constructor for an existing marked content reference.
- *
- * @param dictionary the page dictionary
- */
- public PDMarkedContentReference(COSDictionary dictionary)
- {
- this.dictionary = dictionary;
- }
-
- /**
- * {@inheritDoc}
- */
- public COSBase getCOSObject()
- {
- return this.dictionary;
- }
-
- /**
- * Gets the page.
- *
- * @return the page
- */
- public PDPage getPage()
- {
- COSDictionary pg = (COSDictionary) this.getCOSDictionary()
- .getDictionaryObject(COSName.PG);
- if (pg != null)
- {
- return new PDPage(pg);
- }
- return null;
- }
-
- /**
- * Sets the page.
- *
- * @param page the page
- */
- public void setPage(PDPage page)
- {
- this.getCOSDictionary().setItem(COSName.PG, page);
- }
-
- /**
- * Gets the marked content identifier.
- *
- * @return the marked content identifier
- */
- public int getMCID()
- {
- return this.getCOSDictionary().getInt(COSName.MCID);
- }
-
- /**
- * Sets the marked content identifier.
- *
- * @param mcid the marked content identifier
- */
- public void setMCID(int mcid)
- {
- this.getCOSDictionary().setInt(COSName.MCID, mcid);
- }
-
-
- @Override
- public String toString()
- {
- return new StringBuilder()
- .append("mcid=").append(this.getMCID()).toString();
- }
-
-}
+/*
+ * 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.pdmodel.documentinterchange.logicalstructure;
+
+import org.apache.pdfbox.cos.COSBase;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdmodel.PDPage;
+import org.apache.pdfbox.pdmodel.common.COSObjectable;
+
+/**
+ * A marked-content reference.
+ *
+ * @author Johannes Koch
+ */
+public class PDMarkedContentReference implements COSObjectable
+{
+
+ public static final String TYPE = "MCR";
+
+ private COSDictionary dictionary;
+
+ protected COSDictionary getCOSDictionary()
+ {
+ return this.dictionary;
+ }
+
+ /**
+ * Default constructor
+ */
+ public PDMarkedContentReference()
+ {
+ this.dictionary = new COSDictionary();
+ this.dictionary.setName(COSName.TYPE, TYPE);
+ }
+
+ /**
+ * Constructor for an existing marked content reference.
+ *
+ * @param dictionary the page dictionary
+ */
+ public PDMarkedContentReference(COSDictionary dictionary)
+ {
+ this.dictionary = dictionary;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public COSBase getCOSObject()
+ {
+ return this.dictionary;
+ }
+
+ /**
+ * Gets the page.
+ *
+ * @return the page
+ */
+ public PDPage getPage()
+ {
+ COSDictionary pg = (COSDictionary) this.getCOSDictionary()
+ .getDictionaryObject(COSName.PG);
+ if (pg != null)
+ {
+ return new PDPage(pg);
+ }
+ return null;
+ }
+
+ /**
+ * Sets the page.
+ *
+ * @param page the page
+ */
+ public void setPage(PDPage page)
+ {
+ this.getCOSDictionary().setItem(COSName.PG, page);
+ }
+
+ /**
+ * Gets the marked content identifier.
+ *
+ * @return the marked content identifier
+ */
+ public int getMCID()
+ {
+ return this.getCOSDictionary().getInt(COSName.MCID);
+ }
+
+ /**
+ * Sets the marked content identifier.
+ *
+ * @param mcid the marked content identifier
+ */
+ public void setMCID(int mcid)
+ {
+ this.getCOSDictionary().setInt(COSName.MCID, mcid);
+ }
+
+
+ @Override
+ public String toString()
+ {
+ return new StringBuilder()
+ .append("mcid=").append(this.getMCID()).toString();
+ }
+
+}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDObjectReference.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDObjectReference.java?rev=1666796&r1=1666795&r2=1666796&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDObjectReference.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDObjectReference.java Sun Mar 15 12:47:00 2015
@@ -1,144 +1,145 @@
-/*
- * 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.pdmodel.documentinterchange.logicalstructure;
-
-import java.io.IOException;
-
-import org.apache.pdfbox.cos.COSBase;
-import org.apache.pdfbox.cos.COSDictionary;
-import org.apache.pdfbox.cos.COSName;
-import org.apache.pdfbox.pdmodel.common.COSObjectable;
-import org.apache.pdfbox.pdmodel.graphics.PDXObject;
-import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation;
-import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationUnknown;
-
-/**
- * An object reference.
- *
- * @author Johannes Koch
- */
-public class PDObjectReference implements COSObjectable
-{
-
- /**
- * TYPE of this object.
- */
- public static final String TYPE = "OBJR";
-
- private COSDictionary dictionary;
-
- /**
- * Returns the underlying dictionary.
- *
- * @return the dictionary
- */
- protected COSDictionary getCOSDictionary()
- {
- return this.dictionary;
- }
-
- /**
- * Default Constructor.
- *
- */
- public PDObjectReference()
- {
- this.dictionary = new COSDictionary();
- this.dictionary.setName(COSName.TYPE, TYPE);
- }
-
- /**
- * Constructor for an existing object reference.
- *
- * @param theDictionary The existing dictionary.
- */
- public PDObjectReference(COSDictionary theDictionary)
- {
- dictionary = theDictionary;
- }
-
- /**
- * {@inheritDoc}
- */
- public COSBase getCOSObject()
- {
- return this.dictionary;
- }
-
- /**
- * Gets a higher-level object for the referenced object.
- * Currently this method may return a {@link PDAnnotation},
- * a {@link PDXObject} or <code>null</code>.
- *
- * @return a higher-level object for the referenced object
- */
- public COSObjectable getReferencedObject()
- {
- COSBase obj = this.getCOSDictionary().getDictionaryObject(COSName.OBJ);
- if (!(obj instanceof COSDictionary))
- {
- return null;
- }
- try
- {
- PDXObject xobject = PDXObject.createXObject(obj, null, null); // <-- TODO: valid?
- if (xobject != null)
- {
- return xobject;
- }
- COSDictionary objDictionary = (COSDictionary)obj;
- PDAnnotation annotation = PDAnnotation.createAnnotation(obj);
- /*
- * COSName.TYPE is optional, so if annotation is of type unknown and
- * COSName.TYPE is not COSName.ANNOT it still may be an annotation.
- * TODO shall we return the annotation object instead of null?
- * what else can be the target of the object reference?
- */
- if (!(annotation instanceof PDAnnotationUnknown)
- || COSName.ANNOT.equals(objDictionary.getDictionaryObject(COSName.TYPE)))
- {
- return annotation;
- }
- }
- catch (IOException exception)
- {
- // this can only happen if the target is an XObject.
- }
- return null;
- }
-
- /**
- * Sets the referenced annotation.
- *
- * @param annotation the referenced annotation
- */
- public void setReferencedObject(PDAnnotation annotation)
- {
- this.getCOSDictionary().setItem(COSName.OBJ, annotation);
- }
-
- /**
- * Sets the referenced XObject.
- *
- * @param xobject the referenced XObject
- */
- public void setReferencedObject(PDXObject xobject)
- {
- this.getCOSDictionary().setItem(COSName.OBJ, xobject);
- }
-
-}
+/*
+ * 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.pdmodel.documentinterchange.logicalstructure;
+
+import java.io.IOException;
+
+import org.apache.pdfbox.cos.COSBase;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdmodel.common.COSObjectable;
+import org.apache.pdfbox.pdmodel.graphics.PDXObject;
+import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation;
+import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationUnknown;
+
+/**
+ * An object reference.
+ *
+ * @author Johannes Koch
+ */
+public class PDObjectReference implements COSObjectable
+{
+
+ /**
+ * TYPE of this object.
+ */
+ public static final String TYPE = "OBJR";
+
+ private COSDictionary dictionary;
+
+ /**
+ * Returns the underlying dictionary.
+ *
+ * @return the dictionary
+ */
+ protected COSDictionary getCOSDictionary()
+ {
+ return this.dictionary;
+ }
+
+ /**
+ * Default Constructor.
+ *
+ */
+ public PDObjectReference()
+ {
+ this.dictionary = new COSDictionary();
+ this.dictionary.setName(COSName.TYPE, TYPE);
+ }
+
+ /**
+ * Constructor for an existing object reference.
+ *
+ * @param theDictionary The existing dictionary.
+ */
+ public PDObjectReference(COSDictionary theDictionary)
+ {
+ dictionary = theDictionary;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public COSBase getCOSObject()
+ {
+ return this.dictionary;
+ }
+
+ /**
+ * Gets a higher-level object for the referenced object.
+ * Currently this method may return a {@link PDAnnotation},
+ * a {@link PDXObject} or <code>null</code>.
+ *
+ * @return a higher-level object for the referenced object
+ */
+ public COSObjectable getReferencedObject()
+ {
+ COSBase obj = this.getCOSDictionary().getDictionaryObject(COSName.OBJ);
+ if (!(obj instanceof COSDictionary))
+ {
+ return null;
+ }
+ try
+ {
+ PDXObject xobject = PDXObject.createXObject(obj, null, null); // <-- TODO: valid?
+ if (xobject != null)
+ {
+ return xobject;
+ }
+ COSDictionary objDictionary = (COSDictionary)obj;
+ PDAnnotation annotation = PDAnnotation.createAnnotation(obj);
+ /*
+ * COSName.TYPE is optional, so if annotation is of type unknown and
+ * COSName.TYPE is not COSName.ANNOT it still may be an annotation.
+ * TODO shall we return the annotation object instead of null?
+ * what else can be the target of the object reference?
+ */
+ if (!(annotation instanceof PDAnnotationUnknown)
+ || COSName.ANNOT.equals(objDictionary.getDictionaryObject(COSName.TYPE)))
+ {
+ return annotation;
+ }
+ }
+ catch (IOException exception)
+ {
+ // this can only happen if the target is an XObject.
+ }
+ return null;
+ }
+
+ /**
+ * Sets the referenced annotation.
+ *
+ * @param annotation the referenced annotation
+ */
+ public void setReferencedObject(PDAnnotation annotation)
+ {
+ this.getCOSDictionary().setItem(COSName.OBJ, annotation);
+ }
+
+ /**
+ * Sets the referenced XObject.
+ *
+ * @param xobject the referenced XObject
+ */
+ public void setReferencedObject(PDXObject xobject)
+ {
+ this.getCOSDictionary().setItem(COSName.OBJ, xobject);
+ }
+
+}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDUserProperty.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDUserProperty.java?rev=1666796&r1=1666795&r2=1666796&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDUserProperty.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDUserProperty.java Sun Mar 15 12:47:00 2015
@@ -183,4 +183,34 @@ public class PDUserProperty extends PDDi
return !oldEntry.equals(newEntry);
}
-}
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result
+ + ((userAttributeObject == null) ? 0 : userAttributeObject.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ return true;
+ if (!super.equals(obj))
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ PDUserProperty other = (PDUserProperty) obj;
+ if (userAttributeObject == null)
+ {
+ if (other.userAttributeObject != null)
+ return false;
+ }
+ else if (!userAttributeObject.equals(other.userAttributeObject))
+ return false;
+ return true;
+ }
+
+}
\ No newline at end of file