diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index c3d8d78..6f6ec43 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -199,6 +199,11 @@ public class Spreadsheet { cells[row][col].setValue("" + result); } + /** + * Method to extract the corner cells for a function formula. + * @param formula The formula to isolate the corners for + * @return The formulas corners. + */ public String[] isolateFunctionCorners(String formula){ //? isolate corners ArrayList corners = new ArrayList(); @@ -214,6 +219,13 @@ public class Spreadsheet { return corners.toArray(new String[0]); } + /** + * A methode to extract a block of cells used in a function formula, + * such as A1 and B3 for SUMME(A1:B3). + * Calls the isolateFunctionCorners methode to get the blocks corners. + * @param formula The formula to get the block for. + * @return The cell block. + */ public String[] wholeFunctionBlock(String formula){ String[] corners = isolateFunctionCorners(formula); @@ -236,10 +248,9 @@ public class Spreadsheet { return block.toArray(new String[0]); } - /* + /** * Method for calculating the sum of a rectangular block of cells, such as from A1 to B3. - * @param startCellName The name of the cell in the upper left corner of the rectangle. - * @param endCellName The name of the cell in the lower right corner of the rectangle. + * @param formula The formula to calculate the sum. * @return The sum calculated. */ public long sum(String formula) { @@ -255,6 +266,11 @@ public class Spreadsheet { return res; } + /** + * Method for calculating the product of a rectangular block of cells, such as from A1 to B3. + * @param formula The formula to calculate the product. + * @return The product calculated. + */ public long prod(String formula){ String[] block = wholeFunctionBlock(formula); @@ -276,6 +292,11 @@ public class Spreadsheet { return res; } + /** + * Method for calculating the average of a rectangular block of cells, such as from A1 to B3. + * @param formula The formula to calculate the average. + * @return The average calculated. + */ public long avrg(String formula){ String[] block = wholeFunctionBlock(formula); @@ -302,6 +323,12 @@ public class Spreadsheet { return res; } + /** + * Method for calculating the standard deviation of a rectangular block of cells, such as from A1 to B3. + * Calls the average method. + * @param formula The formula to calculate the standard deviation. + * @return The standard deviation calculated. + */ public long stdDevp(String formula){ String[] block = wholeFunctionBlock(formula); @@ -324,6 +351,11 @@ public class Spreadsheet { return (long) Math.sqrt(variance); } + /** + * Method for selecting the minimum of a rectangular block of cells, such as from A1 to B3. + * @param formula The formula to select the minimum from. + * @return The minimum selected. + */ public long min(String formula){ String[] block = wholeFunctionBlock(formula); @@ -347,6 +379,11 @@ public class Spreadsheet { return currentSmallest; } + /** + * Method for selecting the maximum of a rectangular block of cells, such as from A1 to B3. + * @param formula The formula to select the maximum from. + * @return The maximum selected. + */ public long max(String formula){ String[] block = wholeFunctionBlock(formula); @@ -371,6 +408,12 @@ public class Spreadsheet { return currentBiggest; } + /** + * Method to extract only cells which are not empty from a previously calculated block from a + * function formula. + * @param block Block with empty and not empty cells. + * @return Block with only not empty cells. + */ public String[] extractNotEmptyCells(String[] block){ ArrayList notEmptyValues = new ArrayList(); @@ -381,7 +424,6 @@ public class Spreadsheet { notEmptyValues.add(cellValue); } } - return notEmptyValues.toArray(new String[0]); } @@ -416,6 +458,13 @@ public class Spreadsheet { return res; } + /** + * Method to extract every single element of an expression and stores them as a separate element in the + * String ArrayList formulaElements and returns it. + * An expression element is either a number, a cell name or an operator. + * @param formula The formula expression to extract elements from. + * @return The elements as single elements. + */ public static ArrayList extractExpressionElements(String formula){ Matcher m = Pattern.compile("([A-Z][0-9]*)|[-\\+\\*/]|[0-9]*").matcher(formula); @@ -431,6 +480,15 @@ public class Spreadsheet { return formulaElements; } + /** + * Method to calculate a single calculation. A single calculation always uses one operator and one value part. + * The value part can be a cell name or a value. The calculation takes the given previous solution and uses the given + * operator and the given value part to calculate and return a new solution. + * @param res The previous result of a calculation. + * @param element The element to calculate to the previous result. + * @param operator The operator used to calculate previous result and element. + * @return The new result. + */ private long singleCalculation(long res, String element, String operator){ String elementType = isValueCellName(element); @@ -460,7 +518,12 @@ public class Spreadsheet { return res; } - + /** + * Methode to determine if a value part is either a cell name or a value. + * Has the possibility to determine floating point numbers for the future. + * @param sToCheck The string to decide. + * @return The String containing the information if it is a cell name or a value. + */ public String isValueCellName(String sToCheck){ //? 7 -> "value", A1 -> "cellName", 7A -> "invalid"