<commit_before>

package org.epctagcoder.parse.SSCC;

import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


import org.epctagcoder.option.PrefixLength;
import org.epctagcoder.option.TableItem;
import org.epctagcoder.option.SSCC.SSCCExtensionDigit;
import org.epctagcoder.option.SSCC.SSCCFilterValue;
import org.epctagcoder.option.SSCC.SSCCHeader;
import org.epctagcoder.option.SSCC.SSCCTagSize;
import org.epctagcoder.option.SSCC.partitionTable.SSCCPartitionTableList;
import org.epctagcoder.result.SSCC;
import org.epctagcoder.util.Converter;

public class ParseSSCC {
	private static final Integer RESERVED = 0; // 24 zero bits
	private SSCC sscc = new SSCC();
	private SSCCExtensionDigit extensionDigit;
	private String companyPrefix;
	private PrefixLength prefixLength;
	private SSCCTagSize tagSize;
	private SSCCFilterValue filterValue;
	private String serial;
	private String rfidTag;
	private String epcTagURI;
	private String epcPureIdentityURI;
	private TableItem tableItem;
	
    public static ChoiceStep Builder() throws Exception {
        return new Steps();
    }

	private ParseSSCC(Steps steps) {
		this.extensionDigit = steps.extensionDigit;
		this.companyPrefix = steps.companyPrefix;
		this.tagSize = steps.tagSize;
		this.filterValue = steps.filterValue;
		this.serial = steps.serial;
		this.rfidTag = steps.rfidTag;
		this.epcTagURI = steps.epcTagURI;
		this.epcPureIdentityURI = steps.epcPureIdentityURI;
    	parse();
	}
	
	
	private void parse() {
		Optional<SSCCExtensionDigit> optionalCompanyPrefix = Optional.ofNullable(extensionDigit);
		Optional<String> optionalRfidTag = Optional.ofNullable(rfidTag);
		Optional<String> optionalEpcTagURI = Optional.ofNullable(epcTagURI);
		Optional<String> optionalEpcPureIdentityURI = Optional.ofNullable(epcPureIdentityURI);
		
		if ( optionalRfidTag.isPresent() ) {
			String inputBin = Converter.hexToBin(rfidTag);
			String headerBin = inputBin.substring(0, 8);
			String filterBin = inputBin.substring(8,11);
			String partitionBin = inputBin.substring(11,14);
			SSCCPartitionTableList ssccPartitionTableList = new SSCCPartitionTableList();

			tableItem = ssccPartitionTableList.getPartitionByValue( Integer.parseInt(partitionBin, 2) );
			
			String companyPrefixBin = inputBin.substring(14,14+tableItem.getM());
			String serialWithExtensionBin = inputBin.substring(14+tableItem.getM(),14+tableItem.getM()+tableItem.getN());
			String filterDec = Long.toString( Long.parseLong(filterBin, 2) );
			String companyPrefixDec = Converter.binToDec(companyPrefixBin); 
			String serialWithExtension = Converter.strZero(Converter.binToDec(serialWithExtensionBin), tableItem.getDigits() ); 
			String extensionDec = serialWithExtension.substring(0,1);		

			serial = serialWithExtension.substring(1);
			companyPrefix = Converter.strZero(companyPrefixDec, tableItem.getL());
			extensionDigit = SSCCExtensionDigit.forCode( Integer.parseInt(extensionDec) );
			filterValue = SSCCFilterValue.forCode( Integer.parseInt(filterDec) );
			tagSize = SSCCTagSize.forCode( SSCCHeader.forCode(headerBin).getTagSize() );
			prefixLength = PrefixLength.forCode(tableItem.getL());

		} else {
			
			if ( optionalCompanyPrefix.isPresent() ) {
				SSCCPartitionTableList ssccPartitionTableList = new SSCCPartitionTableList();
				prefixLength = PrefixLength.forCode( companyPrefix.length() );
				validateCompanyPrefix();
				tableItem = ssccPartitionTableList.getPartitionByL( prefixLength.getValue() );
				validateExtensionDigitAndSerial();
			} else {
				if ( optionalEpcTagURI.isPresent() ) { 
					Pattern pattern = Pattern.compile("(urn:epc:tag:sscc-)(96)\\:([0-7])\\.(\\d+)\\.([0-9])(\\d+)");
					Matcher matcher = pattern.matcher(epcTagURI);
					
					if ( matcher.matches() ) {
						tagSize = SSCCTagSize.forCode( Integer.parseInt(matcher.group(2)) );
						filterValue = SSCCFilterValue.forCode( Integer.parseInt(matcher.group(3)) );
						companyPrefix = matcher.group(4);
						prefixLength = PrefixLength.forCode( matcher.group(4).length() );
						extensionDigit = SSCCExtensionDigit.forCode( Integer.parseInt(matcher.group(5)) );
						serial = matcher.group(6);					
					} else {
						throw new IllegalArgumentException("EPC Tag URI is invalid");
					}
					
				} else if ( optionalEpcPureIdentityURI.isPresent() ) {
					Pattern pattern = Pattern.compile("(urn:epc:id:sscc)\\:(\\d+)\\.([0-9])(\\d+)");
					Matcher matcher = pattern.matcher(epcPureIdentityURI);
					
					if ( matcher.matches() ) {<commit_msg>fixed the regular expression of EpcPureIdentityURI and EpcTagURI<commit_after>

package org.epctagcoder.parse.SSCC;

import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


import org.epctagcoder.option.PrefixLength;
import org.epctagcoder.option.TableItem;
import org.epctagcoder.option.SSCC.SSCCExtensionDigit;
import org.epctagcoder.option.SSCC.SSCCFilterValue;
import org.epctagcoder.option.SSCC.SSCCHeader;
import org.epctagcoder.option.SSCC.SSCCTagSize;
import org.epctagcoder.option.SSCC.partitionTable.SSCCPartitionTableList;
import org.epctagcoder.result.SSCC;
import org.epctagcoder.util.Converter;

public class ParseSSCC {
	private static final Integer RESERVED = 0; // 24 zero bits
	private SSCC sscc = new SSCC();
	private SSCCExtensionDigit extensionDigit;
	private String companyPrefix;
	private PrefixLength prefixLength;
	private SSCCTagSize tagSize;
	private SSCCFilterValue filterValue;
	private String serial;
	private String rfidTag;
	private String epcTagURI;
	private String epcPureIdentityURI;
	private TableItem tableItem;
	
    public static ChoiceStep Builder() throws Exception {
        return new Steps();
    }

	private ParseSSCC(Steps steps) {
		this.extensionDigit = steps.extensionDigit;
		this.companyPrefix = steps.companyPrefix;
		this.tagSize = steps.tagSize;
		this.filterValue = steps.filterValue;
		this.serial = steps.serial;
		this.rfidTag = steps.rfidTag;
		this.epcTagURI = steps.epcTagURI;
		this.epcPureIdentityURI = steps.epcPureIdentityURI;
    	parse();
	}
	
	
	private void parse() {
		Optional<SSCCExtensionDigit> optionalCompanyPrefix = Optional.ofNullable(extensionDigit);
		Optional<String> optionalRfidTag = Optional.ofNullable(rfidTag);
		Optional<String> optionalEpcTagURI = Optional.ofNullable(epcTagURI);
		Optional<String> optionalEpcPureIdentityURI = Optional.ofNullable(epcPureIdentityURI);
		
		if ( optionalRfidTag.isPresent() ) {
			String inputBin = Converter.hexToBin(rfidTag);
			String headerBin = inputBin.substring(0, 8);
			String filterBin = inputBin.substring(8,11);
			String partitionBin = inputBin.substring(11,14);
			SSCCPartitionTableList ssccPartitionTableList = new SSCCPartitionTableList();

			tableItem = ssccPartitionTableList.getPartitionByValue( Integer.parseInt(partitionBin, 2) );
			
			String companyPrefixBin = inputBin.substring(14,14+tableItem.getM());
			String serialWithExtensionBin = inputBin.substring(14+tableItem.getM(),14+tableItem.getM()+tableItem.getN());
			String filterDec = Long.toString( Long.parseLong(filterBin, 2) );
			String companyPrefixDec = Converter.binToDec(companyPrefixBin); 
			String serialWithExtension = Converter.strZero(Converter.binToDec(serialWithExtensionBin), tableItem.getDigits() ); 
			String extensionDec = serialWithExtension.substring(0,1);		

			serial = serialWithExtension.substring(1);
			companyPrefix = Converter.strZero(companyPrefixDec, tableItem.getL());
			extensionDigit = SSCCExtensionDigit.forCode( Integer.parseInt(extensionDec) );
			filterValue = SSCCFilterValue.forCode( Integer.parseInt(filterDec) );
			tagSize = SSCCTagSize.forCode( SSCCHeader.forCode(headerBin).getTagSize() );
			prefixLength = PrefixLength.forCode(tableItem.getL());

		} else {
			
			if ( optionalCompanyPrefix.isPresent() ) {
				SSCCPartitionTableList ssccPartitionTableList = new SSCCPartitionTableList();
				prefixLength = PrefixLength.forCode( companyPrefix.length() );
				validateCompanyPrefix();
				tableItem = ssccPartitionTableList.getPartitionByL( prefixLength.getValue() );
				validateExtensionDigitAndSerial();
			} else {
				if ( optionalEpcTagURI.isPresent() ) {
					Pattern pattern = Pattern.compile("(urn:epc:tag:sscc-)(96)\\:([0-7])\\.(\\d+)\\.([0-9])(\\d+)");
					Matcher matcher = pattern.matcher(epcTagURI);
					
					if ( matcher.matches() ) {
						tagSize = SSCCTagSize.forCode( Integer.parseInt(matcher.group(2)) );
						filterValue = SSCCFilterValue.forCode( Integer.parseInt(matcher.group(3)) );
						companyPrefix = matcher.group(4);
						prefixLength = PrefixLength.forCode( matcher.group(4).length() );
						extensionDigit = SSCCExtensionDigit.forCode( Integer.parseInt(matcher.group(5)) );
						serial = matcher.group(6);					
					} else {
						throw new IllegalArgumentException("EPC Tag URI is invalid");
					}
					
				} else if ( optionalEpcPureIdentityURI.isPresent() ) {
					Pattern pattern = Pattern.compile("(urn:epc:id:sscc)\\:(\\d+)\\.([0-9])(\\d+)");
					Matcher matcher = pattern.matcher(epcPureIdentityURI);
					
					if ( matcher.matches() ) {
{'fraction_non_alphanumeric': 0.11357644991212654, 'fraction_numerical': 0.008567662565905097, 'mean_word_length': 4.916179337231969, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '6615042', 'n_tokens_mistral': 3283, 'n_tokens_neox': 2854, 'n_words': 485}