<commit_before>/*
 * Copyright (C) 2007 Esmertec AG. Copyright (C) 2007 The Android Open Source
 * Project
 *
 * Licensed 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 info.guardianproject.otr.app.im.engine;

// import info.guardianproject.otr.app.im.plugin.loopback.LoopbackConnection;
import info.guardianproject.otr.app.im.plugin.xmpp.LLXmppConnection;
import info.guardianproject.otr.app.im.plugin.xmpp.XmppConnection;

import java.util.Map;

import android.content.Context;

/** The factory used to create an instance of ImConnection. */
public class ConnectionFactory {
    private static ConnectionFactory sInstance;

    private ConnectionFactory() {
    }

    /**
     * Gets the singleton instance of the factory.
     *
     * @return the singleton instance.
     */
    public synchronized static ConnectionFactory getInstance() {
        if (sInstance == null) {
            sInstance = new ConnectionFactory();
        }
        return sInstance;
    }

    /**
     * Creates a new ImConnection.
     *
     * @return the new ImConnection.
     * @throws IMException if an error occurs during creating a connection.
     */
    public ImConnection createConnection(Map<String, String> settings, Context context)
            throws ImException {
        if ("XMPP".equals(settings.get("im.protocol"))) {

            try
            {
                return new XmppConnection(context);
            }
            catch (Exception e)
            {
                throw new ImException(e.getMessage());
            }
        }
        if ("LLXMPP".equals(settings.get("im.protocol"))) {
            return new LLXmppConnection(context);
        }
        /*else if ("LOOPBACK".equals(settings.get("im.protocol"))) {
        	return new SMSConnection();
        } */
        else {
            throw new ImException("Unsupported protocol: " + settings.get("im.protocol"));
        }
    }
}<commit_msg>ensure we don't get mulitple instances at once<commit_after>/*
 * Copyright (C) 2007 Esmertec AG. Copyright (C) 2007 The Android Open Source
 * Project
 *
 * Licensed 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 info.guardianproject.otr.app.im.engine;

// import info.guardianproject.otr.app.im.plugin.loopback.LoopbackConnection;
import info.guardianproject.otr.app.im.plugin.xmpp.LLXmppConnection;
import info.guardianproject.otr.app.im.plugin.xmpp.XmppConnection;

import java.util.Map;

import android.content.Context;

/** The factory used to create an instance of ImConnection. */
public class ConnectionFactory {
    private static ConnectionFactory sInstance;

    private ConnectionFactory() {
    }

    /**
     * Gets the singleton instance of the factory.
     *
     * @return the singleton instance.
     */
    public synchronized static ConnectionFactory getInstance() {
        if (sInstance == null) {
            sInstance = new ConnectionFactory();
        }
        return sInstance;
    }

    /**
     * Creates a new ImConnection.
     *
     * @return the new ImConnection.
     * @throws IMException if an error occurs during creating a connection.
     */
    public synchronized ImConnection createConnection(Map<String, String> settings, Context context)
            throws ImException {
        if ("XMPP".equals(settings.get("im.protocol"))) {

            try
            {
                return new XmppConnection(context);
            }
            catch (Exception e)
            {
                throw new ImException(e.getMessage());
            }
        }
        if ("LLXMPP".equals(settings.get("im.protocol"))) {
            return new LLXmppConnection(context);
        }
        /*else if ("LOOPBACK".equals(settings.get("im.protocol"))) {
        	return new SMSConnection();
        } */
        else {
            throw new ImException("Unsupported protocol: " + settings.get("im.protocol"));
        }
    }
}
{'fraction_non_alphanumeric': 0.09594926350245499, 'fraction_numerical': 0.004909983633387889, 'mean_word_length': 2.550472040668119, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4230082', 'n_tokens_mistral': 1311, 'n_tokens_neox': 1274, 'n_words': 412}