-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: creating CalculateNodeReputationTask
- Loading branch information
1 parent
9034ff3
commit aea653e
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
src/main/java/reputation/node/tasks/CalculateNodeReputationTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package reputation.node.tasks; | ||
|
||
import dlt.client.tangle.hornet.model.transactions.Transaction; | ||
import java.util.List; | ||
import java.util.TimerTask; | ||
import reputation.node.models.Node; | ||
import reputation.node.reputation.IReputation; | ||
|
||
/** | ||
* Task para calcular a reputação atual do nó. | ||
* | ||
* @author Allan Capistrano | ||
* @version 1.0.0 | ||
*/ | ||
public class CalculateNodeReputationTask extends TimerTask { | ||
|
||
private final Node node; | ||
private final IReputation reputation; | ||
|
||
/** | ||
* Método construtor. | ||
* @param node Node - O nó que verificará a própria reputação. | ||
* @param reputation IReputation - Objeto para calcular a reputação. | ||
*/ | ||
public CalculateNodeReputationTask(Node node, IReputation reputation) { | ||
this.node = node; | ||
this.reputation = reputation; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
List<Transaction> evaluationTransactions = | ||
this.node.getLedgerConnector() | ||
.getLedgerReader() | ||
.getTransactionsByIndex(this.node.getNodeType().getNodeId(), false); | ||
|
||
double reputationValue = | ||
this.reputation.calculate( | ||
evaluationTransactions, | ||
this.node.isUseLatestCredibility(), | ||
this.node.isUseCredibility() | ||
); | ||
|
||
this.node.setReputationValue(reputationValue); | ||
} | ||
} |