Skip to content

Commit

Permalink
Merge pull request #36 from solvena/Diagrams
Browse files Browse the repository at this point in the history
Diagrams
  • Loading branch information
solvena authored May 25, 2026
2 parents efa9a1f + 76c4fd1 commit e36e00d
Show file tree
Hide file tree
Showing 35 changed files with 3,726 additions and 2,492 deletions.
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

0 comments on commit e36e00d

Please sign in to comment.