<commit_before>package io.liveoak.container.tenancy;

import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import io.liveoak.spi.MediaType;
import io.liveoak.spi.RequestContext;
import io.liveoak.spi.resource.RootResource;
import io.liveoak.spi.resource.SynchronousResource;
import io.liveoak.spi.resource.async.Resource;
import io.liveoak.spi.resource.async.ResourceSink;
import io.liveoak.spi.resource.async.Responder;
import io.netty.handler.codec.http.HttpHeaders;
import org.jboss.logging.Logger;

/**
 * @author <NAME>
 */
public class MediaTypeResourceRegistry implements MountPointResource, RootResource, SynchronousResource {
    public MediaTypeResourceRegistry(Resource parent, String id) {
        this.parent = parent;
        this.id = id;
    }

    public MediaTypeResourceRegistry(String id) {
        this.id = id;
    }

    public void parent(Resource parent) {
        this.parent = parent;
    }

    @Override
    public Resource parent() {
        return this.parent;
    }

    @Override
    public String id() {
        return this.id;
    }

    @Override
    public void registerResource(Resource resource) {
        registerResource(resource, MediaType.JSON, true);
    }

    @Override
    public void registerResource(Resource resource, MediaType mediaType, boolean makeDefault) {
        Map<MediaType, Resource> resourceMap = this.registry.get(resource.id());

        if (resourceMap == null) {
            resourceMap = new ConcurrentHashMap<>();
            this.registry.put(resource.id(), resourceMap);
        }

        resourceMap.put(mediaType, resource);

        if (makeDefault || !resourceMap.containsKey(DEFAULT)) {
            resourceMap.put(DEFAULT, resource);
        }
    }

    @Override
    public void unregisterResource(Resource resource) {
        unregisterResource(resource, MediaType.JSON);
    }

    @Override
    public void unregisterResource(Resource resource, MediaType mediaType) {
        if (this.registry != null) {
            Map<MediaType, Resource> resourceMap = this.registry.get(resource.id());

            if (resourceMap != null) {
                resourceMap.remove(mediaType);

                if (resourceMap.size() == 1 && resourceMap.get(DEFAULT) != null) {
                    resourceMap.remove(DEFAULT);
                }

                if (resourceMap.isEmpty()) {
                    this.registry.remove(resource.id());
                }
            }
        }
    }

    @Override
    public void readMember(RequestContext ctx, String id, Responder responder) throws Exception {<commit_msg>MediaTypeResourceRegistry change to NOT mark a resource as a default unless specified to do so<commit_after>package io.liveoak.container.tenancy;

import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import io.liveoak.spi.MediaType;
import io.liveoak.spi.RequestContext;
import io.liveoak.spi.resource.RootResource;
import io.liveoak.spi.resource.SynchronousResource;
import io.liveoak.spi.resource.async.Resource;
import io.liveoak.spi.resource.async.ResourceSink;
import io.liveoak.spi.resource.async.Responder;
import io.netty.handler.codec.http.HttpHeaders;
import org.jboss.logging.Logger;

/**
 * @author <NAME>
 */
public class MediaTypeResourceRegistry implements MountPointResource, RootResource, SynchronousResource {
    public MediaTypeResourceRegistry(Resource parent, String id) {
        this.parent = parent;
        this.id = id;
    }

    public MediaTypeResourceRegistry(String id) {
        this.id = id;
    }

    public void parent(Resource parent) {
        this.parent = parent;
    }

    @Override
    public Resource parent() {
        return this.parent;
    }

    @Override
    public String id() {
        return this.id;
    }

    @Override
    public void registerResource(Resource resource) {
        registerResource(resource, MediaType.JSON, true);
    }

    @Override
    public void registerResource(Resource resource, MediaType mediaType, boolean makeDefault) {
        Map<MediaType, Resource> resourceMap = this.registry.get(resource.id());

        if (resourceMap == null) {
            resourceMap = new ConcurrentHashMap<>();
            this.registry.put(resource.id(), resourceMap);
        }

        resourceMap.put(mediaType, resource);

        if (makeDefault) {
            resourceMap.put(DEFAULT, resource);
        }
    }

    @Override
    public void unregisterResource(Resource resource) {
        unregisterResource(resource, MediaType.JSON);
    }

    @Override
    public void unregisterResource(Resource resource, MediaType mediaType) {
        if (this.registry != null) {
            Map<MediaType, Resource> resourceMap = this.registry.get(resource.id());

            if (resourceMap != null) {
                resourceMap.remove(mediaType);

                if (resourceMap.size() == 1 && resourceMap.get(DEFAULT) != null) {
                    resourceMap.remove(DEFAULT);
                }

                if (resourceMap.isEmpty()) {
                    this.registry.remove(resource.id());
                }
            }
        }
    }

    @Override
    public void readMember(RequestContext ctx, String id, Responder responder) throws Exception {
{'fraction_non_alphanumeric': 0.10115284492376347, 'fraction_numerical': 0.0003718854592785422, 'mean_word_length': 2.6893004115226335, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6444779', 'n_tokens_mistral': 1483, 'n_tokens_neox': 1436, 'n_words': 313}