Author: batosai
Date: 2008-08-05 15:31:12 +0000 (Tue, 05 Aug 2008)
New Revision: 21618
Modified:
trunk/apps/WoT/src/plugins/WoT/WoT.java
Log:
Comments.
Modified: trunk/apps/WoT/src/plugins/WoT/WoT.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/WoT.java 2008-08-05 15:13:22 UTC (rev
21617)
+++ trunk/apps/WoT/src/plugins/WoT/WoT.java 2008-08-05 15:31:12 UTC (rev
21618)
@@ -37,32 +37,36 @@
this.db = db;
}
+ /**
+ * Handles the creation of a new trust relationship, or the update of
an existing one.
+ * @param newTrust A Trust object reflecting the trust relationship.
+ */
public void setTrust(Trust newTrust) {
boolean changedTrustValue = false;
boolean changedComment = false;
ObjectSet<Trust> trustResult = db.queryByExample(new
Trust(newTrust.getTruster(), newTrust.getTrustee(), 0));
- if(trustResult.size() != 0) {
+ if(trustResult.size() != 0) { // We are updating a existing
trust relationship
Trust oldTrust = trustResult.next();
- if(oldTrust.getValue() != newTrust.getValue()) {
+ if(oldTrust.getValue() != newTrust.getValue()) { // The
trust value has changed
changedTrustValue = true;
oldTrust.setValue(newTrust.getValue());
}
- if(oldTrust.getComment() != newTrust.getComment()) {
+ if(oldTrust.getComment() != newTrust.getComment()) { //
The comment has changed
changedComment = true;
oldTrust.setComment(newTrust.getComment());
}
- if(changedComment || changedTrustValue)
db.store(oldTrust);
+ if(changedComment || changedTrustValue)
db.store(oldTrust); // We store the changes, if needed
}
- else {
+ else { // This is a new trust relationship
db.store(newTrust);
changedTrustValue = true;
}
- if(changedTrustValue) {
+ if(changedTrustValue) { // We have to update the trust tree,
starting with the trustee
ObjectSet<OwnIdentity> ownIdentites =
db.queryByExample(OwnIdentity.class);
- while(ownIdentites.hasNext()) {
+ while(ownIdentites.hasNext()) { // Each OwnIdentity has
its trust tree, we update all
updateScore(ownIdentites.next(),
newTrust.getTrustee());
}
}
@@ -83,7 +87,7 @@
int newCapacity = 0;
boolean hasNegativeTrust = false;
-
+ // We get the score of the identity, or create one if it
doesn't exist
ObjectSet<Score> scoreResult = db.queryByExample(new
Score(treeOwner, identity, 0, 0, 0));
if(scoreResult.hasNext()) {
score = scoreResult.next();
@@ -91,12 +95,14 @@
}
else score = new Score(treeOwner, identity, 0, -1, 0);
+ // We get the trust given by the tree owner (because if it is
negative, the identity has no capacity)
ObjectSet<Trust> trustResult = db.queryByExample(new
Trust(treeOwner, identity, 0));
if(trustResult.hasNext()) {
Trust trust = trustResult.next();
if(trust.getValue() <= 0) hasNegativeTrust = true;
}
+ // We get get all trust received by the identity
ObjectSet<Trust> trusters = db.queryByExample(new Trust(null,
identity, 0));
while(trusters.hasNext()) {
@@ -104,13 +110,14 @@
Score trusterScore;
+ // We get the score of each identity that gives trust
to this one
ObjectSet<Score> trustersScore = db.queryByExample(new
Score(treeOwner, trusterTrust.getTruster(), 0, 0, 0));
if(trustersScore.hasNext()) trusterScore =
trustersScore.next();
- else trusterScore = new Score(treeOwner,
trusterTrust.getTruster(), 0, -1, 0);
+ else trusterScore = new Score(treeOwner,
trusterTrust.getTruster(), 0, -1, 0); // This can only happen when you have
multiple primary identities
- if(trusterScore.getCapacity() > 0) {
- newScore += trusterScore.getCapacity() *
trusterTrust.getValue() / 100;
- if(newRank == -1 || newRank >
trusterScore.getRank())
+ if(trusterScore.getCapacity() > 0) { // If the truster
has capacity
+ newScore += trusterScore.getCapacity() *
trusterTrust.getValue() / 100; // We update the trustee's score
+ if(newRank == -1 || newRank >
trusterScore.getRank()) // We store the lowest truster's rank (but not -1)
newRank = trusterScore.getRank();
}
}
@@ -125,8 +132,9 @@
score.setScore(newScore);
db.store(score);
+ // We don't commit here because this method is going to be
called *many* times while parsing a trust list.
- if(oldCapacity != newCapacity) {
+ if(oldCapacity != newCapacity) { // If the capacity has
changed, we have to update all identities this one trusts
ObjectSet<Trust> trustees = db.queryByExample(new
Trust(identity, null, 0));
while(trustees.hasNext()) {
Trust trustee = trustees.next();
@@ -135,11 +143,18 @@
}
}
+ /**
+ * @return The number of OwnIdentities in the WoT
+ */
public int getNbOwnIdentities() {
ObjectSet<OwnIdentity> ownIdentities =
db.queryByExample(OwnIdentity.class);
return ownIdentities.size();
}
+ /**
+ *
+ * @return The number of Identities in the WoT
+ */
public int getNbIdentities() {
ObjectSet<Identity> identities =
db.queryByExample(Identity.class);
return identities.size() - getNbOwnIdentities();