<commit_before>package org.sagebionetworks.audit.utils;

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

import org.sagebionetworks.StackConfiguration;
import org.sagebionetworks.aws.utils.s3.BucketDao;
import org.sagebionetworks.aws.utils.s3.BucketDaoImpl;

import com.amazonaws.services.s3.AmazonS3Client;

/**
 * This is a helper class that manages bucketDao and bucketName resources for ObjectRecordDAO.
 * 
 * @author kimyen
 *
 */
public class BucketDaoProvider {

	private Map<String, BucketDao> bucketDaoMap;
	private AmazonS3Client s3Client;
	private String stack;
	private Map<String, String> bucketNameMap;

	public BucketDaoProvider(AmazonS3Client s3Client, String stack) {
		super();
		this.s3Client = s3Client;
		this.stack = stack;
		this.bucketDaoMap = new HashMap<String, BucketDao>();
		this.bucketNameMap = new HashMap<String, String>();
	}
	
	/**
	 * 
	 * @param type
	 * @effect if bucketDaoMap does not contain key type, before this method returns,
	 * it adds a new pair <type, new bucketDao> to bucketDaoMap
	 * @return the bucketDao of the requested type
	 */
	public BucketDao getBucketDao(String type) {
		if (bucketDaoMap.containsKey(type)) {
			return bucketDaoMap.get(type);
		}

		// first time seeing this type		
		String bucketName = getBucketName(type);
		
		// create the bucketDao for this type and save it
		BucketDao bucketDao = new BucketDaoImpl(s3Client, bucketName);
		bucketDaoMap.put(type, bucketDao);
		return bucketDao;
	}
	
	/**
	 * 
	 * @param type
	 * @effect if bucketNameMap does not contain key type, before this method returns,
	 * it tries to create a new bucket and adds a new pair <type, new bucketName> to 
	 * bucketNameMap 
	 * @return the bucketName of the requested type
	 */
	public String getBucketName(String type) {
		if (bucketNameMap.containsKey(type)) {
			return bucketNameMap.get(type);
		}
		
		// first time seeing this type	
		String bucketName = StackConfiguration.getObjectRecordBucketName(stack, type);
		
		// Create the bucket if it does not exist
		s3Client.createBucket(bucketName);
		bucketNameMap.put(type, bucketName);
		return bucketName;
	}
}<commit_msg>remove bucketDaoMap<commit_after>package org.sagebionetworks.audit.utils;

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

import org.sagebionetworks.StackConfiguration;
import org.sagebionetworks.aws.utils.s3.BucketDao;
import org.sagebionetworks.aws.utils.s3.BucketDaoImpl;

import com.amazonaws.services.s3.AmazonS3Client;

/**
 * This is a helper class that manages bucketDao and bucketName resources for ObjectRecordDAO.
 * 
 * @author kimyen
 *
 */
public class BucketDaoProvider {

	private AmazonS3Client s3Client;
	private String stack;
	private Map<String, String> bucketNameMap;

	public BucketDaoProvider(AmazonS3Client s3Client, String stack) {
		super();
		this.s3Client = s3Client;
		this.stack = stack;
		this.bucketNameMap = new HashMap<String, String>();
	}
	
	/**
	 * 
	 * @param type
	 * @return the bucketDao of the requested type
	 */
	public BucketDao getBucketDao(String type) {
		return new BucketDaoImpl(s3Client, getBucketName(type));
	}
	
	/**
	 * 
	 * @param type
	 * @effect if bucketNameMap does not contain key type, before this method returns,
	 * it tries to create a new bucket and adds a new pair <type, new bucketName> to 
	 * bucketNameMap 
	 * @return the bucketName of the requested type
	 */
	public String getBucketName(String type) {
		if (bucketNameMap.containsKey(type)) {
			return bucketNameMap.get(type);
		}
		
		// first time seeing this type	
		String bucketName = StackConfiguration.getObjectRecordBucketName(stack, type);
		
		// Create the bucket if it does not exist
		s3Client.createBucket(bucketName);
		bucketNameMap.put(type, bucketName);
		return bucketName;
	}
}
{'fraction_non_alphanumeric': 0.0903534414031358, 'fraction_numerical': 0.006377889981397821, 'mean_word_length': 4.249651324965132, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, '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': '3113450', 'n_tokens_mistral': 1256, 'n_tokens_neox': 1183, 'n_words': 339}