<commit_before>package com.terradue.warhol;

/*
 *    Copyright 2011-2012 Terradue srl
 *
 *    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.
 */

import static com.terradue.warhol.lang.Preconditions.checkArgument;
import static com.terradue.warhol.lang.Preconditions.checkNotNullArgument;

import java.util.HashMap;
import java.util.Map;

import org.w3._2005.atom.Feed;

import com.sun.jersey.api.client.Client;
import com.terradue.warhol.settings.Catalogue;
import com.terradue.warhol.settings.Settings;
import com.terradue.warhol.traverse.TraverseHandler;
import com.terradue.warhol.traverse.TraverseHandlerBuilder;

public final class CatalogueSystem
{
    private static final String ATOM_XML = "application/atom+xml";

    private final Map<String, Catalogue> cataloguesIndex = new HashMap<String, Catalogue>();

    private final Client restClient;

    private final Settings settings;

    public CatalogueSystem( Client restClient, Settings settings )
    {
        this.restClient = checkNotNullArgument( restClient, "Impossible to initialize a CatalogueSystem with a null REST client" );
        this.settings = checkNotNullArgument( settings, "Impossible to initialize a CatalogueSystem from a null Settings reference" );

        for ( Catalogue catalogue : settings.getCatalogues().getCatalogue() )
        {
            cataloguesIndex.put( catalogue.getId(), catalogue );
        }
    }

    public TraverseHandlerBuilder traverse( String catalogueId )
    {
        catalogueId = checkNotNullArgument( catalogueId, "Catalogue ID must be not null." );
        checkArgument( cataloguesIndex.containsKey( catalogueId ), "catalogue <%s> not present in the current system, only %s available",
                                                                   catalogueId, cataloguesIndex.keySet() );
        return new TraverseHandlerBuilder()
        {

            @Override
            public void with( TraverseHandler traverseHandler )
            {
                traverseHandler = checkNotNullArgument( traverseHandler, "Impossible to traverse the Catalogue <%s> with a null handler" );
            }

        };
    }

    private Feed parse( String uri )
    {
        return restClient.resource( uri ).accept( ATOM_XML ).get( Feed.class );
    }

}<commit_msg>not handling rest client directly into the System, rather make each connector will take care<commit_after>package com.terradue.warhol;

/*
 *    Copyright 2011-2012 Terradue srl
 *
 *    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.
 */

import static com.terradue.warhol.lang.Preconditions.checkArgument;
import static com.terradue.warhol.lang.Preconditions.checkNotNullArgument;

import java.util.HashMap;
import java.util.Map;

import com.terradue.warhol.settings.Catalogue;
import com.terradue.warhol.settings.Settings;
import com.terradue.warhol.traverse.TraverseHandler;
import com.terradue.warhol.traverse.TraverseHandlerBuilder;

public final class CatalogueSystem
{
    private final Map<String, Catalogue> cataloguesIndex = new HashMap<String, Catalogue>();

    public CatalogueSystem( Settings settings )
    {
        checkArgument( settings != null, "Impossible to initialize a CatalogueSystem from a null Settings reference" );

        for ( Catalogue catalogue : settings.getCatalogues().getCatalogue() )
        {
            cataloguesIndex.put( catalogue.getId(), catalogue );
        }
    }

    public TraverseHandlerBuilder traverse( String catalogueId )
    {
        catalogueId = checkNotNullArgument( catalogueId, "Catalogue ID must be not null." );
        checkArgument( cataloguesIndex.containsKey( catalogueId ), "catalogue <%s> not present in the current system, only %s available",
                                                                   catalogueId, cataloguesIndex.keySet() );
        return new TraverseHandlerBuilder()
        {

            @Override
            public void with( TraverseHandler traverseHandler )
            {
                traverseHandler = checkNotNullArgument( traverseHandler, "Impossible to traverse the Catalogue <%s> with a null handler" );
            }

        };
    }

}
{'fraction_non_alphanumeric': 0.07772220084647942, 'fraction_numerical': 0.005579068872643324, 'mean_word_length': 2.993087557603687, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6985179', 'n_tokens_mistral': 1345, 'n_tokens_neox': 1311, 'n_words': 439}