Added Javadoc comments to the classes

This commit is contained in:
2024-08-11 23:48:02 -04:00
parent b16956b184
commit c10df8e5df
29 changed files with 3270 additions and 431 deletions

View File

@@ -1,7 +1,23 @@
//CipherStreamJava/src/main/java/com/mattrixwv/cipherstream/monosubstitution/BaseX.java
//Mattrixwv
// Created: 01-08-22
//Modified: 05-04-23
//Modified: 08-11-24
/*
Copyright (C) 2024 Mattrixwv
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.mattrixwv.cipherstream.monosubstitution;
@@ -15,16 +31,35 @@ import com.mattrixwv.cipherstream.exceptions.InvalidCharacterException;
import com.mattrixwv.cipherstream.exceptions.InvalidInputException;
/**
* A class for encoding and decoding strings using a specified numerical base.
* The BaseX class allows encoding and decoding of strings where characters are represented in a given base.
* The base can be set to any value between Character.MIN_RADIX and Character.MAX_RADIX.
*
* <p>
* This class supports encoding and decoding of ASCII characters into their base-X representations,
* where X is the base provided by the user. It ensures that input strings are valid and within the acceptable range
* for the specified base.
* </p>
*/
public class BaseX{
private static final Logger logger = LoggerFactory.getLogger(BaseX.class);
//Fields
protected String inputString; //The string that needs encoded/decoded
protected String outputString; //The encoded/decoded string
//Settings
protected int base; //The base that the number will be encoded at
//?Fields
/** The string that needs encoded/decoded */
protected String inputString;
/** The encoded/decoded string */
protected String outputString;
//?Settings
/** The base that the number will be encoded at */
protected int base;
//Sets the input string
/**
* Sets the input string for encoding, ensuring it is not null and contains at least one letter.
*
* @param inputString the string to be encoded
* @throws InvalidInputException if the input string is null or blank
*/
protected void setInputStringEncode(String inputString) throws InvalidInputException{
if(inputString == null){
throw new InvalidInputException("Input cannot be null");
@@ -38,6 +73,13 @@ public class BaseX{
throw new InvalidInputException("Input must contain at least 1 letter");
}
}
/**
* Sets the input string for decoding, ensuring it is not null, does not contain invalid characters, and is properly formatted.
*
* @param inputString the string to be decoded
* @throws InvalidCharacterException if the input string contains invalid characters
* @throws InvalidInputException if the input string is null or blank
*/
protected void setInputStringDecode(String inputString) throws InvalidCharacterException, InvalidInputException{
if(inputString == null){
throw new InvalidInputException("Input cannot be null");
@@ -68,7 +110,12 @@ public class BaseX{
throw new InvalidInputException("Input must contain at least 1 letter");
}
}
//Sets the numeric base
/**
* Sets the base for encoding and decoding, ensuring it is within valid range.
*
* @param base the base to be set
* @throws InvalidBaseException if the base is less than Character.MIN_RADIX or greater than Character.MAX_RADIX
*/
protected void setBase(int base) throws InvalidBaseException{
if(base < Character.MIN_RADIX){
throw new InvalidBaseException("Base cannot be less than " + Character.MIN_RADIX);
@@ -81,7 +128,9 @@ public class BaseX{
this.base = base;
}
//Encode inputString, store it in outputString, and return it
/**
* Encodes the input string using the specified base.
*/
protected void encode(){
logger.debug("Encoding");
@@ -102,7 +151,11 @@ public class BaseX{
outputString = output.toString().toUpperCase();
logger.debug("Saving output string '{}'", outputString);
}
//Decode inputString, store it in outputString, and return it
/**
* Decodes the input string from the specified base.
*
* @throws InvalidCharacterException if the input string contains invalid characters for the base
*/
protected void decode() throws InvalidCharacterException{
logger.debug("Decoding");
@@ -129,23 +182,49 @@ public class BaseX{
logger.debug("Saving output string '{}'", outputString);
}
//Constructor
//?Constructor
/**
* Constructs a new {@code BaseX} instance with the default base of 2.
*
* @throws InvalidBaseException if the default base is invalid
*/
public BaseX() throws InvalidBaseException{
reset();
setBase(2);
}
/**
* Constructs a new {@code BaseX} instance with the specified base.
*
* @param base the base to be used for encoding and decoding
* @throws InvalidBaseException if the base is invalid
*/
public BaseX(int base) throws InvalidBaseException{
reset();
setBase(base);
}
//Sets the inputString and encodes the message
/**
* Encodes the given input string using the current base.
*
* @param inputString the string to be encoded
* @return the encoded string
* @throws InvalidInputException if the input string is invalid
*/
public String encode(String inputString) throws InvalidInputException{
reset();
setInputStringEncode(inputString);
encode();
return outputString;
}
/**
* Encodes the given input string using the specified base.
*
* @param base the base to use for encoding
* @param inputString the string to be encoded
* @return the encoded string
* @throws InvalidBaseException if the base is invalid
* @throws InvalidInputException if the input string is invalid
*/
public String encode(int base, String inputString) throws InvalidBaseException, InvalidInputException{
reset();
setBase(base);
@@ -153,13 +232,30 @@ public class BaseX{
encode();
return outputString;
}
//Sets the inputString and decodes the message
/**
* Decodes the given input string using the current base.
*
* @param inputString the string to be decoded
* @return the decoded string
* @throws InvalidCharacterException if the input string contains invalid characters
* @throws InvalidInputException if the input string is invalid
*/
public String decode(String inputString) throws InvalidCharacterException, InvalidInputException{
reset();
setInputStringDecode(inputString);
decode();
return outputString;
}
/**
* Decodes the given input string using the specified base.
*
* @param base the base to use for decoding
* @param inputString the string to be decoded
* @return the decoded string
* @throws InvalidBaseException if the base is invalid
* @throws InvalidCharacterException if the input string contains invalid characters
* @throws InvalidInputException if the input string is invalid
*/
public String decode(int base, String inputString) throws InvalidBaseException, InvalidCharacterException, InvalidInputException{
reset();
setBase(base);
@@ -168,17 +264,34 @@ public class BaseX{
return outputString;
}
//Getters
//?Getters
/**
* Gets the current input string.
*
* @return the input string
*/
public String getInputString(){
return inputString;
}
/**
* Gets the current output string.
*
* @return the output string
*/
public String getOutputString(){
return outputString;
}
/**
* Gets the current base.
*
* @return the base
*/
public int getBase(){
return base;
}
//Makes sure all variables are empty
/**
* Resets the input and output strings to empty.
*/
public void reset(){
logger.debug("Resetting fields");