Added javadoc comments

This commit is contained in:
2024-08-11 21:31:00 -04:00
parent ae1346dbcd
commit 3feefdb7dd
12 changed files with 825 additions and 60 deletions

View File

@@ -1,10 +1,10 @@
//JavaClasses/src/main/java/mattrixwv/ArrayAlgorithms.java
//Matthew Ellison
// Created: 07-03-21
//Modified: 06-25-22
//Modified: 08-11-24
//This class contains algorithms for vectors that I've found it useful to keep around
/*
Copyright (C) 2022 Matthew Ellison
Copyright (C) 2024 Matthew Ellison
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
@@ -28,9 +28,26 @@ import java.util.List;
import java.util.StringJoiner;
/**
* The {@code ArrayAlgorithms} class provides static utility methods for performing
* arithmetic operations on collections of numbers, including integers, longs, and BigIntegers.
* It also includes utility methods for printing and converting lists.
*
* <p>This class is not intended to be instantiated.</p>
*/
public class ArrayAlgorithms{
/**
* Private constructor to prevent instantiation of this utility class.
*/
private ArrayAlgorithms(){}
//This function returns the sum of all elements in the list
//?This function returns the sum of all elements in the list
/**
* Returns the sum of all elements in the given iterable collection of integers.
*
* @param nums the iterable collection of integers to sum
* @return the sum of all integers in the collection
*/
public static int getSum(Iterable<Integer> nums){
//Setup the variables
int sum = 0;
@@ -43,6 +60,12 @@ public class ArrayAlgorithms{
//Return the sum of all elements
return sum;
}
/**
* Returns the sum of all elements in the given iterable of longs.
*
* @param nums the iterable collection of longs to sum
* @return the sum of all longs in the collection
*/
public static long getLongSum(Iterable<Long> nums){
//Setup the variables
long sum = 0;
@@ -55,6 +78,12 @@ public class ArrayAlgorithms{
//Return the sum of all elements
return sum;
}
/**
* Returns the sum of all elements in the given iterable collection of {@code BigInteger} objects.
*
* @param nums the iterable collection of {@code BigInteger} objects to sum
* @return the sum of all {@code BigInteger} objects in the collection
*/
public static BigInteger getBigSum(Iterable<BigInteger> nums){
//Setup the variables
BigInteger sum = BigInteger.ZERO;
@@ -67,7 +96,15 @@ public class ArrayAlgorithms{
//Return the sum of all elements
return sum;
}
//This function returns the product of all elements in the list
//?This function returns the product of all elements in the list
/**
* Returns the product of all elements in the given iterable collection of integers.
* If the iterable is empty, it returns 0.
*
* @param nums the iterable collection of integers to multiply
* @return the product of all integers in the collection, or 0 if the collection is empty
*/
public static int getProd(Iterable<Integer> nums){
//If a blank list was passed tot he fuction return 0 as the product
if(!nums.iterator().hasNext()){
@@ -85,6 +122,13 @@ public class ArrayAlgorithms{
//Return the product of all elements
return product;
}
/**
* Returns the product of all elements in the given iterable collection of longs.
* If the iterable is empty, it returns 0.
*
* @param nums the iterable collection of longs to multiply
* @return the product of all longs in the collection, or 0 if the collection is empty
*/
public static long getLongProd(Iterable<Long> nums){
//If a blank list was passed tot he fuction return 0 as the product
if(!nums.iterator().hasNext()){
@@ -102,6 +146,13 @@ public class ArrayAlgorithms{
//Return the product of all elements
return product;
}
/**
* Returns the product of all elements in the given iterable collection of {@code BigInteger} objects.
* If the collection is empty, it returns 0.
*
* @param nums the iterable collection of {@code BigInteger} objects to multiply
* @return the product of all {@code BigInteger} objects in the collection, or 0 if the collection is empty
*/
public static BigInteger getBigProd(Iterable<BigInteger> nums){
//If a blank list was passed tot he fuction return 0 as the product
if(!nums.iterator().hasNext()){
@@ -119,7 +170,16 @@ public class ArrayAlgorithms{
//Return the product of all elements
return product;
}
//Print a list
//?Print a list
/**
* Returns a string representation of the given iterable collection, with elements separated by commas
* and enclosed in square brackets.
*
* @param list the iterable collection to print
* @param <T> the type of elements in the collection
* @return a string representation of the collection
*/
public static <T> String printList(Iterable<T> list){
StringJoiner returnString = new StringJoiner(", ", "[", "]");
for(T obj : list){
@@ -127,7 +187,14 @@ public class ArrayAlgorithms{
}
return returnString.toString();
}
//Convert lists
//?Convert lists
/**
* Converts a list of {@code Long} objects to a list of {@code Integer} objects.
*
* @param originalList the list of {@code Long} objects to convert
* @return a list of {@code Integer} objects
*/
public static List<Integer> longToInt(List<Long> originalList){
ArrayList<Integer> newList = new ArrayList<>(originalList.size());
for(Long num : originalList){