Skip to content

deepak786/ProductCodeIdentifier

Repository files navigation

Product Code Identifier

Library to get the identifier type of Product code i.e. UPC, ISBN, EAN, SKU, ASIN. If the product code is not valid then it will return type of NONE.

What is this Product Code

UPC

UPC is Universal Product Code. It generally consist of 12-digits and used extensively for retail packaging in United States (US).

ISBN

ISBN is Internal Standard Book Number. This actually identifies a particular book. ISBN have either 10 or 13 digits. But all the ISBNs assigned after Jan 1, 2007 are always of 13 digits.

EAN

EAN is International Artical Number or also known as European Article Number. It generally consist of 13 digits but for the small products where an EAN-13 barcode would be too large; for example on cigarettes, pencils, and chewing gum packets, it consist of 8 digits (EAN-8).

ASIN

ASIN is Amazon Standard Identification Number and generally consist of 10 alphanumeric characters. But for the books ISBN and ASIN number is same and only consist of digits.

SKU

SKU is stock keeping unit and it is generally related to company not to the product. A same product can have multiple SKUs as SKU is related to company not to product. It generally consist of 8 alphanumeric characters.

Usage

Suppose we have a product code 0-201-53082-1 and we don't know what is the type of this Product Code. To check the type you can use:

ProductCodeValidator.getCodeType("0-201-53082-1"));

And the result is of type ProductCodeType.ISBN_10. Which means id type of above code is ISBN (International Standard Book Number).

Class ProductCodeType has the following types:

ProductCodeType.SKU
ProductCodeType.EAN_8
ProductCodeType.ASIN
ProductCodeType.ISBN_10
ProductCodeType.UPC
ProductCodeType.EAN_13
ProductCodeType.ISBN_13
ProductCodeType.NONE

If you know the type of code but you want to check, if the code is valid or not. You can use the following:

UPC

ProductCodeValidator.isValidUPC("190198160980");

ISBN-13

ProductCodeValidator.isValidISBN_13("9781940363776");

EAN-8

ProductCodeValidator.isValidEAN("96385074");

ISBN-10

ProductCodeValidator.isValidISBN_10("0201530821");

Note

Make sure to use the functions with String parameter. As Functions with long parameter type also available but when product code is starting with 0, then that functions will give you wrong results. So use the functions having String parameter type. By the way I have depreceated the functions having long parameter type.

Getting Real Name

As ISBN_10 and ISBN_13 both are Internation Standard Book Number (ISBN) types. The difference is just the digits. ISBN_10 has 10 digits and ISBN_13 has 13 digits. So to get the real name of any Product type, you can use:

ProductCodeType.ISBN_10.getRealName(); // ISBN
ProductCodeType.ISBN_13.getRealName(); // ISBN

Validation Algorithm

Validation of each code is based on the check digit algorithm. You can check the more information at https://en.wikipedia.org/wiki/Check_digit

License

Copyright (c) 2018, Deepak Goyal under Apache License. 
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

- Redistributions of source code must retain the above copyright
  notice, this list of conditions and the following disclaimer.

- Redistributions in binary form must reproduce the above copyright
  notice, this list of conditions and the following disclaimer in the
  documentation and/or other materials provided with the distribution.