This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag org.apache.sling.testing.jcr-mock-1.1.0 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-jcr-mock.git
commit d585caf48f9b543d61863e769ef765405740da83 Author: Stefan Seifert <[email protected]> AuthorDate: Thu Oct 16 19:02:45 2014 +0000 SLING-4042 minor optimization git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/jcr-mock@1632413 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/sling/testing/mock/jcr/AbstractItem.java | 20 ++++++++++---------- .../org/apache/sling/testing/mock/jcr/ItemData.java | 4 +++- .../org/apache/sling/testing/mock/jcr/MockNode.java | 5 +---- .../apache/sling/testing/mock/jcr/MockProperty.java | 5 +---- 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/apache/sling/testing/mock/jcr/AbstractItem.java b/src/main/java/org/apache/sling/testing/mock/jcr/AbstractItem.java index 0eb92f3..f174514 100644 --- a/src/main/java/org/apache/sling/testing/mock/jcr/AbstractItem.java +++ b/src/main/java/org/apache/sling/testing/mock/jcr/AbstractItem.java @@ -32,27 +32,27 @@ import org.apache.commons.lang3.StringUtils; */ abstract class AbstractItem implements Item { - private final String path; + protected final ItemData itemData; private final Session session; - public AbstractItem(final String path, final Session session) { - this.path = path; + public AbstractItem(final ItemData itemData, final Session session) { + this.itemData = itemData; this.session = session; } @Override public String getName() { - return ResourceUtil.getName(this.path); + return this.itemData.getName(); } @Override public String getPath() { - return this.path; + return this.itemData.getPath(); } @Override public Node getParent() throws RepositoryException { - return (Node) getSession().getItem(ResourceUtil.getParent(this.path)); + return (Node) getSession().getItem(ResourceUtil.getParent(getPath())); } @Override @@ -75,14 +75,14 @@ abstract class AbstractItem implements Item { if (depth < 0 || depth > getDepth()) { throw new ItemNotFoundException(); } - return this.session.getItem(ResourceUtil.getParent(this.path, depth)); + return this.session.getItem(ResourceUtil.getParent(getPath(), depth)); } protected String makeAbsolutePath(final String relativePath) { String absolutePath = relativePath; // ensure the path is absolute and normalized if (!StringUtils.startsWith(absolutePath, "/")) { - absolutePath = this.path + "/" + absolutePath; // NOPMD + absolutePath = getPath() + "/" + absolutePath; // NOPMD } return ResourceUtil.normalize(absolutePath); } @@ -98,10 +98,10 @@ abstract class AbstractItem implements Item { @Override public int getDepth() throws RepositoryException { - if (StringUtils.equals("/", this.path)) { + if (StringUtils.equals("/", getPath())) { return 0; } else { - return StringUtils.countMatches(this.path, "/"); + return StringUtils.countMatches(getPath(), "/"); } } diff --git a/src/main/java/org/apache/sling/testing/mock/jcr/ItemData.java b/src/main/java/org/apache/sling/testing/mock/jcr/ItemData.java index 21b2678..64ec7c1 100644 --- a/src/main/java/org/apache/sling/testing/mock/jcr/ItemData.java +++ b/src/main/java/org/apache/sling/testing/mock/jcr/ItemData.java @@ -31,6 +31,7 @@ import javax.jcr.nodetype.NodeType; class ItemData { private final String path; + private final String name; private final boolean isNode; private final String uuid; private final NodeType nodeType; @@ -40,6 +41,7 @@ class ItemData { private ItemData(String path, boolean isNode, String uuid, NodeType nodeType) { super(); this.path = path; + this.name = ResourceUtil.getName(path); this.uuid = uuid; this.isNode = isNode; this.nodeType = nodeType; @@ -50,7 +52,7 @@ class ItemData { } public String getName() { - return ResourceUtil.getName(path); + return name; } public boolean isNode() { diff --git a/src/main/java/org/apache/sling/testing/mock/jcr/MockNode.java b/src/main/java/org/apache/sling/testing/mock/jcr/MockNode.java index d53f43c..45a8060 100644 --- a/src/main/java/org/apache/sling/testing/mock/jcr/MockNode.java +++ b/src/main/java/org/apache/sling/testing/mock/jcr/MockNode.java @@ -49,11 +49,8 @@ import org.apache.jackrabbit.commons.iterator.PropertyIteratorAdapter; */ class MockNode extends AbstractItem implements Node { - private final ItemData itemData; - public MockNode(final ItemData itemData, final Session session) { - super(itemData.getPath(), session); - this.itemData = itemData; + super(itemData, session); } @Override diff --git a/src/main/java/org/apache/sling/testing/mock/jcr/MockProperty.java b/src/main/java/org/apache/sling/testing/mock/jcr/MockProperty.java index 40a3b40..2bc4182 100644 --- a/src/main/java/org/apache/sling/testing/mock/jcr/MockProperty.java +++ b/src/main/java/org/apache/sling/testing/mock/jcr/MockProperty.java @@ -39,11 +39,8 @@ import org.apache.jackrabbit.value.BinaryValue; */ class MockProperty extends AbstractItem implements Property { - private final ItemData itemData; - public MockProperty(final ItemData itemData, final Session session) { - super(itemData.getPath(), session); - this.itemData = itemData; + super(itemData, session); if (this.itemData.getValues() == null) { try { this.itemData.setValues(new Value[] { getSession().getValueFactory().createValue("") }); -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
