joerghoh commented on a change in pull request #43:
URL:
https://github.com/apache/sling-org-apache-sling-resourceresolver/pull/43#discussion_r604899255
##########
File path:
src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
##########
@@ -1117,4 +1142,68 @@ public Resource move(final String srcAbsPath, final
String destAbsPath) throws P
}
return rsrc;
}
+
+
+
+ // A very simple tupel implementation which can be used as key in any map
+ public class String3Tupel {
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
Review comment:
Eclipse created both `hashCode` and `equals`, so I didn't want to bother
with it :-)
##########
File path:
src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
##########
@@ -1046,37 +1051,57 @@ public String getParentResourceType(final String
resourceType) {
public boolean isResourceType(final Resource resource, final String
resourceType) {
boolean result = false;
if ( resource != null && resourceType != null ) {
- // Check if the resource is of the given type. This method first
checks the
Review comment:
Added it as method description for `isResourceTypeInternal`
##########
File path:
src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
##########
@@ -1046,37 +1051,57 @@ public String getParentResourceType(final String
resourceType) {
public boolean isResourceType(final Resource resource, final String
resourceType) {
boolean result = false;
if ( resource != null && resourceType != null ) {
- // Check if the resource is of the given type. This method first
checks the
- // resource type of the resource, then its super resource type
and continues
- // to go up the resource super type hierarchy.
- if (ResourceTypeUtil.areResourceTypesEqual(resourceType,
resource.getResourceType(), factory.getSearchPath())) {
- result = true;
- } else {
- Set<String> superTypesChecked = new HashSet<>();
- String superType = this.getParentResourceType(resource);
- while (!result && superType != null) {
- if (ResourceTypeUtil.areResourceTypesEqual(resourceType,
superType, factory.getSearchPath())) {
- result = true;
- } else {
- superTypesChecked.add(superType);
- superType = this.getParentResourceType(superType);
- if (superType != null &&
superTypesChecked.contains(superType)) {
- throw new SlingException("Cyclic dependency for
resourceSuperType hierarchy detected on resource " + resource.getPath(), null);
- }
- }
- }
+
+ // Check if the result is already available from cache
+ String3Tupel key = new
String3Tupel(resource.getResourceType(),resource.getResourceSuperType(),
resourceType);
+ if (resourceTypeLookupCache.containsKey(key)) {
Review comment:
Done
##########
File path:
src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
##########
@@ -1117,4 +1142,68 @@ public Resource move(final String srcAbsPath, final
String destAbsPath) throws P
}
return rsrc;
}
+
+
+
+ // A very simple tupel implementation which can be used as key in any map
+ public class String3Tupel {
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + getEnclosingInstance().hashCode();
+ result = prime * result + ((s1 == null) ? 0 : s1.hashCode());
+ result = prime * result + ((s2 == null) ? 0 : s2.hashCode());
+ result = prime * result + ((s3 == null) ? 0 : s3.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ String3Tupel other = (String3Tupel) obj;
+ if (!getEnclosingInstance().equals(other.getEnclosingInstance()))
+ return false;
+ if (s1 == null) {
+ if (other.s1 != null)
+ return false;
+ } else if (!s1.equals(other.s1))
+ return false;
+ if (s2 == null) {
+ if (other.s2 != null)
+ return false;
+ } else if (!s2.equals(other.s2))
+ return false;
+ if (s3 == null) {
+ if (other.s3 != null)
+ return false;
+ } else if (!s3.equals(other.s3))
+ return false;
+ return true;
+ }
+
+ String s1;
Review comment:
Changed order (not sure what Eclipse did here ...)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]