package org.gs1.source.service.util;

public class CheckBit {
	
	public boolean check(String gtin) {
		
		int[] check = new int[13];
		int sum = 0;
		
		if(gtin.length() == 14) {
			if(gtin.charAt(0) != '0') {
				return false;
			}
			
			for(int i = 0; i < 13; i++) {
				check[i] = Character.getNumericValue(gtin.charAt(i+1));
			}
		} else {
			for(int i = 0; i < 13; i++) {
				check[i] = Character.getNumericValue(gtin.charAt(i));
			}
		}
		
		for(int i = 1; i < 12; i += 2) {
			check[i] *= 3;
			
		}
		
		for(int i = 0; i < 12; i ++) {
			sum += check[i];
		}
		
		int check_sum = 10 - (sum % 10);
		
		if(check[12] == check_sum) {
			return true;
		} else {
			return false;
		}
	
	}

}

@@ -600,24 +600,73 @@
 m %25 10);%0A%09%09%0A
+%09%09if(check_sum == 10) %7B%0A%09%09%09check_sum = 0;%0A%09%09%7D%0A%09%09%0A
 %09%09if(check%5B1

modify CheckBit