Skip to content

Commit

Permalink
chore: Remove unused files and update project docs
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-logan committed Jul 11, 2024
1 parent c07d8ea commit 5a586d7
Show file tree
Hide file tree
Showing 37 changed files with 266 additions and 598 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*
replay_pid*

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

This file was deleted.

8 changes: 3 additions & 5 deletions .idea/sonarlint/issuestore/index.pb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions .idea/sonarlint/securityhotspotstore/index.pb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

89 changes: 58 additions & 31 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 23 additions & 2 deletions src/main/java/io/github/multiform_validator/CnpjValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
import java.util.Arrays;

public class CnpjValidator {
// Prevent instantiation
private CnpjValidator() {
throw new IllegalStateException("Utility class");
}

/**
* Calculate the first verifier digit of a CNPJ
*
* @param cnpjBase an array of integers with the first 12 digits of a CNPJ
* @return the first verifier digit
*/
private static int calculateFirstVerifier(int[] cnpjBase) {
final int[] weight = {5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2};
int sum = 0;
Expand All @@ -19,6 +26,13 @@ private static int calculateFirstVerifier(int[] cnpjBase) {
return remainder < 2 ? 0 : 11 - remainder;
}

/**
* Calculate the second verifier digit of a CNPJ
*
* @param cnpjBase an array of integers with the first 12 digits of a CNPJ
* @param firstVerifier the first verifier digit
* @return the second verifier digit
*/
private static int calculateSecondVerifier(int[] cnpjBase, int firstVerifier) {
final int[] weight = {6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2};
int sum = 0;
Expand All @@ -33,9 +47,16 @@ private static int calculateSecondVerifier(int[] cnpjBase, int firstVerifier) {
return remainder < 2 ? 0 : 11 - remainder;
}

/**
* Check if a CNPJ is valid
*
* @param cnpj the CNPJ to be validated
* @return true if the CNPJ is valid, false otherwise
* @throws NullPointerException if the CNPJ is null
*/
public static boolean cnpjIsValid(String cnpj) {
if (cnpj == null) {
throw new NullPointerException("CNPJ cannot be null or empty");
throw new NullPointerException("CNPJ cannot be null");
}

final String cnpjClean = cnpj.replaceAll("\\D", "");
Expand Down Expand Up @@ -67,4 +88,4 @@ public static boolean cnpjIsValid(String cnpj) {

return cnpjArray[12] == firstVerifier && cnpjArray[13] == secondVerifier;
}
}
}
15 changes: 13 additions & 2 deletions src/main/java/io/github/multiform_validator/CpfValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,25 @@
import java.util.regex.Pattern;
import java.util.stream.IntStream;

/**
* The CpfValidator class provides a utility method to validate CPF (Cadastro de Pessoas Físicas) numbers.
*/
public class CpfValidator {
// Prevent instantiation
private CpfValidator() {
throw new IllegalStateException("Utility class");
}

/**
* Validates a CPF number.
*
* @param cpf the CPF number to validate
* @return true if the CPF number is valid, false otherwise
* @throws NullPointerException if the CPF number is null
*/
public static boolean cpfIsValid(String cpf) {
if (cpf == null) {
throw new NullPointerException("CPF cannot be null or empty");
throw new NullPointerException("CPF cannot be null");
}

final String cpfClean = cpf.replaceAll("\\D", "");
Expand All @@ -37,4 +48,4 @@ public static boolean cpfIsValid(String cpf) {

return cpfArray[9] == validator1 && cpfArray[10] == validator2;
}
}
}
Loading

0 comments on commit 5a586d7

Please sign in to comment.