<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.directory.shared.ldap.model.schema.registries;


import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import org.apache.directory.shared.i18n.I18n;
import org.apache.directory.shared.ldap.model.schema.SchemaObjectWrapper;
import org.apache.directory.shared.util.StringConstants;


/**
 * The default Schema interface implementation.
 *
 * @author <a href="mailto:<EMAIL>">Apache Directory Project</a>
 */
public class DefaultSchema implements Schema
{
    /** The default schema's owner */
    protected static final String DEFAULT_OWNER = "uid=admin,ou=system";
    
    /** Tells if this schema is disabled */
    protected boolean disabled;
    
    /** Contains the list of schema it depends on */
    protected String[] dependencies;
    
    /** The schema owner */
    protected String owner;
    
    /** The schema name */
    protected String name;
    
    /** The set of SchemaObjects declared in this schema */
    protected Set<SchemaObjectWrapper> content;
    
    
    /**
     * Creates a new instance of DefaultSchema.
     *
     * @param name The schema's name
     */
    public DefaultSchema( String name )
    {
        this( name, null, null, false );
    }
    
        
    /**
     * Creates a new instance of DefaultSchema.
     *
     * @param name The schema's name
     * @param owner the schema's owner
     */
    public DefaultSchema( String name, String owner )
    {
        this( name, owner, null, false );
    }
    
        
    /**
     * Creates a new instance of DefaultSchema.
     *
     * @param name The schema's name
     * @param owner the schema's owner
     * @param dependencies The list of schemas it depends on 
     */
    public DefaultSchema( String name, String owner, String[] dependencies )
    {
        this( name, owner, dependencies, false );
    }
    
        
    /**
     * Creates a new instance of DefaultSchema.
     *
     * @param name The schema's name
     * @param owner the schema's owner
     * @param dependencies The list of schemas it depends on
     * @param disabled Set the status for this schema 
     */
    public DefaultSchema( String name, String owner, String[] dependencies, boolean disabled )
    {
        if ( name == null )
        {
            throw new IllegalArgumentException( I18n.err( I18n.ERR_04266 ) );
        }
        
        this.name = name;
        
        if ( owner != null )
        {
            this.owner = owner;
        }
        else
        {
            this.owner = DEFAULT_OWNER;
        }
        
        if ( dependencies != null )
        {
            this.dependencies = dependencies;
        }
        else
        {
            this.dependencies = StringConstants.EMPTY_STRINGS;
        }
        
        this.disabled = disabled;
        
        content = new HashSet<SchemaObjectWrapper>(); 
    }


    /**
     * {@inheritDoc}
     */
    public String[] getDependencies()
    {
        String[] copy = new String[dependencies.length];
        System.arraycopy( dependencies, 0, copy, 0, dependencies.length );
        return copy;
    }

    
    /**
     * {@inheritDoc}
     */
    public void addDependencies( String... dependenciesToAdd )
    {
        if ( dependenciesToAdd != null )
        {
            this.dependencies = new String[dependenciesToAdd.length];
            System.arraycopy( this.dependencies, 0, dependenciesToAdd, 0, dependenciesToAdd.length );
        }
    }

    
    /**
     * {@inheritDoc}
     */
    public String getOwner()
    {
        return owner;
    }

    
    /**<commit_msg>Fixed a bug where dependencies were not copied correctly (switched arrays when calling System.arraycopy(...)).<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.directory.shared.ldap.model.schema.registries;


import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import org.apache.directory.shared.i18n.I18n;
import org.apache.directory.shared.ldap.model.schema.SchemaObjectWrapper;
import org.apache.directory.shared.util.StringConstants;


/**
 * The default Schema interface implementation.
 *
 * @author <a href="mailto:<EMAIL>">Apache Directory Project</a>
 */
public class DefaultSchema implements Schema
{
    /** The default schema's owner */
    protected static final String DEFAULT_OWNER = "uid=admin,ou=system";
    
    /** Tells if this schema is disabled */
    protected boolean disabled;
    
    /** Contains the list of schema it depends on */
    protected String[] dependencies;
    
    /** The schema owner */
    protected String owner;
    
    /** The schema name */
    protected String name;
    
    /** The set of SchemaObjects declared in this schema */
    protected Set<SchemaObjectWrapper> content;
    
    
    /**
     * Creates a new instance of DefaultSchema.
     *
     * @param name The schema's name
     */
    public DefaultSchema( String name )
    {
        this( name, null, null, false );
    }
    
        
    /**
     * Creates a new instance of DefaultSchema.
     *
     * @param name The schema's name
     * @param owner the schema's owner
     */
    public DefaultSchema( String name, String owner )
    {
        this( name, owner, null, false );
    }
    
        
    /**
     * Creates a new instance of DefaultSchema.
     *
     * @param name The schema's name
     * @param owner the schema's owner
     * @param dependencies The list of schemas it depends on 
     */
    public DefaultSchema( String name, String owner, String[] dependencies )
    {
        this( name, owner, dependencies, false );
    }
    
        
    /**
     * Creates a new instance of DefaultSchema.
     *
     * @param name The schema's name
     * @param owner the schema's owner
     * @param dependencies The list of schemas it depends on
     * @param disabled Set the status for this schema 
     */
    public DefaultSchema( String name, String owner, String[] dependencies, boolean disabled )
    {
        if ( name == null )
        {
            throw new IllegalArgumentException( I18n.err( I18n.ERR_04266 ) );
        }
        
        this.name = name;
        
        if ( owner != null )
        {
            this.owner = owner;
        }
        else
        {
            this.owner = DEFAULT_OWNER;
        }
        
        if ( dependencies != null )
        {
            this.dependencies = dependencies;
        }
        else
        {
            this.dependencies = StringConstants.EMPTY_STRINGS;
        }
        
        this.disabled = disabled;
        
        content = new HashSet<SchemaObjectWrapper>(); 
    }


    /**
     * {@inheritDoc}
     */
    public String[] getDependencies()
    {
        String[] copy = new String[dependencies.length];
        System.arraycopy( dependencies, 0, copy, 0, dependencies.length );
        return copy;
    }

    
    /**
     * {@inheritDoc}
     */
    public void addDependencies( String... dependenciesToAdd )
    {
        if ( dependenciesToAdd != null )
        {
            this.dependencies = new String[dependenciesToAdd.length];
            System.arraycopy( dependenciesToAdd, 0, dependencies, 0, dependenciesToAdd.length );
        }
    }

    
    /**
     * {@inheritDoc}
     */
    public String getOwner()
    {
        return owner;
    }

    
    /**
{'fraction_non_alphanumeric': 0.09036278655686623, 'fraction_numerical': 0.004673937235699978, 'mean_word_length': 2.1075380359612725, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '2659387', 'n_tokens_mistral': 2429, 'n_tokens_neox': 2355, 'n_words': 801}