Skip to content

Diagrams #36

Merged
merged 24 commits into from
May 25, 2026
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7ce2816
Added Checkstyle to Exchange
elisab3 May 24, 2026
50bf4be
Added Checkstyle to ExchangeObserver
elisab3 May 24, 2026
f435314
Added Checkstyle to Player
elisab3 May 24, 2026
b08e846
Added Checkstyle to PlayerStatus
elisab3 May 24, 2026
2774464
Added Checkstyle to Portfolio
elisab3 May 24, 2026
6803d26
Added Checkstyle to Purchase
elisab3 May 24, 2026
03e503c
Added Checkstyle to PurchaseCalculator
elisab3 May 24, 2026
e2c15cb
Added Checkstyle to Sale
elisab3 May 24, 2026
b8e334c
Added Checkstyle to SaleCalculator
elisab3 May 24, 2026
098388e
Added Checkstyle to Share
elisab3 May 24, 2026
dd22359
Added Checkstyle to Stock
elisab3 May 24, 2026
e40cc48
Added Checkstyle to Transaction
elisab3 May 24, 2026
2a35c2e
Added Checkstyle to TransactionArchive
elisab3 May 24, 2026
19b9c89
Added Checkstyle to TransactionCalculator
elisab3 May 24, 2026
3700545
Added Checkstyle to TransactionFactory
elisab3 May 24, 2026
9310799
Added Checkstyle to GameSetupScene
elisab3 May 24, 2026
21f91a6
Added Checkstyle to Launcher
elisab3 May 24, 2026
bd3591d
Added Checkstyle to StockTradingGameApp
elisab3 May 24, 2026
38d0471
Add checkstyle to GameSetupScene
elisab3 May 25, 2026
60c2191
Improve Javadocs
elisab3 May 25, 2026
5eb6c99
Added Checkstyle and Javadocs to test-classes
elisab3 May 25, 2026
d896b96
Merge branch 'main' into 32-create-javadocs-and-add-checkstyle
elisab3 May 25, 2026
7fb1ee0
Improved Checkstyle on test-classes
elisab3 May 25, 2026
76c4fd1
Merge branch '32-create-javadocs-and-add-checkstyle' of https://git.n…
elisab3 May 25, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"java.checkstyle.configuration": "/google_checks.xml"
}
101 changes: 101 additions & 0 deletions checkstyle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">

<!--
Google's Java Style Guide: https://google.github.io/styleguide/javaguide.html
-->
<module name="Checker">
<property name="charset" value="UTF-8"/>
<property name="severity" value="warning"/>
<property name="fileExtensions" value="java,properties,xml"/>

<!-- Excludes all 'module' directory -->
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="module\-info\.java$"/>
</module>

<!-- File length -->
<module name="FileLength">
<property name="max" value="2000"/>
<property name="severity" value="ignore"/>
</module>

<!-- Line length -->
<module name="LineLength">
<property name="max" value="100"/>
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
</module>

<!-- No trailing whitespace -->
<module name="RegexpSingleline">
<property name="format" value="\s+$"/>
<property name="message" value="Line has trailing spaces."/>
</module>

<!-- No tabs -->
<module name="RegexpSingleline">
<property name="format" value="^\t+"/>
<property name="message" value="Line contains tabs."/>
</module>

<module name="TreeWalker">
<!-- Imports -->
<module name="AvoidStarImport"/>
<module name="RedundantImport"/>
<module name="UnusedImports"/>

<!-- Javadoc -->
<module name="JavadocMethod">
<property name="accessModifiers" value="public"/>
<property name="severity" value="warning"/>
<property name="allowMissingParamTags" value="false"/>
<property name="allowMissingReturnTag" value="false"/>
</module>
<module name="JavadocType">
<property name="severity" value="warning"/>
</module>
<module name="JavadocStyle">
<property name="checkFirstSentence" value="true"/>
</module>

<!-- Naming conventions -->
<module name="TypeName">
<property name="format" value="^[A-Z][a-zA-Z0-9]*$"/>
</module>
<module name="MethodName">
<property name="format" value="^[a-z][a-zA-Z0-9]*$"/>
</module>
<module name="ConstantName">
<property name="format" value="^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$"/>
</module>
<module name="LocalVariableName">
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
</module>
<module name="MemberName">
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
</module>
<module name="ParameterName">
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
</module>

<!-- Whitespace -->
<module name="GenericWhitespace"/>
<module name="MethodParamPad"/>
<module name="NoWhitespaceAfter">
<property name="tokens" value="BNOT,DEC,DOT,INC,LNOT,UNARY_MINUS,UNARY_PLUS"/>
</module>
<module name="NoWhitespaceBefore"/>
<module name="OperatorWrap"/>
<module name="ParenPad"/>
<module name="TypecastParenPad"/>

<!-- Other checks -->
<module name="EmptyBlock"/>
<module name="NeedBraces"/>
<module name="OneStatementPerLine"/>
<module name="EqualsHashCode"/>
<module name="StringLiteralEquality"/>
</module>
</module>
21 changes: 21 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,27 @@
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.12.0</version>
</plugin>

<!-- Checkstyle plugin for Google Java Style -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.3.1</version>
<configuration>
<configLocation>checkstyle.xml</configLocation>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>false</failsOnError>
<failOnViolation>false</failOnViolation>
</configuration>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>10.12.5</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
69 changes: 45 additions & 24 deletions src/main/java/Controller/StockFileHandler.java
Original file line number Diff line number Diff line change
@@ -1,37 +1,58 @@
package Controller;
import java.nio.file.*;

import Model.Stock;
import java.io.IOException;
import java.math.BigDecimal;
import java.nio.file.*;
import java.util.ArrayList;
import java.util.List;

import Model.Stock;

/**
* Handles loading and saving Stock data from/to CSV files.
* The CSV format is: ticker,company_name,price
* Lines starting with '#' are treated as comments and ignored.
*/
public class StockFileHandler {

// lesing
public List<Stock> loadStocksFromFile(String filename) throws IOException {
return Files.readAllLines(Paths.get(filename)).stream()
.map(String::trim)
.filter(line -> !line.isEmpty() && !line.startsWith("#"))
.map(line -> line.split(","))
.filter(parts -> parts.length == 3)
.map(parts -> new Stock(parts[0], parts[1], new BigDecimal(parts[2])))
.toList();
}
/**
* Loads stocks from a CSV file.
* Expected format: ticker,company,price
* Empty lines and lines starting with '#' are ignored.
*
* @param filename the path to the CSV file
* @return a list of Stock objects loaded from the file
* @throws IOException if the file cannot be read
*/
public List<Stock> loadStocksFromFile(String filename) throws IOException {
return Files.readAllLines(Paths.get(filename)).stream()
.map(String::trim)
.filter(line -> !line.isEmpty() && !line.startsWith("#"))
.map(line -> line.split(","))
.filter(parts -> parts.length == 3)
.map(parts -> new Stock(parts[0], parts[1], new BigDecimal(parts[2])))
.toList();
}

// lagring
public void saveStocksToFile(String filename, List<Stock> stocks) throws IOException {
List<String> lines = new ArrayList<>();
lines.add("# Ticker,Name,Price");
/**
* Saves stocks to a CSV file.
* The file includes a header comment line followed by one stock per line.
*
* @param filename the path to the CSV file to write
* @param stocks the list of stocks to save
* @throws IOException if the file cannot be written
*/
public void saveStocksToFile(String filename, List<Stock> stocks) throws IOException {
List<String> lines = new ArrayList<>();
lines.add("# Ticker,Name,Price");

lines.addAll(stocks.stream()
.map(stock -> String.format("%s,%s,%s",
stock.getSymbol(),
stock.getCompany(),
stock.getSalesPrice().toString()))
.toList());
lines.addAll(stocks.stream()
.map(stock -> String.format("%s,%s,%s",
stock.getSymbol(),
stock.getCompany(),
stock.getSalesPrice().toString()))
.toList());

Files.write(Paths.get(filename), lines);
}
Files.write(Paths.get(filename), lines);
}
}
Loading