<commit_before>/*******************************************************************************
 *
 *    Copyright (C) 2015-2018 the BBoxDB 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 org.bboxdb.storage.entity;

import org.bboxdb.commons.StringUtil;
import org.bboxdb.distribution.DistributionGroupName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TupleStoreName implements Comparable<TupleStoreName> {

	/**
	 * The full name of the table
	 * 
	 * Format: groupname_tablename_tablenumber
	 * 
	 * e.g. mydata_mytable2
	 * 
	 */
	protected final String fullname;
	
	/**
	 * Is the tablename valid?
	 */
	protected final boolean valid;
	
	/**
	 * The group of the table
	 */
	protected String group;
	
	/**
	 * The name of the table
	 */
	protected String tablename;
	
	/**
	 * The region id
	 */
	protected long regionid;
	
	/**
	 * The value for an invalid group
	 */
	public final static String INVALID_GROUP = null;
	
	/**
	 * The value for an invalid table
	 */
	public final static String INVALID_TABLENAME = null;
	
	/**
	 * The value for an invalid name prefix
	 */
	public final static short INVALID_REGIONID = -1;
	
	/**
	 * The Logger
	 */
	private final static Logger logger = LoggerFactory.getLogger(TupleStoreName.class);
	
	public TupleStoreName(final String fullname) {
		this.fullname = fullname;
		this.valid = splitTablename();
	}
	
	public TupleStoreName(final String distributionGroup, 
			final String tablename, final long regionid) {		
		this.fullname = distributionGroup + "_" + tablename + "_" + regionid;
		this.valid = true;

		this.group = distributionGroup;
		this.tablename = tablename;
		this.regionid = regionid;
	}
	
	/**
	 * Clone this sstable name with another region id
	 * @param regionId
	 * @return
	 */
	public TupleStoreName cloneWithDifferntRegionId(final long regionId) {
		return new TupleStoreName(group, tablename, regionId);
	}
	
	/**
	 * Split the tablename into the three components
	 * @return
	 */
	protected boolean splitTablename() {
		
		if(fullname == null) {
			return false;
		}
		
		final String[] parts = fullname.split("_");
		final long terminals = StringUtil.countCharOccurrence(fullname, '_');

		if(parts.length - 1 != terminals) {
			logger.warn("Got invalid tablename: " + fullname);
			return false;
		}
		
		if(parts.length != 2 && parts.length != 3) {
			logger.warn("Got invalid tablename: " + fullname);	
			return false;
		}
		
		group = parts[0];
		tablename = parts[1];
		
		if(group.length() == 0 || tablename.length() == 0) {
			logger.warn("Got invalid tablename: " + fullname);
			return false;
		}
				
		if(parts.length == 3) {
			final String regionIdString = parts[2];

			if(regionIdString.length() == 0) {
				logger.warn("Got invalid tablename: " + fullname);
				return false;
			}
			
			try {
				regionid = Short.parseShort(regionIdString);
			} catch(NumberFormatException e) {
				logger.warn("Invalid tablenumber: " + regionIdString);
				return false;
			}			
		} else {
			regionid = INVALID_REGIONID;
		}
		
		return true;
	}
	
	/**
	 * Is the tablename valid?
	 * @return
	 */
	public boolean isValid() {
		return valid;
	}
	<commit_msg>Refactored logger to java 8<commit_after>/*******************************************************************************
 *
 *    Copyright (C) 2015-2018 the BBoxDB 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 org.bboxdb.storage.entity;

import org.bboxdb.commons.StringUtil;
import org.bboxdb.distribution.DistributionGroupName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TupleStoreName implements Comparable<TupleStoreName> {

	/**
	 * The full name of the table
	 * 
	 * Format: groupname_tablename_tablenumber
	 * 
	 * e.g. mydata_mytable2
	 * 
	 */
	protected final String fullname;
	
	/**
	 * Is the tablename valid?
	 */
	protected final boolean valid;
	
	/**
	 * The group of the table
	 */
	protected String group;
	
	/**
	 * The name of the table
	 */
	protected String tablename;
	
	/**
	 * The region id
	 */
	protected long regionid;
	
	/**
	 * The value for an invalid group
	 */
	public final static String INVALID_GROUP = null;
	
	/**
	 * The value for an invalid table
	 */
	public final static String INVALID_TABLENAME = null;
	
	/**
	 * The value for an invalid name prefix
	 */
	public final static short INVALID_REGIONID = -1;
	
	/**
	 * The Logger
	 */
	private final static Logger logger = LoggerFactory.getLogger(TupleStoreName.class);
	
	public TupleStoreName(final String fullname) {
		this.fullname = fullname;
		this.valid = splitTablename();
	}
	
	public TupleStoreName(final String distributionGroup, 
			final String tablename, final long regionid) {		
		this.fullname = distributionGroup + "_" + tablename + "_" + regionid;
		this.valid = true;

		this.group = distributionGroup;
		this.tablename = tablename;
		this.regionid = regionid;
	}
	
	/**
	 * Clone this sstable name with another region id
	 * @param regionId
	 * @return
	 */
	public TupleStoreName cloneWithDifferntRegionId(final long regionId) {
		return new TupleStoreName(group, tablename, regionId);
	}
	
	/**
	 * Split the tablename into the three components
	 * @return
	 */
	protected boolean splitTablename() {
		
		if(fullname == null) {
			return false;
		}
		
		final String[] parts = fullname.split("_");
		final long terminals = StringUtil.countCharOccurrence(fullname, '_');

		if(parts.length - 1 != terminals) {
			logger.warn("Got invalid tablename: {}", fullname);
			return false;
		}
		
		if(parts.length != 2 && parts.length != 3) {
			logger.warn("Got invalid tablename: {}", fullname);	
			return false;
		}
		
		group = parts[0];
		tablename = parts[1];
		
		if(group.length() == 0 || tablename.length() == 0) {
			logger.warn("Got invalid tablename: {}", fullname);
			return false;
		}
				
		if(parts.length == 3) {
			final String regionIdString = parts[2];

			if(regionIdString.length() == 0) {
				logger.warn("Got invalid tablename: {}", fullname);
				return false;
			}
			
			try {
				regionid = Short.parseShort(regionIdString);
			} catch(NumberFormatException e) {
				logger.warn("Invalid tablenumber: {}", regionIdString);
				return false;
			}			
		} else {
			regionid = INVALID_REGIONID;
		}
		
		return true;
	}
	
	/**
	 * Is the tablename valid?
	 * @return
	 */
	public boolean isValid() {
		return valid;
	}
	
{'fraction_non_alphanumeric': 0.1431749770972386, 'fraction_numerical': 0.006936264886794922, 'mean_word_length': 3.2836322869955157, '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': '1794776', 'n_tokens_mistral': 2611, 'n_tokens_neox': 2233, 'n_words': 674}