<commit_before>/*
 * 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.sling.resourcemerger.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.sling.api.resource.AbstractResource;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceMetadata;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;

/**
 * {@inheritDoc}
 */
public class MergedResource extends AbstractResource {

    private final ResourceResolver resolver;
    private final String path;
    private final String relativePath;
    private final List<String> mappedResources = new ArrayList<String>();

    private final ResourceMetadata metadata = new ResourceMetadata();

    /** Cache value map. */
    private ValueMap properties;

    /**
     * Constructor
     *
     * @param resolver      Resource resolver
     * @param mergeRootPath Merge root path
     * @param relativePath  Relative path
     */
    MergedResource(final ResourceResolver resolver,
                   final String mergeRootPath,
                   final String relativePath) {
        this(resolver, mergeRootPath, relativePath, null);
    }

    /**
     * Constructor
     *
     * @param resolver      Resource resolver
     * @param mergeRootPath   Merge root path
     * @param relativePath    Relative path
     * @param mappedResources List of physical mapped resources' paths
     */
    MergedResource(final ResourceResolver resolver,
                   final String mergeRootPath,
                   final String relativePath,
                   final List<String> mappedResources) {
        this.resolver = resolver;
        this.path = (relativePath.length() == 0 ? mergeRootPath : mergeRootPath + "/" + relativePath);
        this.relativePath = (relativePath.length() == 0 ? "/" : relativePath);
        if ( mappedResources != null ) {
            this.mappedResources.addAll(mappedResources);
        }
        metadata.put("sling.mergedResource", true);
        metadata.put("sling.mappedResources", mappedResources.toArray(new String[mappedResources.size()]));
    }


    // ---- MergedResource interface ------------------------------------------

    public String getRelativePath() {
        return relativePath;
    }

    /**
     * {@inheritDoc}
     */
    public void addMappedResource(final String path) {
        mappedResources.add(path);
    }

    /**
     * {@inheritDoc}
     */
    public Iterable<String> getMappedResources() {
        return mappedResources;
    }


    // ---- Resource interface ------------------------------------------------

    /**
     * {@inheritDoc}
     */
    public String getPath() {
        return this.path;
    }

    /**
     * {@inheritDoc}
     */
    public String getResourceType() {
        return this.relativePath;
    }

    /**
     * {@inheritDoc}
     */
    public String getResourceSuperType() {
        // So far, there's no concept of resource super type for a merged resource<commit_msg>SLING-2986 : Use sling:resourceType property to define the resource type<commit_after>/*
 * 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.sling.resourcemerger.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.sling.api.resource.AbstractResource;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceMetadata;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;

/**
 * {@inheritDoc}
 */
public class MergedResource extends AbstractResource {

    private final ResourceResolver resolver;
    private final String path;
    private final String relativePath;
    private final List<String> mappedResources = new ArrayList<String>();

    private final ResourceMetadata metadata = new ResourceMetadata();

    private final String resourceType;

    /** Cache value map. */
    private ValueMap properties;

    /**
     * Constructor
     *
     * @param resolver      Resource resolver
     * @param mergeRootPath Merge root path
     * @param relativePath  Relative path
     */
    MergedResource(final ResourceResolver resolver,
                   final String mergeRootPath,
                   final String relativePath) {
        this(resolver, mergeRootPath, relativePath, null);
    }

    /**
     * Constructor
     *
     * @param resolver      Resource resolver
     * @param mergeRootPath   Merge root path
     * @param relativePath    Relative path
     * @param mappedResources List of physical mapped resources' paths
     */
    MergedResource(final ResourceResolver resolver,
                   final String mergeRootPath,
                   final String relativePath,
                   final List<String> mappedResources) {
        this.resolver = resolver;
        this.path = (relativePath.length() == 0 ? mergeRootPath : mergeRootPath + "/" + relativePath);
        this.relativePath = (relativePath.length() == 0 ? "/" : relativePath);
        if ( mappedResources != null ) {
            this.mappedResources.addAll(mappedResources);
        }
        this.resourceType = this.adaptTo(ValueMap.class).get(ResourceResolver.PROPERTY_RESOURCE_TYPE, this.relativePath);
        metadata.put("sling.mergedResource", true);
        metadata.put("sling.mappedResources", mappedResources.toArray(new String[mappedResources.size()]));
    }


    // ---- MergedResource interface ------------------------------------------

    public String getRelativePath() {
        return relativePath;
    }

    /**
     * {@inheritDoc}
     */
    public void addMappedResource(final String path) {
        mappedResources.add(path);
    }

    /**
     * {@inheritDoc}
     */
    public Iterable<String> getMappedResources() {
        return mappedResources;
    }


    // ---- Resource interface ------------------------------------------------

    /**
     * {@inheritDoc}
     */
    public String getPath() {
        return this.path;
    }

    /**
     * {@inheritDoc}
     */
    public String getResourceType() {
        return this.resourceType;
    }

    /**
     * {@inheritDoc}
     */
    public String getResourceSuperType() {
        // So far, there's no concept of resource super type for a merged resource
{'fraction_non_alphanumeric': 0.11199080577193206, 'fraction_numerical': 0.002043161792874473, 'mean_word_length': 2.5026833631484795, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5568846', 'n_tokens_mistral': 1996, 'n_tokens_neox': 1942, 'n_words': 610}