<commit_before>/*
 * Copyright 2014 <NAME>
 *
 * The jawampa authors license 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 ws.wamp.jawampa;

import io.netty.handler.ssl.SslContext;

import java.net.URI;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ws.wamp.jawampa.auth.client.ClientSideAuthentication;
import ws.wamp.jawampa.internal.UriValidator;
import ws.wamp.jawampa.transport.WampClientChannelFactory;
import ws.wamp.jawampa.transport.WampClientChannelFactoryResolver;

/**
 * WampClientBuilder is the builder object which allows to create
 * {@link WampClient} objects.<br>
 * New clients have to be configured with the member methods before
 * a client can be created with the {@link #build build()} method.
 */
public class WampClientBuilder {
    private static final Logger log = LoggerFactory.getLogger( WampClientBuilder.class );

    String uri;
    String realm;
    SslContext sslContext;
    int nrReconnects = 0;
    int reconnectInterval = DEFAULT_RECONNECT_INTERVAL;
    boolean closeOnErrors = true;
    Set<WampRoles> roles = new HashSet<WampRoles>();
    private String authId = null;
    private List<ClientSideAuthentication> authMethods = new ArrayList<ClientSideAuthentication>();
    
    /** The default reconnect interval in milliseconds.<br>This is set to 5s */
    public static final int DEFAULT_RECONNECT_INTERVAL = 5000;
    /** The minimum reconnect interval in milliseconds.<br>This is set to 100ms */
    public static final int MIN_RECONNECT_INTERVAL = 100;

    /**
     * Construct a new WampClientBuilder object.
     */
    public WampClientBuilder() {
        log.info( "WampClientBuilder" );
        // Add the default roles
        roles.add(WampRoles.Caller);
        roles.add(WampRoles.Callee);
        roles.add(WampRoles.Publisher);
        roles.add(WampRoles.Subscriber);
    }
    
    /**
     * Builds a new {@link WampClient WAMP client} from the information given in this builder.<br>
     * At least the uri of the router and the name of the realm have to be
     * set for a proper operation.
     * @return The created WAMP client
     * @throws WampError if any parameter is not invalid
     */
    public WampClient build() throws ApplicationError {
        if (uri == null)
            throw new ApplicationError(ApplicationError.INVALID_URI);
        
        URI routerUri;
        try {
        	routerUri = new URI(uri);
        }
        catch (Throwable t) {
        	throw new ApplicationError(ApplicationError.INVALID_URI);
        }
        
        if (realm == null)
            throw new ApplicationError(ApplicationError.INVALID_REALM);
        
        try {
            UriValidator.validate(realm);
        } catch (Exception e) {
            throw new ApplicationError(ApplicationError.INVALID_REALM);
        }
        
        if (roles.size() == 0) {
            throw new ApplicationError(ApplicationError.INVALID_ROLES);
        }
        
        WampClientChannelFactory channelFactory = 
            WampClientChannelFactoryResolver.getFactory(routerUri, sslContext);
        
        return new WampClientImpl(routerUri, realm, roles, closeOnErrors, 
                channelFactory, nrReconnects, reconnectInterval, authId, authMethods);
    }
    
    /**
     * Sets the address of the router to which the new client shall connect.
     * @param uri The address of the router, e.g. ws://wamp.ws/ws
     * @return The {@link WampClientBuilder} object
     * @deprecated This method existed only due to a typo will be removed
     */
    public WampClientBuilder witUri(String uri) {
        this.uri = uri;
        return this;
    }
    
    /**
     * Sets the address of the router to which the new client shall connect.
     * @param uri The address of the router, e.g. ws://wamp.ws/ws
     * @return The {@link WampClientBuilder} object
     */
    public WampClientBuilder withUri(String uri) {
        this.uri = uri;
        return this;
    }
    
    /**
     * Sets the name of the realm on the router which shall be used for the sesion.
     * @param realm The name of the realm to which shall be connected.
     * @return The {@link WampClientBuilder} object
     */<commit_msg>Remove miss-spelled method<commit_after>/*
 * Copyright 2014 <NAME>
 *
 * The jawampa authors license 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 ws.wamp.jawampa;

import io.netty.handler.ssl.SslContext;

import java.net.URI;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ws.wamp.jawampa.auth.client.ClientSideAuthentication;
import ws.wamp.jawampa.internal.UriValidator;
import ws.wamp.jawampa.transport.WampClientChannelFactory;
import ws.wamp.jawampa.transport.WampClientChannelFactoryResolver;

/**
 * WampClientBuilder is the builder object which allows to create
 * {@link WampClient} objects.<br>
 * New clients have to be configured with the member methods before
 * a client can be created with the {@link #build build()} method.
 */
public class WampClientBuilder {
    private static final Logger log = LoggerFactory.getLogger( WampClientBuilder.class );

    String uri;
    String realm;
    SslContext sslContext;
    int nrReconnects = 0;
    int reconnectInterval = DEFAULT_RECONNECT_INTERVAL;
    boolean closeOnErrors = true;
    Set<WampRoles> roles = new HashSet<WampRoles>();
    private String authId = null;
    private List<ClientSideAuthentication> authMethods = new ArrayList<ClientSideAuthentication>();
    
    /** The default reconnect interval in milliseconds.<br>This is set to 5s */
    public static final int DEFAULT_RECONNECT_INTERVAL = 5000;
    /** The minimum reconnect interval in milliseconds.<br>This is set to 100ms */
    public static final int MIN_RECONNECT_INTERVAL = 100;

    /**
     * Construct a new WampClientBuilder object.
     */
    public WampClientBuilder() {
        log.info( "WampClientBuilder" );
        // Add the default roles
        roles.add(WampRoles.Caller);
        roles.add(WampRoles.Callee);
        roles.add(WampRoles.Publisher);
        roles.add(WampRoles.Subscriber);
    }
    
    /**
     * Builds a new {@link WampClient WAMP client} from the information given in this builder.<br>
     * At least the uri of the router and the name of the realm have to be
     * set for a proper operation.
     * @return The created WAMP client
     * @throws WampError if any parameter is not invalid
     */
    public WampClient build() throws ApplicationError {
        if (uri == null)
            throw new ApplicationError(ApplicationError.INVALID_URI);
        
        URI routerUri;
        try {
        	routerUri = new URI(uri);
        }
        catch (Throwable t) {
        	throw new ApplicationError(ApplicationError.INVALID_URI);
        }
        
        if (realm == null)
            throw new ApplicationError(ApplicationError.INVALID_REALM);
        
        try {
            UriValidator.validate(realm);
        } catch (Exception e) {
            throw new ApplicationError(ApplicationError.INVALID_REALM);
        }
        
        if (roles.size() == 0) {
            throw new ApplicationError(ApplicationError.INVALID_ROLES);
        }
        
        WampClientChannelFactory channelFactory = 
            WampClientChannelFactoryResolver.getFactory(routerUri, sslContext);
        
        return new WampClientImpl(routerUri, realm, roles, closeOnErrors, 
                channelFactory, nrReconnects, reconnectInterval, authId, authMethods);
    }
    
    /**
     * Sets the address of the router to which the new client shall connect.
     * @param uri The address of the router, e.g. ws://wamp.ws/ws
     * @return The {@link WampClientBuilder} object
     */
    public WampClientBuilder withUri(String uri) {
        this.uri = uri;
        return this;
    }
    
    /**
     * Sets the name of the realm on the router which shall be used for the sesion.
     * @param realm The name of the realm to which shall be connected.
     * @return The {@link WampClientBuilder} object
     */
{'fraction_non_alphanumeric': 0.08033804022250748, 'fraction_numerical': 0.004920838682071031, 'mean_word_length': 2.8284193284193284, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '7315874', 'n_tokens_mistral': 2614, 'n_tokens_neox': 2560, 'n_words': 873}