<commit_before>/*
 * ProfileRegistry.java  $Revision: 1.3 $ $Date: 2001/06/28 15:42:49 $
 *
 * Copyright (c) 2001 Invisible Worlds, Inc.  All rights reserved.
 *
 * The contents of this file are subject to the Blocks Public License (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.invisible.net/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied.  See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 */
package org.beepcore.beep.core;


import java.util.Enumeration;
import java.util.Hashtable;


/**
 * This class is used to save pointers in Sessions - if the peer is using
 * the same set of profile and associated StartChannelListener for all
 * sessions then they should create one of these helpers and use them in
 * the corresponding factory methods.
 *
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>
 * @version $Revision, $Date: 2001/06/28 15:42:49 $
 */
public class ProfileRegistry implements Cloneable {

    private static final String SPACE = " ";
    private static final String FRAGMENT_ANGLE_SUFFIX = ">";
    private static final String FRAGMENT_FEATURES_PREFIX = "features='";
    private static final String FRAGMENT_GREETING_PREFIX = "<greeting";
    private static final String FRAGMENT_GREETING_SUFFIX = "</greeting>";
    private static final String FRAGMENT_LOCALIZE_PREFIX = "localize='";
    private static final String FRAGMENT_PROFILE_PREFIX = "<profile ";
    private static final String FRAGMENT_QUOTE_ANGLE_SUFFIX = "'>";
    private static final String FRAGMENT_QUOTE_SLASH_ANGLE_SUFFIX = "' />";
    private static final String FRAGMENT_QUOTE_SUFFIX = "' ";
    private static final String FRAGMENT_URI_PREFIX = "uri='";
    private static final int FRAGMENT_GREETING_LENGTH =
        FRAGMENT_GREETING_PREFIX.length()
        + FRAGMENT_QUOTE_ANGLE_SUFFIX.length()
        + FRAGMENT_GREETING_SUFFIX.length();
    private static final int FRAGMENT_PROFILE_LENGTH =
        FRAGMENT_PROFILE_PREFIX.length()
        + FRAGMENT_QUOTE_ANGLE_SUFFIX.length();

    // Instance Data
    private class InternalProfile {
        StartChannelListener listener;
        SessionTuningProperties tuning;
    }

    private Hashtable profileListeners;
    String greeting;
    String localize;
    String features;

    // Constructors

    /**
     * Constructor ProfileRegistry
     *
     *
     */
    public ProfileRegistry()
    {
        this.greeting = null;
        this.features = null;
        this.localize = Constants.LOCALIZE_DEFAULT;
        this.profileListeners = new Hashtable();
    }

    private ProfileRegistry(String greeting, String localize,
                            String features, Hashtable profiles)
    {
        this.greeting = greeting;
        this.features = features;
        this.localize = localize;
        this.profileListeners = profiles;
    }

    public Object clone()
    {
        return new ProfileRegistry(this.greeting, this.localize,
                                   this.features,
                                   (Hashtable) this.profileListeners.clone());
    }

    /**
     * Method getProfiles
     *
     *
     * @return
     *
     */
    public Enumeration getProfiles()
    {
        return profileListeners.keys();
    }

    /**
     * Returns the <code>StartChannelListener</code> for the specified URI.
     *
     *
     * @param uri
     *
     */
    public StartChannelListener getStartChannelListener(SessionTuningProperties tuning,
                                                        String uri)
    {

        InternalProfile profile = (InternalProfile) profileListeners.get(uri);

        // if there are no qualifications, then just return the listener
        if (profile.tuning == null) {
            return ((InternalProfile) profileListeners.get(uri)).listener;
        }

        // so the profile requires something, but if the session doesn't
        // have anything, then return null
        if (tuning == null) {
            return null;
        }

        // if the profile requires any of the standard properties, then
        // make sure they are set on the session before returning the listener
        int i = 0;

        for (i = 0; i < SessionTuningProperties.STANDARD_PROPERTIES.length;
                i++)
        {
            if ((profile.tuning.getProperty(SessionTuningProperties.STANDARD_PROPERTIES[i]) != null)
                    && (tuning.getProperty(SessionTuningProperties.STANDARD_PROPERTIES[i])
                        == null))
            {
                return null;<commit_msg>Fix for NullPointerException when calling getStartChannelListener with an unregistered uri<commit_after>/*
 * ProfileRegistry.java  $Revision: 1.4 $ $Date: 2001/07/03 20:47:25 $
 *
 * Copyright (c) 2001 Invisible Worlds, Inc.  All rights reserved.
 *
 * The contents of this file are subject to the Blocks Public License (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.invisible.net/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied.  See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 */
package org.beepcore.beep.core;


import java.util.Enumeration;
import java.util.Hashtable;


/**
 * This class is used to save pointers in Sessions - if the peer is using
 * the same set of profile and associated StartChannelListener for all
 * sessions then they should create one of these helpers and use them in
 * the corresponding factory methods.
 *
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>
 * @version $Revision, $Date: 2001/07/03 20:47:25 $
 */
public class ProfileRegistry implements Cloneable {

    private static final String SPACE = " ";
    private static final String FRAGMENT_ANGLE_SUFFIX = ">";
    private static final String FRAGMENT_FEATURES_PREFIX = "features='";
    private static final String FRAGMENT_GREETING_PREFIX = "<greeting";
    private static final String FRAGMENT_GREETING_SUFFIX = "</greeting>";
    private static final String FRAGMENT_LOCALIZE_PREFIX = "localize='";
    private static final String FRAGMENT_PROFILE_PREFIX = "<profile ";
    private static final String FRAGMENT_QUOTE_ANGLE_SUFFIX = "'>";
    private static final String FRAGMENT_QUOTE_SLASH_ANGLE_SUFFIX = "' />";
    private static final String FRAGMENT_QUOTE_SUFFIX = "' ";
    private static final String FRAGMENT_URI_PREFIX = "uri='";
    private static final int FRAGMENT_GREETING_LENGTH =
        FRAGMENT_GREETING_PREFIX.length()
        + FRAGMENT_QUOTE_ANGLE_SUFFIX.length()
        + FRAGMENT_GREETING_SUFFIX.length();
    private static final int FRAGMENT_PROFILE_LENGTH =
        FRAGMENT_PROFILE_PREFIX.length()
        + FRAGMENT_QUOTE_ANGLE_SUFFIX.length();

    // Instance Data
    private class InternalProfile {
        StartChannelListener listener;
        SessionTuningProperties tuning;
    }

    private Hashtable profileListeners;
    String greeting;
    String localize;
    String features;

    // Constructors

    /**
     * Constructor ProfileRegistry
     *
     *
     */
    public ProfileRegistry()
    {
        this.greeting = null;
        this.features = null;
        this.localize = Constants.LOCALIZE_DEFAULT;
        this.profileListeners = new Hashtable();
    }

    private ProfileRegistry(String greeting, String localize,
                            String features, Hashtable profiles)
    {
        this.greeting = greeting;
        this.features = features;
        this.localize = localize;
        this.profileListeners = profiles;
    }

    public Object clone()
    {
        return new ProfileRegistry(this.greeting, this.localize,
                                   this.features,
                                   (Hashtable) this.profileListeners.clone());
    }

    /**
     * Method getProfiles
     *
     *
     * @return
     *
     */
    public Enumeration getProfiles()
    {
        return profileListeners.keys();
    }

    /**
     * Returns the <code>StartChannelListener</code> for the specified URI.
     *
     *
     * @param uri
     *
     */
    public StartChannelListener getStartChannelListener(SessionTuningProperties tuning,
                                                        String uri)
    {

        InternalProfile profile = (InternalProfile) profileListeners.get(uri);

        if (profile == null) {
            return null;
        }

        // if there are no qualifications, then just return the listener
        if (profile.tuning == null) {
            return ((InternalProfile) profileListeners.get(uri)).listener;
        }

        // so the profile requires something, but if the session doesn't
        // have anything, then return null
        if (tuning == null) {
            return null;
        }

        // if the profile requires any of the standard properties, then
        // make sure they are set on the session before returning the listener
        int i = 0;

        for (i = 0; i < SessionTuningProperties.STANDARD_PROPERTIES.length;
                i++)
        {
            if ((profile.tuning.getProperty(SessionTuningProperties.STANDARD_PROPERTIES[i]) != null)
                    && (tuning.getProperty(SessionTuningProperties.STANDARD_PROPERTIES[i])
                        == null))
            {
                return null;
{'fraction_non_alphanumeric': 0.08149598186688646, 'fraction_numerical': 0.00741809190191634, 'mean_word_length': 2.445864394746184, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '407211', 'n_tokens_mistral': 2695, 'n_tokens_neox': 2573, 'n_words': 789}