Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/extensive refactor #221

Open
wants to merge 32 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f416c0a
Stock class refactored
HerikCosmo Nov 14, 2023
08ce114
refactor GodClass
VictorM-Coder Nov 14, 2023
2b0a46b
Merge pull request #1 from VictorM-Coder/refactor/god-class-stock
VictorM-Coder Nov 14, 2023
44b32b5
Merge branch 'develop' into refactor/god-class-util
VictorM-Coder Nov 14, 2023
3b697d6
Merge pull request #2 from VictorM-Coder/refactor/god-class-util
VictorM-Coder Nov 14, 2023
74930c3
refactor: Builder in HistoricalQuote
HerikCosmo Nov 14, 2023
e720ff8
implementação do builder para stockdividend
VictorM-Coder Nov 14, 2023
a41ed40
Merge branch 'develop' into refactor/excessive-params-list
VictorM-Coder Nov 14, 2023
5d4dd01
Merge pull request #3 from VictorM-Coder/refactor/excessive-params-list
VictorM-Coder Nov 14, 2023
8dde30b
refactor da classe de StockDataUpdate
VictorM-Coder Nov 14, 2023
ca3a428
excessive method lenght fix para CrumbManager
VictorM-Coder Nov 14, 2023
91bfa25
refactor: method getQuotes with excessive-method-length refactored
HerikCosmo Nov 14, 2023
342389b
refactor: method getResult with excessive-method-length refactored
HerikCosmo Nov 14, 2023
69a9161
refactor: method getResult in class QuotesRequest with excessive-meth…
HerikCosmo Nov 14, 2023
cc9806c
refactor: method getResult in class HistQuotes2Request with excessive…
HerikCosmo Nov 14, 2023
86f402f
Merge pull request #4 from VictorM-Coder/refactor/excessive-method-le…
VictorM-Coder Nov 15, 2023
c2daf0d
Merge branch 'develop' into refactor/excessive-method-length
VictorM-Coder Nov 15, 2023
8e151af
Merge pull request #5 from VictorM-Coder/refactor/excessive-method-le…
VictorM-Coder Nov 15, 2023
84d23d9
refactor HistSplitRequest
VictorM-Coder Nov 19, 2023
0175764
refactor HistQuotesRequest
VictorM-Coder Nov 19, 2023
54e982f
refactor HistQuotesQuery2V8Request
VictorM-Coder Nov 19, 2023
e54f487
refactor StockQuotesData
VictorM-Coder Nov 19, 2023
5535bed
refactor QuotesRequest
VictorM-Coder Nov 19, 2023
469e857
StockQuotesQuery1v7Request
VictorM-Coder Nov 19, 2023
e4c6607
refactor BigDecimal
VictorM-Coder Nov 19, 2023
62c6a42
refactor CalendarUtil
VictorM-Coder Nov 19, 2023
0867d99
refactor PrimitiveTypesConvertUtils
VictorM-Coder Nov 19, 2023
89c54d9
Merge pull request #6 from VictorM-Coder/refactor/method-lenght
VictorM-Coder Nov 19, 2023
9414258
refactor FxSymbols
VictorM-Coder Nov 20, 2023
4a663ad
Merge pull request #7 from VictorM-Coder/refactor/class-lenght
VictorM-Coder Nov 20, 2023
baaaef4
style refactor in CrumbManager
VictorM-Coder Nov 22, 2023
919092c
final refactoring
VictorM-Coder Nov 22, 2023
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
11 changes: 11 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,17 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.7</version>
<configuration>
<rulesets>
<ruleset>/rulesets/java/basic.xml</ruleset>
<ruleset>ruleset.xml</ruleset>
</rulesets>
</configuration>
</plugin>
</plugins>
<extensions>
<extension>
Expand Down
36 changes: 36 additions & 0 deletions result-3.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
src\main\java\yahoofinance\Stock.java:30: ExcessiveClassLength: Avoid really long classes.
src\main\java\yahoofinance\YahooFinance.java:46: ExcessiveClassLength: Avoid really long classes.
src\main\java\yahoofinance\exchanges\ExchangeTimeZone.java:15: ExcessiveClassLength: Avoid really long classes.
src\main\java\yahoofinance\histquotes2\CrumbManager.java:27: ExcessiveClassLength: Avoid really long classes.
src\main\java\yahoofinance\histquotes2\HistQuotes2Request.java:23: ExcessiveClassLength: Avoid really long classes.
src\main\java\yahoofinance\histquotes2\HistoricalDividend.java:14: DataClass: The class 'HistoricalDividend' is suspected to be a Data Class (WOC=20.000%, NOPA=0, NOAM=4, WMC=7)
src\main\java\yahoofinance\histquotes2\HistoricalSplit.java:12: DataClass: The class 'HistoricalSplit' is suspected to be a Data Class (WOC=20.000%, NOPA=0, NOAM=4, WMC=7)
src\main\java\yahoofinance\histquotes\HistQuotesRequest.java:26: ExcessiveClassLength: Avoid really long classes.
src\main\java\yahoofinance\histquotes\HistoricalQuote.java:13: ExcessiveClassLength: Avoid really long classes.
src\main\java\yahoofinance\query2v8\HistQuotesQuery2V8Request.java:34: ExcessiveClassLength: Avoid really long classes.
src\main\java\yahoofinance\query2v8\HistQuotesQuery2V8Request.java:96: ExcessiveMethodLength: Avoid really long methods.
src\main\java\yahoofinance\quotes\csv\QuotesProperty.java:7: ExcessiveClassLength: Avoid really long classes.
src\main\java\yahoofinance\quotes\csv\StockQuotesData.java:16: ExcessiveClassLength: Avoid really long classes.
src\main\java\yahoofinance\quotes\csv\StockQuotesData.java:32: ExcessiveMethodLength: Avoid really long methods.
src\main\java\yahoofinance\quotes\csv\StockQuotesRequest.java:10: ExcessiveClassLength: Avoid really long classes.
src\main\java\yahoofinance\quotes\csv\StockQuotesRequest.java:107: ExcessiveMethodLength: Avoid really long methods.
src\main\java\yahoofinance\quotes\fx\FxSymbols.java:6: DataClass: The class 'FxSymbols' is suspected to be a Data Class (WOC=0.000%, NOPA=89, NOAM=0, WMC=0)
src\main\java\yahoofinance\quotes\query1v7\StockQuotesQuery1V7Request.java:20: ExcessiveClassLength: Avoid really long classes.
src\main\java\yahoofinance\quotes\query1v7\StockQuotesQuery1V7Request.java:58: ExcessiveMethodLength: Avoid really long methods.
src\main\java\yahoofinance\quotes\query1v7\StockQuotesQuery1V7Request.java:112: ExcessiveMethodLength: Avoid really long methods.
src\main\java\yahoofinance\quotes\stock\StockDividend.java:12: DataClass: The class 'StockDividend' is suspected to be a Data Class (WOC=18.182%, NOPA=0, NOAM=9, WMC=15)
src\main\java\yahoofinance\quotes\stock\StockQuote.java:16: ExcessiveClassLength: Avoid really long classes.
src\main\java\yahoofinance\quotes\stock\StockStats.java:14: ExcessiveClassLength: Avoid really long classes.
src\main\java\yahoofinance\quotes\stock\StockStats.java:14: DataClass: The class 'StockStats' is suspected to be a Data Class (WOC=5.128%, NOPA=0, NOAM=37, WMC=41)
src\main\java\yahoofinance\utils\CalendarUtil.java:11: ExcessiveClassLength: Avoid really long classes.
src\main\java\yahoofinance\utils\RedirectableRequest.java:12: DataClass: The class 'RedirectableRequest' is suspected to be a Data Class (WOC=20.000%, NOPA=0, NOAM=8, WMC=22)
src\main\java\yahoofinance\utils\RedirectableRequest.java:37: ExcessiveMethodLength: Avoid really long methods.
src\main\java\yahoofinance\utils\Utils.java:63: ExcessiveMethodLength: Avoid really long methods.
src\test\java\yahoofinance\HistoricalQuoteRequestTest.java:21: ExcessiveClassLength: Avoid really long classes.
src\test\java\yahoofinance\HistoricalQuoteRequestTest.java:38: ExcessiveMethodLength: Avoid really long methods.
src\test\java\yahoofinance\HistoricalQuoteRequestTest.java:81: ExcessiveMethodLength: Avoid really long methods.
src\test\java\yahoofinance\SimpleQuoteRequestTest.java:18: ExcessiveClassLength: Avoid really long classes.
src\test\java\yahoofinance\SimpleQuoteRequestTest.java:21: ExcessiveMethodLength: Avoid really long methods.
src\test\java\yahoofinance\SimpleQuoteRequestTest.java:91: ExcessiveMethodLength: Avoid really long methods.
src\test\java\yahoofinance\SimpleQuoteRequestTest.java:125: ExcessiveMethodLength: Avoid really long methods.
src\test\java\yahoofinance\mock\MockedServersTest.java:27: ExcessiveMethodLength: Avoid really long methods.
27 changes: 27 additions & 0 deletions ruleset.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0"?>
<ruleset name="Custom ruleset"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0
http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
<description>
This ruleset checks my code for bad stuff
</description>
<rule ref="category/java/design.xml/ExcessiveParameterList">
<properties>
<property name="minimum" value="4" />
</properties>
</rule>
<rule ref="category/java/design.xml/ExcessiveClassLength">
<properties>
<property name="minimum" value="100" />
</properties>
</rule>
<rule ref="category/java/design.xml/ExcessiveMethodLength">
<properties>
<property name="minimum" value="20" />
</properties>
</rule>
<rule ref="category/java/design.xml/GodClass" />
<rule ref="category/java/design.xml/DataClass" />
</ruleset>
45 changes: 7 additions & 38 deletions src/main/java/yahoofinance/Stock.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,42 +39,20 @@ public class Stock {
private StockQuote quote;
private StockStats stats;
private StockDividend dividend;

private final StockDataUpdater dataUpdater;

private List<HistoricalQuote> history;
private List<HistoricalDividend> dividendHistory;
private List<HistoricalSplit> splitHistory;

public Stock(String symbol) {
this.symbol = symbol;
this.dataUpdater = new StockDataUpdater(this, symbol);
}

private void update() throws IOException {
if(YahooFinance.QUOTES_QUERY1V7_ENABLED.equalsIgnoreCase("true")) {
StockQuotesQuery1V7Request request = new StockQuotesQuery1V7Request(this.symbol);
Stock stock = request.getSingleResult();
if (stock != null) {
this.setName(stock.getName());
this.setCurrency(stock.getCurrency());
this.setStockExchange(stock.getStockExchange());
this.setQuote(stock.getQuote());
this.setStats(stock.getStats());
this.setDividend(stock.getDividend());
log.info("Updated Stock with symbol: {}", this.symbol);
} else {
log.error("Failed to update Stock with symbol: {}", this.symbol);
}
} else {
StockQuotesRequest request = new StockQuotesRequest(this.symbol);
StockQuotesData data = request.getSingleResult();
if (data != null) {
this.setQuote(data.getQuote());
this.setStats(data.getStats());
this.setDividend(data.getDividend());
log.info("Updated Stock with symbol: {}", this.symbol);
} else {
log.error("Failed to update Stock with symbol: {}", this.symbol);
}
}
dataUpdater.update();
}

/**
Expand Down Expand Up @@ -114,10 +92,7 @@ public StockQuote getQuote() {
* @throws java.io.IOException when there's a connection problem
*/
public StockQuote getQuote(boolean refresh) throws IOException {
if(refresh) {
this.update();
}
return this.quote;
return dataUpdater.getQuote(refresh);
}

public void setQuote(StockQuote quote) {
Expand Down Expand Up @@ -153,10 +128,7 @@ public StockStats getStats() {
* @throws java.io.IOException when there's a connection problem
*/
public StockStats getStats(boolean refresh) throws IOException {
if(refresh) {
this.update();
}
return this.stats;
return dataUpdater.getStats(refresh);
}

public void setStats(StockStats stats) {
Expand Down Expand Up @@ -193,10 +165,7 @@ public StockDividend getDividend() {
* @throws java.io.IOException when there's a connection problem
*/
public StockDividend getDividend(boolean refresh) throws IOException {
if(refresh) {
this.update();
}
return this.dividend;
return dataUpdater.getDividend(refresh);
}

public void setDividend(StockDividend dividend) {
Expand Down
95 changes: 95 additions & 0 deletions src/main/java/yahoofinance/StockDataUpdater.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package yahoofinance;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import yahoofinance.quotes.csv.StockQuotesData;
import yahoofinance.quotes.csv.StockQuotesRequest;
import yahoofinance.quotes.query1v7.StockQuotesQuery1V7Request;
import yahoofinance.quotes.stock.StockDividend;
import yahoofinance.quotes.stock.StockQuote;
import yahoofinance.quotes.stock.StockStats;

import java.io.IOException;

public class StockDataUpdater {
private static final Logger log = LoggerFactory.getLogger(StockDataUpdater.class);

private Stock stock;
private String symbol;

public StockDataUpdater(Stock stock, String symbol) {
this.stock = stock;
this.symbol = symbol;
}

public void update() throws IOException {
if(YahooFinance.QUOTES_QUERY1V7_ENABLED.equalsIgnoreCase("true")) {
StockQuotesQuery1V7Request request = new StockQuotesQuery1V7Request(this.symbol);
Stock stockResponse = request.getSingleResult();
if (stockResponse != null) {
updateStock(stockResponse);
} else {
log.error("Failed to update Stock with symbol: {}", this.symbol);
}
} else {
StockQuotesRequest request = new StockQuotesRequest(this.symbol);
StockQuotesData data = request.getSingleResult();
if (data != null) {
updateStock(data);
} else {
log.error("Failed to update Stock with symbol: {}", this.symbol);
}
}
}

public StockQuote getQuote() {
return stock.getQuote();
}

public StockQuote getQuote(boolean refresh) throws IOException {
if(refresh) {
update();
}
return getQuote();
}

public StockStats getStats() {
return stock.getStats();
}

public StockStats getStats(boolean refresh) throws IOException {
if(refresh) {
update();
}
return getStats();
}

public StockDividend getDividend() {
return stock.getDividend();
}

public StockDividend getDividend(boolean refresh) throws IOException {
if(refresh) {
update();
}

return getDividend();
}

private void updateStock(Stock stockResponse){
stock.setName(stockResponse.getName());
stock.setCurrency(stockResponse.getCurrency());
stock.setStockExchange(stockResponse.getStockExchange());
stock.setQuote(stockResponse.getQuote());
stock.setStats(stockResponse.getStats());
stock.setDividend(stockResponse.getDividend());
log.info("Updated Stock with symbol: {}", this.symbol);
}

private void updateStock(StockQuotesData data) {
stock.setQuote(data.getQuote());
stock.setStats(data.getStats());
stock.setDividend(data.getDividend());
log.info("Updated Stock with symbol: {}", this.symbol);
}
}
Loading