<commit_before>package org.csanchez.aws.glacier.actions;

import static com.google.common.collect.Iterables.transform;
import static com.google.common.collect.Sets.union;
import static java.util.Collections.unmodifiableSet;
import static org.csanchez.aws.glacier.utils.Check.notNull;

import java.util.Collection;
import java.util.Set;
import java.util.concurrent.Callable;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.csanchez.aws.glacier.domain.Vault;
import org.csanchez.aws.glacier.utils.Check;
import org.joda.time.DateTime;
import org.joda.time.format.ISODateTimeFormat;

import com.amazonaws.services.glacier.AmazonGlacierClient;
import com.amazonaws.services.glacier.model.DescribeVaultOutput;
import com.amazonaws.services.glacier.model.ListVaultsRequest;
import com.amazonaws.services.glacier.model.ListVaultsResult;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet;

public class Vaults implements Callable<Collection<Vault>> {

    private static final Log LOG = LogFactory.getLog( Vaults.class );

    private final AmazonGlacierClient client;

    public Vaults( AmazonGlacierClient client ) {
        this.client = notNull( client );
    }

    public Collection<Vault> call() {
        try {
            LOG.info( "Retrieving vault list" );
            return listVaults( client, new ListVaultsRequest( "-" ) );
        } catch ( Exception e ) {
            String errorMessage = "Couldn't retrieve vault list";
            LOG.error( errorMessage, e );
            throw new RuntimeException( errorMessage, e );
        }
    }

    private static Set<Vault> listVaults( AmazonGlacierClient client, ListVaultsRequest request ) {
        ListVaultsResult result = client.listVaults( request );

        Set<Vault> vaults = ImmutableSet.copyOf( transform( result.getVaultList(), TO_VAULT ) );

        if ( result.getMarker() != null ) {
            ListVaultsRequest nextRequest = new ListVaultsRequest( "-" ).withMarker( result.getMarker() );
            return union( vaults, listVaults( client, nextRequest ) );
        }

        return unmodifiableSet( vaults );
    }

    private static final Function<DescribeVaultOutput, Vault> TO_VAULT = new Function<DescribeVaultOutput, Vault>() {
        public Vault apply( DescribeVaultOutput response ) {
            Check.notNull( response );
            
            String arn = response.getVaultARN();
            String name = response.getVaultName();
            Long numberOfArchives = response.getNumberOfArchives();
            Long sizeInBytes = response.getSizeInBytes();
            DateTime creationDate = ISODateTimeFormat.dateTimeParser().parseDateTime( response.getCreationDate() );
            
            return new Vault( arn, name, numberOfArchives, sizeInBytes, creationDate );
        }
    };

}<commit_msg>Small refactor of Vaults callable<commit_after>package org.csanchez.aws.glacier.actions;

import static com.google.common.collect.Iterables.transform;
import static com.google.common.collect.Sets.union;
import static java.util.Collections.unmodifiableSet;
import static org.csanchez.aws.glacier.utils.Check.notNull;

import java.util.Collection;
import java.util.Set;
import java.util.concurrent.Callable;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.csanchez.aws.glacier.domain.Vault;
import org.csanchez.aws.glacier.utils.Check;
import org.joda.time.DateTime;
import org.joda.time.format.ISODateTimeFormat;

import com.amazonaws.services.glacier.AmazonGlacierClient;
import com.amazonaws.services.glacier.model.DescribeVaultOutput;
import com.amazonaws.services.glacier.model.ListVaultsRequest;
import com.amazonaws.services.glacier.model.ListVaultsResult;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet;

public class Vaults implements Callable<Collection<Vault>> {

    private static final Log LOG = LogFactory.getLog( Vaults.class );

    private final AmazonGlacierClient client;

    public Vaults( AmazonGlacierClient client ) {
        this.client = notNull( client );
    }

    @Override
    public Collection<Vault> call() {
        try {
            LOG.info( "Retrieving vault list" );
            return listVaults( client, new ListVaultsRequest( "-" ) );
        } catch ( Exception e ) {
            throw new RuntimeException( "Couldn't retrieve vault list", e );
        }
    }

    private static Set<Vault> listVaults( AmazonGlacierClient client, ListVaultsRequest request ) {
        ListVaultsResult result = client.listVaults( request );

        Set<Vault> vaults = ImmutableSet.copyOf( transform( result.getVaultList(), TO_VAULT ) );

        String marker = result.getMarker();
        if ( marker != null ) {
            ListVaultsRequest nextRequest = new ListVaultsRequest( "-" ).withMarker( marker );
            return union( vaults, listVaults( client, nextRequest ) );
        }

        return unmodifiableSet( vaults );
    }

    private static final Function<DescribeVaultOutput, Vault> TO_VAULT = new Function<DescribeVaultOutput, Vault>() {
        @Override
        public Vault apply( DescribeVaultOutput response ) {
            Check.notNull( response );

            String arn = response.getVaultARN();
            String name = response.getVaultName();
            Long numberOfArchives = response.getNumberOfArchives();
            Long sizeInBytes = response.getSizeInBytes();
            DateTime creationDate = ISODateTimeFormat.dateTimeParser().parseDateTime( response.getCreationDate() );

            return new Vault( arn, name, numberOfArchives, sizeInBytes, creationDate );
        }
    };

}
{'fraction_non_alphanumeric': 0.09776536312849161, 'fraction_numerical': 0.0, 'mean_word_length': 3.369946605644546, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5561015', 'n_tokens_mistral': 1667, 'n_tokens_neox': 1647, 'n_words': 349}