Skip to content

Commit

Permalink
refactor: adhere to Error Prone rules
Browse files Browse the repository at this point in the history
  • Loading branch information
algonell committed Feb 23, 2024
1 parent 7d7a0b1 commit 4ac8eb8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 66 deletions.
20 changes: 11 additions & 9 deletions src/main/java/com/fxminer/Quote.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.fxminer;

import java.io.Serializable;
import java.util.Date;
import java.time.ZonedDateTime;

/**
* Container for basic asset data (FX currency pair, Stock and etc.).
Expand All @@ -20,7 +20,7 @@ public class Quote implements QuoteValidator, Serializable {
protected double close;
protected double adjClose;
protected long volume;
protected Date timestamp;
protected ZonedDateTime timestamp;

/** Trend. */
protected String classifiedTrend;
Expand All @@ -32,14 +32,14 @@ public Quote(
double close,
double adjClose,
long volume,
Date timestamp) {
ZonedDateTime timestamp) {
this.open = open;
this.high = high;
this.low = low;
this.close = close;
this.adjClose = adjClose;
this.volume = volume;
this.timestamp = new Date(timestamp.getTime());
this.timestamp = timestamp;
}

public double getAdjClose() {
Expand All @@ -66,12 +66,12 @@ public void setClassifiedTrend(String classifiedTrend) {
this.classifiedTrend = classifiedTrend;
}

public Date getTimestamp() {
return new Date(timestamp.getTime());
public ZonedDateTime getTimestamp() {
return timestamp;
}

public void setTimestamp(Date timestamp) {
this.timestamp = new Date(timestamp.getTime());
public void setTimestamp(ZonedDateTime timestamp) {
this.timestamp = timestamp;
}

public double getOpen() {
Expand Down Expand Up @@ -107,11 +107,13 @@ public void setClose(double close) {
}

/** Checks if the data is clean and ready for calculations. */
@Override
public boolean isCleanAttribute() {
return open != 0 && high != 0 && low != 0 && close != 0;
}

/** Checks if the data is clean and ready for calculations. */
@Override
public boolean isCleanClass() {
return !classifiedTrend.equals(Trend.UNCERTAINTY.name())
&& !classifiedTrend.equals(Trend.RANGING.name());
Expand All @@ -121,7 +123,7 @@ public boolean isCleanClass() {
public String toString() {
var sb = new StringBuilder();

sb.append(timestamp.getTime()).append(",");
sb.append(timestamp.toEpochSecond()).append(",");

// OHLC
sb.append(open)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/fxminer/Symbol.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public long calculateAvgVol() {

// calc mean
for (var i = 0; i < 63; i++) {
stats.addValue(history.get(i).getVolume());
stats.addValue((double) history.get(i).getVolume());
}

return (long) stats.getMean();
Expand Down
67 changes: 11 additions & 56 deletions src/main/java/com/fxminer/ZigZag.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,7 @@ public ZigZag(int depth, int deviation, int backstep, double point) {
deviationInPoints = deviation * point;
}

/**
* Searches for index of the highest bar.
*
* @param array
* @param depth
* @param startPos
*/
/** Searches for index of the highest bar. */
private int iHighest(double[] array, int depth, int startPos) {
var index = startPos;

Expand All @@ -85,16 +79,10 @@ private int iHighest(double[] array, int depth, int startPos) {
}

// --- return index of the highest bar
return (index);
return index;
}

/**
* Searches for index of the lowest bar
*
* @param array
* @param depth
* @param startPos
*/
/** Searches for index of the lowest bar */
private int iLowest(double[] array, int depth, int startPos) {
var index = startPos;

Expand All @@ -120,16 +108,10 @@ private int iLowest(double[] array, int depth, int startPos) {
}

// --- return index of the lowest bar
return (index);
return index;
}

/**
* Performs custom calculation.
*
* @param ratesTotal
* @param high
* @param low
*/
/** Performs custom calculation. */
public void calculate(int ratesTotal, double[] high, double[] low) {
init(ratesTotal);

Expand Down Expand Up @@ -210,12 +192,7 @@ private void searchForPeak() {
}
}

/**
* Searches for peak or lawn.
*
* @param high
* @param low
*/
/** Searches for peak or lawn. */
private void searchForPeakOrLawn(double[] high, double[] low) {
if (lastlow == 0 && lasthigh == 0) {
if (highMapBuffer[shift] != 0) {
Expand All @@ -234,13 +211,7 @@ private void searchForPeakOrLawn(double[] high, double[] low) {
}
}

/**
* Searches for high and low.
*
* @param ratesTotal
* @param high
* @param low
*/
/** Searches for high and low. */
private void searchForHighAndLow(int ratesTotal, double[] high, double[] low) {
for (shift = limit; shift < ratesTotal; shift++) {
handleLowFound(low);
Expand All @@ -250,11 +221,7 @@ private void searchForHighAndLow(int ratesTotal, double[] high, double[] low) {
}
}

/**
* Handles low found.
*
* @param low
*/
/** Handles low found. */
private void handleLowFound(double[] low) {
val = low[iLowest(low, depth, shift)];

Expand All @@ -276,11 +243,7 @@ private void handleLowFound(double[] low) {
else lowMapBuffer[shift] = 0.0;
}

/**
* Handles found high.
*
* @param high
*/
/** Handles found high. */
private void handleHighFound(double[] high) {
val = high[iHighest(high, depth, shift)];

Expand All @@ -302,11 +265,7 @@ private void handleHighFound(double[] high) {
else highMapBuffer[shift] = 0.0;
}

/**
* Performs calculations if previously done.
*
* @param ratesTotal
*/
/** Performs calculations if previously done. */
private void calculateIfAlreadyCountedBefore(int ratesTotal) {
int i;
if (prevCalculated > 0) {
Expand Down Expand Up @@ -342,11 +301,7 @@ private void calculateIfAlreadyCountedBefore(int ratesTotal) {
}
}

/**
* Initializes variables.
*
* @param ratesTotal
*/
/** Initializes variables. */
private void init(int ratesTotal) {
limit = 0;
counterZ = 0;
Expand Down

0 comments on commit 4ac8eb8

Please sign in to comment.