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 2020/05/08 09:20:18 UTC
svn commit: r1877505 - in
/pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox: XMPMetadata.java
type/ComplexPropertyContainer.java
Author: tilman
Date: Fri May 8 09:20:18 2020
New Revision: 1877505
URL: http://svn.apache.org/viewvc?rev=1877505&view=rev
Log:
PDFBOX-4071: use jdk8 functional syntax; simplify code
Modified:
pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/XMPMetadata.java
pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/type/ComplexPropertyContainer.java
Modified: pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/XMPMetadata.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/XMPMetadata.java?rev=1877505&r1=1877504&r2=1877505&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/XMPMetadata.java (original)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/XMPMetadata.java Fri May 8 09:20:18 2020
@@ -169,18 +169,13 @@ public class XMPMetadata
}
/**
- * Get All Schemas declared in this metadata representation.
+ * Get all Schemas declared in this metadata representation.
*
* @return List of declared schemas
*/
public List<XMPSchema> getAllSchemas()
{
- List<XMPSchema> schem = new ArrayList<>();
- for (XMPSchema schema : schemas)
- {
- schem.add(schema);
- }
- return schem;
+ return new ArrayList<>(schemas);
}
/**
Modified: pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/type/ComplexPropertyContainer.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/type/ComplexPropertyContainer.java?rev=1877505&r1=1877504&r2=1877505&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/type/ComplexPropertyContainer.java (original)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/type/ComplexPropertyContainer.java Fri May 8 09:20:18 2020
@@ -24,6 +24,7 @@ package org.apache.xmpbox.type;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.stream.Collectors;
/**
* Object representation for arrays content This Class could be used to define directly a property with more than one
@@ -89,7 +90,7 @@ public class ComplexPropertyContainer
/**
* Return all children associated to this property
*
- * @return All Properties contained in this container
+ * @return All Properties contained in this container, never null.
*/
public List<AbstractField> getAllProperties()
{
@@ -98,34 +99,25 @@ public class ComplexPropertyContainer
/**
* Return all properties with this specified localName.
- *
- * @param localName
- * the local name wanted
- * @return All properties with local name which match with localName given, or null if there are none.
+ *
+ * @param localName the local name wanted
+ * @return All properties with local name which match with localName given, or null if there are
+ * none.
*/
public List<AbstractField> getPropertiesByLocalName(String localName)
{
- List<AbstractField> absFields = getAllProperties();
- if (absFields != null)
+ List<AbstractField> list =
+ getAllProperties().stream().
+ filter(abstractField -> (abstractField.getPropertyName().equals(localName))).
+ collect(Collectors.toList());
+ if (list.isEmpty())
{
- List<AbstractField> list = new ArrayList<>();
- for (AbstractField abstractField : absFields)
- {
- if (abstractField.getPropertyName().equals(localName))
- {
- list.add(abstractField);
- }
- }
- if (list.isEmpty())
- {
- return null;
- }
- else
- {
- return list;
- }
+ return null;
+ }
+ else
+ {
+ return list;
}
- return null;
}
/**
@@ -211,9 +203,6 @@ public class ComplexPropertyContainer
{
return;
}
- for (AbstractField field : propList)
- {
- properties.remove(field);
- }
+ propList.forEach(properties::remove);
}
}