[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [taler-schemafuzz] branch master updated: corrected some sh
From: |
gnunet |
Subject: |
[GNUnet-SVN] [taler-schemafuzz] branch master updated: corrected some shitty implementation and lightened up some code. Stop laughing Christian |
Date: |
Tue, 22 May 2018 16:40:10 +0200 |
This is an automated email from the git hooks/post-receive script.
erwan-ulrich pushed a commit to branch master
in repository schemafuzz.
The following commit(s) were added to refs/heads/master by this push:
new b626899 corrected some shitty implementation and lightened up some
code. Stop laughing Christian
b626899 is described below
commit b62689956c4c2c20ad28c0de3da199028c0f79b7
Author: Feideus <address@hidden>
AuthorDate: Tue May 22 16:39:59 2018 +0200
corrected some shitty implementation and lightened up some code. Stop
laughing Christian
---
src/main/java/org/schemaspy/DBFuzzer.java | 201 ++++--
src/main/java/org/schemaspy/Main.java | 2 -
src/main/java/org/schemaspy/model/GenericTree.java | 188 +-----
.../java/org/schemaspy/model/GenericTreeNode.java | 726 +++++++++------------
4 files changed, 476 insertions(+), 641 deletions(-)
diff --git a/src/main/java/org/schemaspy/DBFuzzer.java
b/src/main/java/org/schemaspy/DBFuzzer.java
index 980e261..f65602d 100644
--- a/src/main/java/org/schemaspy/DBFuzzer.java
+++ b/src/main/java/org/schemaspy/DBFuzzer.java
@@ -9,8 +9,6 @@ import org.schemaspy.model.*;
import org.schemaspy.model.Table;
import org.schemaspy.model.GenericTree;
import org.schemaspy.model.GenericTreeNode;
-import org.schemaspy.service.DatabaseService;
-import org.schemaspy.service.SqlService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
@@ -22,103 +20,146 @@ public class DBFuzzer
private static final Logger LOGGER =
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
- public SqlService sqlService;
-
- private SchemaAnalyzer analyzer;
-
- private DatabaseService databaseService;
+ private SchemaAnalyzer analyzer; // Passed from the schemaAnalyser object
from the runAnalyzer part. Contains sqlService object used to perform sql
Queries
private GenericTree mutationTree = new GenericTree();
public DBFuzzer(SchemaAnalyzer analyzer)
{
- this.sqlService = Objects.requireNonNull(analyzer.getSqlService());
- this.databaseService =
Objects.requireNonNull(analyzer.getDatabaseService());
this.analyzer = analyzer;
}
+ public boolean processFirstMutation(GenericTreeNode rootMutation)
+ {
+ boolean resQuery,returnStatus=true;
+ try
+ {
+ if(rootMutation.getChosenChange() != null)
+ {
+ resQuery = rootMutation.inject(analyzer,false);
+ if(resQuery)
+ {
+ LOGGER.info("GenericTreeNode was sucessfull");
+ }
+ else
+ LOGGER.info("QueryError");
+ }
+ }
+ catch(Exception e)
+ {
+ e.printStackTrace();
+ returnStatus = false;
+ }
+
+
+ //Evalutation
+ try
+ {
+ int mark;
+ Process evaluatorProcess = new ProcessBuilder("/bin/bash",
"./evaluator.sh").start();
+ mark = Integer.parseInt(getEvaluatorResponse(evaluatorProcess));
+ rootMutation.setInterest_mark(mark);
+ rootMutation.setWeight(mark);
+ rootMutation.propagateWeight();
+ System.out.println("marking : "+mark);
+ System.out.println("Weight : "+rootMutation.getWeight());
+ }
+ catch(Exception e)
+ {
+ e.printStackTrace();
+ returnStatus = false;
+ }
+
+ return returnStatus;
+ }
+
public boolean fuzz (Config config)
{
boolean returnStatus = true;
- boolean resQuery = false;
+ boolean resQuery;
int mark = 0;
//adding CASCADE to all foreign key tableColumns.
settingTemporaryCascade(false); // need to drop and recreate database
LOGGER.info("Starting Database Fuzzing");
+ // Building root Mutation. Could be extended by looking for a relevant
first SingleChange as rootMutation
Row randomRow = pickRandomRow();
GenericTreeNode currentMutation = new
GenericTreeNode(randomRow,nextId());
currentMutation.setChosenChange(currentMutation.getPotential_changes().get(0));
mutationTree.setRoot(currentMutation);
+ processFirstMutation(currentMutation);
-
+ /*
+ * Main loop. Picks and inject a mutation chosen based on its weight
(currently equal to its mark)
+ * After injecting and retrieving the marking for the evaluator,
+ * undoes necessary mutations from the tree to setup for next mutation
+ */
while(mark != -1)
{
- //INJECTION
- try
- {
- if(currentMutation.getChosenChange() != null)
- {
- resQuery = currentMutation.inject(analyzer,false);
- if(resQuery)
- {
- LOGGER.info("GenericTreeNode was sucessfull");
- }
- else
- LOGGER.info("QueryError");
-
- }
-
- }
- catch(Exception e)
- {
- e.printStackTrace();
- returnStatus = false;
- }
-
-
- //EVALUATION
- try
- {
- Process evaluatorProcess = new ProcessBuilder("/bin/bash",
"./evaluator.sh").start();
- mark = Integer.parseInt(getEvaluatorResponse(evaluatorProcess));
- currentMutation.setInterest_mark(mark);
- currentMutation.setWeight(mark);
- currentMutation.propagateWeight();
- System.out.println("marking : "+mark);
- System.out.println("Weight : "+currentMutation.getWeight());
- }
- catch(Exception e)
- {
- returnStatus = false;
- e.printStackTrace();
- }
-
- // CHOOSINGNEXT GenericTreeNode AND SETTING UP FOR NEXT ITERATION\
-
+ //Choosing next mutation
currentMutation = chooseNextMutation();
- while(!this.isNewMutation(currentMutation))
+ while(!this.isNewMutation(currentMutation,mutationTree.getRoot()))
{
System.out.println("this GenericTreeNode has already been tried ");
currentMutation = chooseNextMutation();
}
- System.out.println("chosen mutation"+currentMutation);
+ System.out.println("chosen mutation "+currentMutation);
if(!currentMutation.getParent().compare(mutationTree.getLastMutation()))
{
try
{
mutationTree.getLastMutation().undoToMutation(currentMutation.getParent(),analyzer);
+
}
catch(Exception e)
{
- System.out.println("error while performing an undo update"+e);
+ e.printStackTrace();
}
}
mutationTree.addToTree(currentMutation);
+ //Injection
+ try
+ {
+ if(currentMutation.getChosenChange() != null)
+ {
+ resQuery = currentMutation.inject(analyzer,false);
+ if(resQuery)
+ {
+ LOGGER.info("GenericTreeNode was sucessfull");
+ }
+ else
+ LOGGER.info("QueryError");
+ }
+ }
+ catch(Exception e)
+ {
+ e.printStackTrace();
+ returnStatus = false;
+ }
+
+
+ //Evalutation
+ try
+ {
+ // the evaluator sets a mark for representing how interesting
the mutation was
+ Process evaluatorProcess = new ProcessBuilder("/bin/bash",
"./evaluator.sh").start();
+ mark =
Integer.parseInt(getEvaluatorResponse(evaluatorProcess));
+ currentMutation.setInterest_mark(mark);
+ currentMutation.setWeight(mark);
+ currentMutation.propagateWeight(); //update parents weight
according to this node new weight
+ System.out.println("marking : "+mark);
+ System.out.println("Weight : "+currentMutation.getWeight());
+ }
+ catch(Exception e)
+ {
+ e.printStackTrace();
+ returnStatus = false;
+ }
}
+
System.out.println("success");
printMutationTree();
removeTemporaryCascade();
@@ -126,7 +167,7 @@ public class DBFuzzer
}
- //extract Random row from the db specified in sqlService
+ //Extract Random row from the db specified in sqlService
public Row pickRandomRow()
{
Table randomTable = pickRandomTable();
@@ -141,7 +182,7 @@ public class DBFuzzer
try
{
- stmt = sqlService.prepareStatement(theQuery);
+ stmt = analyzer.getSqlService().prepareStatement(theQuery);
rs = stmt.executeQuery();
res =
qrp.parse(rs,analyzer.getDb().getTablesMap().get("test_table")).getRows().get(0);
//randomTable should be set there
}
@@ -167,6 +208,7 @@ public class DBFuzzer
throw new RuntimeException("Random table wasn't found"); // should
never be reached
}
+
public boolean settingTemporaryCascade(Boolean undo)
{
Iterator i;
@@ -250,6 +292,11 @@ public class DBFuzzer
return response;
}
+
+ /*
+ * Pick a mutation for next iteration of the main loop.
+ *
+ */
public GenericTreeNode chooseNextMutation()
{
GenericTreeNode nextMut = null;
@@ -258,14 +305,15 @@ public class DBFuzzer
Random rand = new Random();
- if(mutationTree.getNumberOfNodes() > 1)
+ if(mutationTree.getNumberOfNodes() > 1) // first mutation does;n;t have
a predecessor
{
markingDiff =
previousMutation.getInterest_mark()-mutationTree.find(mutationTree.getLastId()).getInterest_mark();
}
+
if(mutationTree.getRoot() != null)
{
- if(markingDiff > 0)
+ if(markingDiff > 0) //
{
int randNumber =
rand.nextInt(previousMutation.getPotential_changes().size());
nextMut = new
GenericTreeNode(previousMutation.getPost_change_row(),nextId(),mutationTree.getRoot(),previousMutation);
@@ -286,18 +334,33 @@ public class DBFuzzer
return nextMut;
}
- public boolean isNewMutation(GenericTreeNode newMut)
+// public boolean isNewMutation(GenericTreeNode newMut) //iterative shitty
implementation.
+// {
+//
if(newMut.getChosenChange().getNewValue().equals(newMut.getChosenChange().getOldValue()))
+// return false;
+//
+// for(int i = 1; i <= mutationTree.getNumberOfNodes(); i++)
+// {
+// if(mutationTree.find(i).compare(newMut) ||
newMut.isSingleChangeOnCurrentPath())
+// return false;
+// }
+//
+// return true;
+// }
+
+ public boolean isNewMutation(GenericTreeNode newMut,GenericTreeNode
rootMutation)
{
-
if(newMut.getChosenChange().getNewValue().equals(newMut.getChosenChange().getOldValue()))
- return false;
+ boolean res = true;
- for(int i = 1; i <= mutationTree.getNumberOfNodes(); i++)
- {
- if(mutationTree.find(i).compare(newMut) ||
newMut.isSingleChangeOnCurrentPath())
- return false;
- }
+ if(rootMutation.compare(newMut) ||
newMut.isSingleChangeOnCurrentPath())
+ return false;
- return true;
+ for(GenericTreeNode child : rootMutation.getChildren())
+ {
+ res = isNewMutation(newMut,child);
+ }
+
+ return res;
}
public void printMutationTree()
diff --git a/src/main/java/org/schemaspy/Main.java
b/src/main/java/org/schemaspy/Main.java
index d981cd1..61c6030 100644
--- a/src/main/java/org/schemaspy/Main.java
+++ b/src/main/java/org/schemaspy/Main.java
@@ -121,8 +121,6 @@ public class Main implements CommandLineRunner {
}
catch(Exception e)
{
- System.out.println("erreur");
- //LOGGER.error(e.getMessage(),e);
e.printStackTrace();
}
}
diff --git a/src/main/java/org/schemaspy/model/GenericTree.java
b/src/main/java/org/schemaspy/model/GenericTree.java
index 8197726..3946277 100644
--- a/src/main/java/org/schemaspy/model/GenericTree.java
+++ b/src/main/java/org/schemaspy/model/GenericTree.java
@@ -3,6 +3,7 @@ package org.schemaspy.model;
import org.schemaspy.*;
import org.schemaspy.model.SingleChange;
+
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
@@ -27,7 +28,7 @@ public class GenericTree {
public int getNumberOfNodes() {
int numberOfNodes = 0;
- if(root != null) {
+ if (root != null) {
numberOfNodes = auxiliaryGetNumberOfNodes(root) + 1; //1 for the
root!
}
@@ -38,17 +39,17 @@ public class GenericTree {
private int auxiliaryGetNumberOfNodes(GenericTreeNode node) {
int numberOfNodes = node.getNumberOfChildren();
- for(GenericTreeNode child : node.getChildren()) {
+ for (GenericTreeNode child : node.getChildren()) {
numberOfNodes += auxiliaryGetNumberOfNodes(child);
}
return numberOfNodes;
}
+ //finds a node in the tree recursivly. used as testing and code ease
purposes. should not be sued in loop to much.
public GenericTreeNode find(Integer id) {
- if(root == null)
- {
- return null;
+ if (root == null) {
+ return null;
}
return auxiliaryFind(root, id);
}
@@ -56,13 +57,12 @@ public class GenericTree {
private GenericTreeNode auxiliaryFind(GenericTreeNode currentNode, Integer
id) {
if (currentNode.getId().equals(id))
return currentNode;
- if (! currentNode.hasChildren())
+ if (!currentNode.hasChildren())
return null;
- for (GenericTreeNode child : currentNode.getChildren())
- {
- GenericTreeNode returnNode = auxiliaryFind(child, id);
- if (null != returnNode)
- return returnNode;
+ for (GenericTreeNode child : currentNode.getChildren()) {
+ GenericTreeNode returnNode = auxiliaryFind(child, id);
+ if (null != returnNode)
+ return returnNode;
}
return null;
}
@@ -71,169 +71,39 @@ public class GenericTree {
return (root == null);
}
- public List<GenericTreeNode> build(GenericTreeTraversalOrderEnum
traversalOrder) {
- List<GenericTreeNode> returnList = null;
-
- if(root != null) {
- returnList = build(root, traversalOrder);
- }
-
- return returnList;
- }
-
- public List<GenericTreeNode> build(GenericTreeNode node,
GenericTreeTraversalOrderEnum traversalOrder) {
- List<GenericTreeNode> traversalResult = new
ArrayList<GenericTreeNode>();
-
- if(traversalOrder == GenericTreeTraversalOrderEnum.PRE_ORDER) {
- buildPreOrder(node, traversalResult);
- }
-
- else if(traversalOrder == GenericTreeTraversalOrderEnum.POST_ORDER) {
- buildPostOrder(node, traversalResult);
- }
-
- return traversalResult;
- }
-
- private void buildPreOrder(GenericTreeNode node, List<GenericTreeNode>
traversalResult) {
- traversalResult.add(node);
-
- for(GenericTreeNode child : node.getChildren()) {
- buildPreOrder(child, traversalResult);
- }
- }
-
- private void buildPostOrder(GenericTreeNode node, List<GenericTreeNode>
traversalResult) {
- for(GenericTreeNode child : node.getChildren()) {
- buildPostOrder(child, traversalResult);
- }
-
- traversalResult.add(node);
+ public Integer getLastId() {
+ return this.getNumberOfNodes();
}
- public Map<GenericTreeNode, Integer>
buildWithDepth(GenericTreeTraversalOrderEnum traversalOrder) {
- Map<GenericTreeNode, Integer> returnMap = null;
-
- if(root != null) {
- returnMap = buildWithDepth(root, traversalOrder);
- }
-
- return returnMap;
+ public GenericTreeNode getLastMutation() {
+ return find(getLastId());
}
- public Map<GenericTreeNode, Integer> buildWithDepth(GenericTreeNode node,
GenericTreeTraversalOrderEnum traversalOrder) {
- Map<GenericTreeNode, Integer> traversalResult = new
LinkedHashMap<GenericTreeNode, Integer>();
-
- if(traversalOrder == GenericTreeTraversalOrderEnum.PRE_ORDER) {
- buildPreOrderWithDepth(node, traversalResult, 0);
- }
-
- else if(traversalOrder == GenericTreeTraversalOrderEnum.POST_ORDER) {
- buildPostOrderWithDepth(node, traversalResult, 0);
- }
-
- return traversalResult;
+ public void addToTree(GenericTreeNode currentMutation) {
+ currentMutation.getParent().addChild(currentMutation);
}
- private void buildPreOrderWithDepth(GenericTreeNode node,
Map<GenericTreeNode, Integer> traversalResult, int depth) {
- traversalResult.put(node, depth);
-
- for(GenericTreeNode child : node.getChildren()) {
- buildPreOrderWithDepth(child, traversalResult, depth + 1);
- }
- }
-
- private void buildPostOrderWithDepth(GenericTreeNode node,
Map<GenericTreeNode, Integer> traversalResult, int depth) {
- for(GenericTreeNode child : node.getChildren()) {
- buildPostOrderWithDepth(child, traversalResult, depth + 1);
- }
-
- traversalResult.put(node, depth);
- }
-
- public String toString() {
- /*
- We're going to assume a pre-order traversal by default
- */
-
- String stringRepresentation = "";
-
- if(root != null) {
- stringRepresentation =
build(GenericTreeTraversalOrderEnum.PRE_ORDER).toString();
-
- }
-
- return stringRepresentation;
- }
-
- public String toStringWithDepth() {
- /*
- We're going to assume a pre-order traversal by default
- */
-
- String stringRepresentation = "";
-
- if(root != null) {
- stringRepresentation =
buildWithDepth(GenericTreeTraversalOrderEnum.PRE_ORDER).toString();
- }
-
- return stringRepresentation;
- }
-
- public Integer getLastId()
- {
- return this.getNumberOfNodes();
- }
-
- public GenericTreeNode getLastMutation()
- {
- return find(getLastId());
- }
-
- public void addToTree(GenericTreeNode currentMutation)
- {
- currentMutation.getParent().addChild(currentMutation);
- }
-
- public GenericTreeNode findFirstMutationWithout(GenericTreeNode mutation,
SingleChange chosenChange)
- {
- int i,j;
+ //finds first mutation that hasnt explored the singleChange. not to be
used any more as the picking patern.
+ public GenericTreeNode findFirstMutationWithout(GenericTreeNode mutation,
SingleChange chosenChange) {
+ int i, j;
boolean noSonHasChosenChange = true;
GenericTreeNode res = null;
- if(mutation.getChildren().isEmpty())
- {
- return mutation;
+ if (mutation.getChildren().isEmpty()) {
+ return mutation;
}
- for(i = 0; i < mutation.getChildren().size(); i++)
- {
-
if(mutation.getChildren().get(i).getChosenChange().compare(chosenChange))
- noSonHasChosenChange = false;
+ for (i = 0; i < mutation.getChildren().size(); i++) {
+ if
(mutation.getChildren().get(i).getChosenChange().compare(chosenChange))
+ noSonHasChosenChange = false;
}
- if(noSonHasChosenChange)
- return mutation;
+ if (noSonHasChosenChange)
+ return mutation;
- for(j = 0; j < mutation.getChildren().size(); j++)
- {
- res =
findFirstMutationWithout(mutation.getChildren().get(j),chosenChange);
+ for (j = 0; j < mutation.getChildren().size(); j++) {
+ res = findFirstMutationWithout(mutation.getChildren().get(j),
chosenChange);
}
return res; // should never be null unless the algorithm is not
looking for something precise
}
-
- public void printTree(int tabs)
- {
- for(int i = 1; i <= getNumberOfNodes(); i++)
- {
- for(int j = 0; j < tabs ; j++)
- {
- System.out.println(" ");
- }
- System.out.println(find(i));
- if(find(i).getChildren().size() != 0)
- printTree(find(i).getDepth());
- }
- }
-
}
diff --git a/src/main/java/org/schemaspy/model/GenericTreeNode.java
b/src/main/java/org/schemaspy/model/GenericTreeNode.java
index 6904d8a..70cfcab 100644
--- a/src/main/java/org/schemaspy/model/GenericTreeNode.java
+++ b/src/main/java/org/schemaspy/model/GenericTreeNode.java
@@ -8,7 +8,9 @@ import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+
import org.schemaspy.*;
+
import java.util.*;
import java.util.ArrayList;
import java.util.regex.Matcher;
@@ -31,269 +33,221 @@ public class GenericTreeNode {
private GenericTreeNode parent;
private boolean cascadingFK;
private int depth;
+
/**
- * Default GenericTreeNode constructor
- */
- public GenericTreeNode(Row initial_state_row,int id) { // used only for
rootMutation
- this.id = id;
- this.initial_state_row = initial_state_row;
- this.cascadingFK = false;
- this.potential_changes = discoverMutationPossibilities();
- this.weight = 1;
- this.subTreeWeight = 0;
- this.depth = 0;
- this.parent = null;
- }
-
- public GenericTreeNode(Row initial_state_row,int id, GenericTreeNode
rootMutation, GenericTreeNode parentMutation) {
- this.id = id;
- this.initial_state_row = initial_state_row;
- this.cascadingFK = false;
- this.rootMutation = rootMutation;
- this.parent = parentMutation;
- initDepth();
- this.potential_changes = discoverMutationPossibilities();
- this.weight = 1;
- this.subTreeWeight = 0;
+ * Default GenericTreeNode constructor
+ */
+ public GenericTreeNode(Row initial_state_row, int id) { // used only for
rootMutation
+ this.id = id;
+ this.initial_state_row = initial_state_row;
+ this.cascadingFK = false;
+ this.potential_changes = discoverMutationPossibilities();
+ this.weight = 1;
+ this.subTreeWeight = 0;
+ this.depth = 0;
+ this.parent = null;
+ }
+
+ public GenericTreeNode(Row initial_state_row, int id, GenericTreeNode
rootMutation, GenericTreeNode parentMutation) {
+ this.id = id;
+ this.initial_state_row = initial_state_row;
+ this.cascadingFK = false;
+ this.rootMutation = rootMutation;
+ this.parent = parentMutation;
+ initDepth();
+ this.potential_changes = discoverMutationPossibilities();
+ this.weight = 1;
+ this.subTreeWeight = 0;
}
public Integer getId() {
- return id;
+ return id;
}
- public Integer getWeight()
- {
- return this.weight;
+ public Integer getWeight() {
+ return this.weight;
}
- public void initDepth()
- {
- GenericTreeNode tmp = this;
- int cpt = 0;
- while( tmp.getParent() != null)
- {
- tmp = tmp.getParent();
- cpt++;
- }
+ public void initDepth() {
+ GenericTreeNode tmp = this;
+ int cpt = 0;
+ while (tmp.getParent() != null) {
+ tmp = tmp.getParent();
+ cpt++;
+ }
- this.depth = cpt;
+ this.depth = cpt;
}
- public boolean checkWeightConsistency()
- {
- int tmp = 0;
- for(GenericTreeNode child : this.getChildren())
- {
- tmp += child.getWeight();
- }
+ public boolean checkWeightConsistency() {
+ int tmp = 0;
+ for (GenericTreeNode child : this.getChildren()) {
+ tmp += child.getWeight();
+ }
- if(tmp != this.getSubTreeWeight() && !this.getChildren().isEmpty())
- {
- System.out.println("Weight inconstistent "+this.getWeight()+"
"+this.getSubTreeWeight());
- System.out.println("Mutation concernee = "+this);
- return false;
- }
+ if (tmp != this.getSubTreeWeight() && !this.getChildren().isEmpty()) {
+ System.out.println("Weight inconstistent " + this.getWeight() + "
" + this.getSubTreeWeight());
+ System.out.println("Mutation concernee = " + this);
+ return false;
+ }
- return true ;
+ return true;
}
- public void updateSubTreeWeight()
- {
- int tmp = 0;
- for(GenericTreeNode child : this.getChildren())
- {
- tmp += child.getWeight();
- }
- this.subTreeWeight = tmp;
+ public void updateSubTreeWeight() {
+ int tmp = 0;
+ for (GenericTreeNode child : this.getChildren()) {
+ tmp += child.getWeight();
+ }
+ this.subTreeWeight = tmp;
}
- public void setWeight(int weight)
- {
- this.weight = weight;
+ public void setWeight(int weight) {
+ this.weight = weight;
}
- private static final Random r = new Random();
/**
- *
- */
- public SingleChange singleChangeBasedOnWeight ()
- {
- checkWeightConsistency();
- if (this.potential_changes.isEmpty() && (0 == subTreeWeight))
- System.out.println("ERROR PICKING : no potential_changes AND
subtreeweight = 0");
-
- int rnd = r.nextInt(subTreeWeight + potential_changes.size());
- assert (rnd >= 0);
- if (rnd < potential_changes.size())
- return potential_changes.remove (rnd);
- rnd -= potential_changes.size();
- for (GenericTreeNode n : children)
+ *
+ */
+ public SingleChange singleChangeBasedOnWeight() {
+ final Random r = new Random();
+ checkWeightConsistency();
+ if (this.potential_changes.isEmpty() && (0 == subTreeWeight))
+ System.out.println("ERROR PICKING : no potential_changes AND
subtreeweight = 0");
+
+ int rnd = r.nextInt(subTreeWeight + potential_changes.size());
+ assert (rnd >= 0);
+ if (rnd < potential_changes.size()) // checking if currentNode is the
pick
+ return potential_changes.remove(rnd);
+ rnd -= potential_changes.size(); // removing the potential changes
"weight" of the current node to match subtree Weight
+ for (GenericTreeNode n : children) // launching on every child if
current node wasnt picked.
{
- int w = n.getWeight();
- if (rnd < w)
- {
- return n.singleChangeBasedOnWeight();
- }
- rnd -= w;
+ int w = n.getWeight();
+ if (rnd < w) {
+ return n.singleChangeBasedOnWeight();
+ }
+ rnd -= w;
}
- System.out.println("ici2");
- throw new Error("This should be impossible to reach");
- }
-
- public Row getPost_change_row()
- {
- return this.post_change_row;
+ System.out.println("ici2");
+ throw new Error("This should be impossible to reach");
}
- public void setPost_change_row(Row postChangeRow)
- {
- this.post_change_row = postChangeRow;
+ public Row getPost_change_row() {
+ return this.post_change_row;
}
- public int getDepth()
- {
- return this.depth;
+ public int getDepth() {
+ return this.depth;
}
public SingleChange getChosenChange() {
- return chosenChange;
+ return chosenChange;
}
- public int getSubTreeWeight()
- {
- return this.subTreeWeight;
+ public int getSubTreeWeight() {
+ return this.subTreeWeight;
}
public Row getInitial_state_row() {
- return initial_state_row;
+ return initial_state_row;
}
- public int getInterest_mark()
- {
+ public int getInterest_mark() {
return this.interest_mark;
}
- public void setInterest_mark(int mark)
- {
- this.interest_mark = mark;
+ public void setInterest_mark(int mark) {
+ this.interest_mark = mark;
}
/**
- * Returns value of potential_changes
- * @return
- */
+ * Returns value of potential_changes
+ *
+ * @return
+ */
public ArrayList<SingleChange> getPotential_changes() {
- return potential_changes;
+ return potential_changes;
}
/**
* @return the rootMutation
*/
public GenericTreeNode getRootMutation() {
- return rootMutation;
+ return rootMutation;
}
- public void setRootMutation(GenericTreeNode rootMutation)
- {
- this.rootMutation = rootMutation;
- }
- /**
- * Sets new value of potential_changes
- * @param
- */
- public void initPotential_changes(ArrayList<SingleChange>
potential_changes) {
- this.potential_changes = potential_changes;
+ public void setChosenChange(SingleChange sc) {
+ this.chosenChange = sc;
+ this.chosenChange.setAttachedToMutation(this);
}
- public void setChosenChange(SingleChange sc)
- {
- this.chosenChange = sc;
- this.chosenChange.setAttachedToMutation(this);
- }
/**
- * Sets new value of children
- * @param
- */
- public void setchildren(ArrayList<GenericTreeNode> children) {
- this.children = children;
- }
+ * Sets new value of children
+ *
+ * @param
+ */
public void setParent(GenericTreeNode parent) {
- this.parent = parent;
+ this.parent = parent;
}
+ public ArrayList<SingleChange> discoverMutationPossibilities() {
- public GenericTreeNode getChildAt(int index) throws
IndexOutOfBoundsException
- {
- return children.get(index);
- }
+ int i;
+ ArrayList<SingleChange> possibilities = new ArrayList<SingleChange>();
- public ArrayList<SingleChange> discoverMutationPossibilities()
- {
+ //TRYING TO DISCOVER RAW POSSIBILITIES
+ for (Map.Entry<String, String> content :
initial_state_row.getContent().entrySet()) {
+ try {
+ TableColumn parentColumn =
initial_state_row.getParentTable().findTableColumn(content.getKey());
+ possibilities.addAll(discoverFieldPossibilities(parentColumn,
content.getValue()));
+ } catch (Exception e) {
+ }
+ }
- int i;
- ArrayList<SingleChange> possibilities = new ArrayList<SingleChange>();
+ //REMOVING POSSIBILITIES THAT DONT MATCH CONSTRAINTS
+ for (i = 0; i < possibilities.size(); i++) {
+ if (!possibilities.get(i).respectsConstraints())
+ possibilities.remove(possibilities.get(i));
+ }
+ return possibilities;
+ }
- //TRYING TO DISCOVER RAW POSSIBILITIES
- for(Map.Entry<String,String> content :
initial_state_row.getContent().entrySet())
- {
- try
- {
- TableColumn parentColumn =
initial_state_row.getParentTable().findTableColumn(content.getKey());
-
possibilities.addAll(discoverFieldPossibilities(parentColumn,content.getValue()));
- }
- catch(Exception e)
- {
- }
- }
-
- //REMOVING POSSIBILITIES THAT DONT MATCH CONSTRAINTS
- for(i = 0; i < possibilities.size(); i++)
- {
- if(!possibilities.get(i).respectsConstraints())
- possibilities.remove(possibilities.get(i));
- }
- return possibilities;
- }
-
- public ArrayList<SingleChange> discoverFieldPossibilities (TableColumn
tableColumn, String column_value) throws Exception
+ public ArrayList<SingleChange> discoverFieldPossibilities(TableColumn
tableColumn, String column_value) throws Exception //listing of the mutation
possibilities on the specified row
{
ArrayList<SingleChange> oneChange = new ArrayList<SingleChange>();
String typeName = tableColumn.getTypeName();
switch (typeName) {
- case "int2":
- int tmp =
Integer.parseInt(rootMutation.getInitial_state_row().getContent().get(tableColumn.getName()));
- oneChange.add(new
SingleChange(tableColumn,this,column_value,Integer.toString(tmp++)));
- oneChange.add(new
SingleChange(tableColumn,this,column_value,Integer.toString(32767)));
- oneChange.add(new
SingleChange(tableColumn,this,column_value,Integer.toString(1)));
- break;
- case "varchar":
- if(this.getRootMutation() == null)
- {
- char tmp2 = column_value.charAt(0);
- oneChange.add(new
SingleChange(tableColumn,this,column_value,(Character.toString(tmp2++)+column_value.substring(1))));
- oneChange.add(new
SingleChange(tableColumn,this,column_value,(Character.toString(tmp2--)+column_value.substring(1))));
- }
- else
- {
- char tmp2 = (char)
this.getRootMutation().getInitial_state_row().getContent().get(tableColumn.getName()).charAt(0);
- char nextChar = (char) (tmp2+1);
- char prevChar = (char) (tmp2-1);
- oneChange.add(new
SingleChange(tableColumn,this,column_value,(Character.toString(nextChar)+column_value.substring(1))));
- oneChange.add(new
SingleChange(tableColumn,this,column_value,(Character.toString(prevChar)+column_value.substring(1))));
- }
-
- break;
- case "bool":
- if(column_value.equals("f"))
- oneChange.add(new
SingleChange(tableColumn,this,column_value,"t"));
- if(column_value.equals("t"))
- oneChange.add(new
SingleChange(tableColumn,this,column_value,"f"));
- break;
+ case "int2":
+ int tmp =
Integer.parseInt(rootMutation.getInitial_state_row().getContent().get(tableColumn.getName()));
+ oneChange.add(new SingleChange(tableColumn, this,
column_value, Integer.toString(tmp++)));
+ oneChange.add(new SingleChange(tableColumn, this,
column_value, Integer.toString(32767)));
+ oneChange.add(new SingleChange(tableColumn, this,
column_value, Integer.toString(1)));
+ break;
+ case "varchar":
+ if (this.getRootMutation() == null) {
+ char tmp2 = column_value.charAt(0);
+ oneChange.add(new SingleChange(tableColumn, this,
column_value, (Character.toString(tmp2++) + column_value.substring(1))));
+ oneChange.add(new SingleChange(tableColumn, this,
column_value, (Character.toString(tmp2--) + column_value.substring(1))));
+ } else {
+ char tmp2 = (char)
this.getRootMutation().getInitial_state_row().getContent().get(tableColumn.getName()).charAt(0);
+ char nextChar = (char) (tmp2 + 1);
+ char prevChar = (char) (tmp2 - 1);
+ oneChange.add(new SingleChange(tableColumn, this,
column_value, (Character.toString(nextChar) + column_value.substring(1))));
+ oneChange.add(new SingleChange(tableColumn, this,
column_value, (Character.toString(prevChar) + column_value.substring(1))));
+ }
+
+ break;
+ case "bool":
+ if (column_value.equals("f"))
+ oneChange.add(new SingleChange(tableColumn, this,
column_value, "t"));
+ if (column_value.equals("t"))
+ oneChange.add(new SingleChange(tableColumn, this,
column_value, "f"));
+ break;
/* case 5: typeName = "May";
break;
case 6: typeName = "June";
@@ -310,189 +264,159 @@ public class GenericTreeNode {
break;
case 12: typeName = "December";
break;*/
- default: throw new Exception("No raw GenericTreeNode
possibilities could be found");
- }
+ default:
+ throw new Exception("No raw GenericTreeNode possibilities
could be found");
+ }
return oneChange;
}
- public boolean inject(SchemaAnalyzer analyzer, boolean undo) throws
Exception
- {
+ public boolean inject(SchemaAnalyzer analyzer, boolean undo) {
- if(undo)
- System.out.println("UNDOING");
- else
- System.out.println("INJECT");
- String theQuery = updateQueryBuilder(undo);
- try
- {
- PreparedStatement stmt =
analyzer.getSqlService().prepareStatement(theQuery, analyzer.getDb(),null);
- stmt.execute();
- this.post_change_row = this.initial_state_row.clone();
-
this.post_change_row.setValueOfColumn(chosenChange.getParentTableColumn().getName(),
chosenChange.getNewValue());
- return true;
- }
- catch(Exception e)
- {
- throw new Exception(e);
- }
- }
-
- public boolean undo(SchemaAnalyzer analyzer)
- {
- try
- {
- return this.inject(analyzer, true);
- }
- catch(Exception e)
- {
- System.out.println("Undo failed with error :"+e);
- return false;
- }
- }
-
- public String updateQueryBuilder(boolean undo)
- {
- String theQuery ;
-
- if(undo)
- {
- if(chosenChange.getParentTableColumn().getTypeName().equals("varchar")
|| chosenChange.getParentTableColumn().getTypeName().equals("bool"))
- theQuery = "UPDATE "+initial_state_row.getParentTable().getName()+"
SET
"+chosenChange.getParentTableColumn().getName()+"='"+chosenChange.getOldValue()+"',
";
- else
- theQuery = "UPDATE "+initial_state_row.getParentTable().getName()+"
SET "+chosenChange.getParentTableColumn().getName()+" =
"+chosenChange.getOldValue()+", ";
- }
- else
- {
- if(chosenChange.getParentTableColumn().getTypeName().equals("varchar")
|| chosenChange.getParentTableColumn().getTypeName().equals("bool"))
- theQuery = "UPDATE "+initial_state_row.getParentTable().getName()+"
SET
"+chosenChange.getParentTableColumn().getName()+"='"+chosenChange.getNewValue()+"',
";
+ if (undo)
+ System.out.println("UNDOING");
else
- theQuery = "UPDATE "+initial_state_row.getParentTable().getName()+"
SET
"+chosenChange.getParentTableColumn().getName()+"="+chosenChange.getNewValue()+",
";
- }
- for(Map.Entry<String,String> entry :
initial_state_row.getContent().entrySet())
- {
-
if(!entry.getKey().equals(chosenChange.getParentTableColumn().getName()))
- {
-
if(chosenChange.getParentTableColumn().getTable().getColumn(entry.getKey()).getTypeName().equals("varchar")
||
chosenChange.getParentTableColumn().getTable().getColumn(entry.getKey()).getTypeName().equals("bool"))
- theQuery = theQuery+(entry.getKey()+"='"+entry.getValue()+"', ");
- else
- theQuery = theQuery+(entry.getKey()+"="+entry.getValue()+", ");
+ System.out.println("INJECT");
+ String theQuery = updateQueryBuilder(undo);
+ try {
+ PreparedStatement stmt =
analyzer.getSqlService().prepareStatement(theQuery, analyzer.getDb(), null);
+ stmt.execute();
+ initPostChangeRow();
+ return true;
+ } catch (Exception e) {
+ e.printStackTrace();
+ return false;
}
+ }
- }
-
- theQuery = theQuery.substring(0,theQuery.lastIndexOf(","));
- theQuery = theQuery+" WHERE ";
+ private void initPostChangeRow() {
+ this.post_change_row = this.initial_state_row.clone();
+
this.post_change_row.setValueOfColumn(chosenChange.getParentTableColumn().getName(),
chosenChange.getNewValue());
+ }
- // USING ALL VALUES TO TRIANGULATE THE ROW TO UPDATE (no primary key)
- if(initial_state_row.getParentTable().getPrimaryColumns().isEmpty())
- {
- for(Map.Entry<String,String> entry :
initial_state_row.getContent().entrySet())
- {
-
if(!entry.getKey().equals(chosenChange.getParentTableColumn().getName()))
- {
-
if(chosenChange.getParentTableColumn().getTable().getColumn(entry.getKey()).getTypeName().equals("varchar")
||
chosenChange.getParentTableColumn().getTable().getColumn(entry.getKey()).getTypeName().equals("bool"))
- theQuery = theQuery+(entry.getKey()+"='"+entry.getValue()+"' AND
");
- else
- theQuery = theQuery+(entry.getKey()+"="+entry.getValue()+" AND
");
- }
- else
- {
- if(undo)
- theQuery =
theQuery+(entry.getKey()+"='"+chosenChange.getNewValue()+"' AND ");
- else
- theQuery =
theQuery+(entry.getKey()+"='"+chosenChange.getOldValue()+"' AND ");
- }
+ public boolean undo(SchemaAnalyzer analyzer) {
+ try {
+ return this.inject(analyzer, true);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return false;
}
- theQuery = theQuery.substring(0,theQuery.lastIndexOf(" AND "));
- }
- else
- theQuery = theQuery+("
"+initial_state_row.getParentTable().getPrimaryColumns().get(0).getName()+"="+initial_state_row.getValueOfColumn(initial_state_row.getParentTable().getPrimaryColumns().get(0).getName()));
-
-
- //System.out.println("build query ! "+theQuery); uncomment to see built
request;
- return theQuery;
}
-
- //NOT FUNCTIONNAL
- public ArrayList<SingleChange> checkCascadeFK(SingleChange chosenChange,
SchemaAnalyzer analyzer)
+ public String updateQueryBuilder(boolean undo) //undo variable tells if
the function should build Inject string or Undo string
{
- ArrayList<SingleChange> res = new ArrayList<SingleChange>();
- int i,j;
-
- for(Map.Entry<String,Collection<ForeignKeyConstraint>> entry :
analyzer.getDb().getLesForeignKeys().entrySet())
- {
- Iterator<ForeignKeyConstraint> iter = entry.getValue().iterator();
- while (iter.hasNext()) {
- ForeignKeyConstraint elem = iter.next();
- for(i = 0; i < elem.getParentColumns().size();i++)
- {
-
if(elem.getParentColumns().get(i).getName().equals(chosenChange.getParentTableColumn().getName()))
- res.add(new
SingleChange(elem.getParentColumns().get(i),this,chosenChange.getOldValue(),chosenChange.getNewValue()));
-
if(elem.getChildColumns().get(i).getName().equals(chosenChange.getParentTableColumn().getName()))
- res.add(new
SingleChange(elem.getChildColumns().get(i),this,chosenChange.getOldValue(),chosenChange.getNewValue()));
- }
- }
- }
+ String theQuery;
- for( i = 0; i < res.size();i++)
- {
- for( j = 0; j < res.size();j++)
- {
- if(res.get(i).equals(res.get(j)))
- res.remove(res.get(j));
+ if (undo) {
+ if
(chosenChange.getParentTableColumn().getTypeName().equals("varchar") ||
chosenChange.getParentTableColumn().getTypeName().equals("bool"))
+ theQuery = "UPDATE " +
initial_state_row.getParentTable().getName() + " SET " +
chosenChange.getParentTableColumn().getName() + "='" +
chosenChange.getOldValue() + "', ";
+ else
+ theQuery = "UPDATE " +
initial_state_row.getParentTable().getName() + " SET " +
chosenChange.getParentTableColumn().getName() + " = " +
chosenChange.getOldValue() + ", ";
+ } else {
+ if
(chosenChange.getParentTableColumn().getTypeName().equals("varchar") ||
chosenChange.getParentTableColumn().getTypeName().equals("bool"))
+ theQuery = "UPDATE " +
initial_state_row.getParentTable().getName() + " SET " +
chosenChange.getParentTableColumn().getName() + "='" +
chosenChange.getNewValue() + "', ";
+ else
+ theQuery = "UPDATE " +
initial_state_row.getParentTable().getName() + " SET " +
chosenChange.getParentTableColumn().getName() + "=" +
chosenChange.getNewValue() + ", ";
}
- }
-
- System.out.println("LA PRESENCE DE FOREIGN KEY EST"+ res);
- return res;
- }
-
+ for (Map.Entry<String, String> entry :
initial_state_row.getContent().entrySet()) {
+ if
(!entry.getKey().equals(chosenChange.getParentTableColumn().getName())) {
+ if
(chosenChange.getParentTableColumn().getTable().getColumn(entry.getKey()).getTypeName().equals("varchar")
||
chosenChange.getParentTableColumn().getTable().getColumn(entry.getKey()).getTypeName().equals("bool"))
+ theQuery = theQuery + (entry.getKey() + "='" +
entry.getValue() + "', ");
+ else
+ theQuery = theQuery + (entry.getKey() + "=" +
entry.getValue() + ", ");
+ }
- public boolean compare(GenericTreeNode genericTreeNode)
- {
- boolean res = false;
- if(this.getId() == genericTreeNode.getId())
- res=true;
+ }
-
if(this.initial_state_row.compare(genericTreeNode.getInitial_state_row()) &&
this.chosenChange.compare(genericTreeNode.getChosenChange()))
- res = true;
+ theQuery = theQuery.substring(0, theQuery.lastIndexOf(","));
+ theQuery = theQuery + " WHERE ";
- return res;
- }
+ // USING ALL VALUES TO TRIANGULATE THE ROW TO UPDATE (no primary key)
+ if (initial_state_row.getParentTable().getPrimaryColumns().isEmpty()) {
+ for (Map.Entry<String, String> entry :
initial_state_row.getContent().entrySet()) {
+ if
(!entry.getKey().equals(chosenChange.getParentTableColumn().getName())) {
+ if
(chosenChange.getParentTableColumn().getTable().getColumn(entry.getKey()).getTypeName().equals("varchar")
||
chosenChange.getParentTableColumn().getTable().getColumn(entry.getKey()).getTypeName().equals("bool"))
+ theQuery = theQuery + (entry.getKey() + "='" +
entry.getValue() + "' AND ");
+ else
+ theQuery = theQuery + (entry.getKey() + "=" +
entry.getValue() + " AND ");
+ } else {
+ if (undo)
+ theQuery = theQuery + (entry.getKey() + "='" +
chosenChange.getNewValue() + "' AND ");
+ else
+ theQuery = theQuery + (entry.getKey() + "='" +
chosenChange.getOldValue() + "' AND ");
+ }
+ }
+ theQuery = theQuery.substring(0, theQuery.lastIndexOf(" AND "));
+ } else
+ theQuery = theQuery + (" " +
initial_state_row.getParentTable().getPrimaryColumns().get(0).getName() + "=" +
initial_state_row.getValueOfColumn(initial_state_row.getParentTable().getPrimaryColumns().get(0).getName()));
- public boolean undoToMutation(GenericTreeNode target, SchemaAnalyzer
analyzer) throws Exception
- {
- ArrayList<GenericTreeNode> goingUp = findPathToMutation(target).get(0);
- ArrayList<GenericTreeNode> goingDown =
findPathToMutation(target).get(1);;
- for(int i = 0; i < goingUp.size();i++)
- {
- goingUp.get(i).undo(analyzer);
- }
- for(int i = 0; i < goingDown.size();i++)
- {
- goingDown.get(i).inject(analyzer,false);
- }
- return true;
+ //System.out.println("build query ! "+theQuery); uncomment to see
built request;
+ return theQuery;
}
- public GenericTreeNode getMutation(GenericTreeNode GenericTreeNode ,int id)
- {
-
- for(int i = 0; i < GenericTreeNode.getChildren().size();i++)
- {
- if(getMutation(GenericTreeNode.getChildren().get(i),
GenericTreeNode.getChildren().get(i).getId()).getId() == id)
- return GenericTreeNode.getChildren().get(i);
- }
-
- return null;
+ //NOT FUNCTIONNAL
+// public ArrayList<SingleChange> checkCascadeFK(SingleChange chosenChange,
SchemaAnalyzer analyzer)
+// {
+// ArrayList<SingleChange> res = new ArrayList<SingleChange>();
+// int i,j;
+//
+// for(Map.Entry<String,Collection<ForeignKeyConstraint>> entry :
analyzer.getDb().getLesForeignKeys().entrySet())
+// {
+// Iterator<ForeignKeyConstraint> iter = entry.getValue().iterator();
+// while (iter.hasNext()) {
+// ForeignKeyConstraint elem = iter.next();
+// for(i = 0; i < elem.getParentColumns().size();i++)
+// {
+//
if(elem.getParentColumns().get(i).getName().equals(chosenChange.getParentTableColumn().getName()))
+// res.add(new
SingleChange(elem.getParentColumns().get(i),this,chosenChange.getOldValue(),chosenChange.getNewValue()));
+//
if(elem.getChildColumns().get(i).getName().equals(chosenChange.getParentTableColumn().getName()))
+// res.add(new
SingleChange(elem.getChildColumns().get(i),this,chosenChange.getOldValue(),chosenChange.getNewValue()));
+// }
+// }
+// }
+//
+// for( i = 0; i < res.size();i++)
+// {
+// for( j = 0; j < res.size();j++)
+// {
+// if(res.get(i).equals(res.get(j)))
+// res.remove(res.get(j));
+// }
+// }
+//
+// System.out.println("LA PRESENCE DE FOREIGN KEY EST"+ res);
+// return res;
+// }
+
+
+ public boolean compare(GenericTreeNode genericTreeNode) {
+ boolean res = false;
+ if (this.getId() == genericTreeNode.getId())
+ res = true;
+
+ if
(this.initial_state_row.compare(genericTreeNode.getInitial_state_row()) &&
this.chosenChange.compare(genericTreeNode.getChosenChange()))
+ res = true;
+
+ return res;
+ }
+
+ public boolean undoToMutation(GenericTreeNode target, SchemaAnalyzer
analyzer) throws Exception {
+ ArrayList<GenericTreeNode> goingUp = findPathToMutation(target).get(0);
+ ArrayList<GenericTreeNode> goingDown =
findPathToMutation(target).get(1);
+ ;
+
+ for (int i = 0; i < goingUp.size(); i++) {
+ goingUp.get(i).undo(analyzer);
+ }
+ for (int i = 0; i < goingDown.size(); i++) {
+ goingDown.get(i).inject(analyzer, false);
+ }
+ return true;
}
-
public GenericTreeNode getParent() {
return this.parent;
}
@@ -510,8 +434,8 @@ public class GenericTreeNode {
}
public void setChildren(ArrayList<GenericTreeNode> children) {
- for(GenericTreeNode child : children) {
- child.parent = this;
+ for (GenericTreeNode child : children) {
+ child.parent = this;
}
this.children = children;
@@ -522,90 +446,70 @@ public class GenericTreeNode {
children.add(child);
}
- public void removeChildren() {
- this.children = new ArrayList<GenericTreeNode>();
- }
-
- public void removeChildAt(int index) throws IndexOutOfBoundsException {
- children.remove(index);
- }
-
-
public String toString() {
- return "[ MUT ID "+this.getId()+" Depth = "+this.getDepth()+" SG
"+this.chosenChange+"]";
+ return "[ MUT ID " + this.getId() + " Depth = " + this.getDepth() + "
SG " + this.chosenChange + "]";
}
- public ArrayList<ArrayList<GenericTreeNode>>
findPathToMutation(GenericTreeNode target)
- {
- ArrayList<ArrayList<GenericTreeNode>> finalPath = new
ArrayList<ArrayList<GenericTreeNode>>();
- ArrayList<GenericTreeNode> thisPath = new ArrayList<GenericTreeNode>();
- ArrayList<GenericTreeNode> targetPath = new ArrayList<GenericTreeNode>();
+ public ArrayList<ArrayList<GenericTreeNode>>
findPathToMutation(GenericTreeNode target) {
+ ArrayList<ArrayList<GenericTreeNode>> finalPath = new
ArrayList<ArrayList<GenericTreeNode>>();
+ ArrayList<GenericTreeNode> thisPath = new ArrayList<GenericTreeNode>();
+ ArrayList<GenericTreeNode> targetPath = new
ArrayList<GenericTreeNode>();
- GenericTreeNode tmpTarget = target;
- GenericTreeNode tmpThis = this;
- int depthOffset = -1;
+ GenericTreeNode tmpTarget = target;
+ GenericTreeNode tmpThis = this;
+ int depthOffset = -1;
+ while (depthOffset != 0) {
+ depthOffset = tmpThis.getDepth() - tmpTarget.getDepth();
+ if (depthOffset > 0) {
+ thisPath.add(tmpThis);
+ tmpThis = tmpThis.getParent();
+ } else if (depthOffset < 0) {
+ targetPath.add(tmpTarget);
+ tmpTarget = tmpTarget.getParent();
+ }
+ }
- while(depthOffset != 0)
- {
- depthOffset= tmpThis.getDepth()-tmpTarget.getDepth();
- if(depthOffset > 0)
- {
+ while (!tmpThis.compare(tmpTarget)) {
thisPath.add(tmpThis);
- tmpThis = tmpThis.getParent();
-
- }
- else if(depthOffset < 0)
- {
targetPath.add(tmpTarget);
+
+ tmpThis = tmpThis.getParent();
tmpTarget = tmpTarget.getParent();
- }
}
- while(!tmpThis.compare(tmpTarget))
- {
- thisPath.add(tmpThis);
- targetPath.add(tmpTarget);
-
- tmpThis = tmpThis.getParent();
- tmpTarget = tmpTarget.getParent();
- }
-
- Collections.reverse(targetPath);
- finalPath.add(thisPath);
- finalPath.add(targetPath);
+ Collections.reverse(targetPath);
+ finalPath.add(thisPath); //way up
+ finalPath.add(targetPath); // way down
- return finalPath;
+ return finalPath; // returns the way up to first commun ancestor as
index 0 and the way down to the target from the FCA as index 1
}
public void initWeight() // Modify euristic here when refining the
choosing patern
{
- setWeight (this.interest_mark); // eventually consider depth?
+ setWeight(this.interest_mark); // eventually consider depth?
}
- public boolean isSingleChangeOnCurrentPath()
- {
- ArrayList<GenericTreeNode> finalPath = new ArrayList<GenericTreeNode>();
- finalPath.addAll(this.findPathToMutation(rootMutation).get(0));
- finalPath.addAll(this.findPathToMutation(rootMutation).get(1));
+ public boolean isSingleChangeOnCurrentPath() {
+ ArrayList<GenericTreeNode> finalPath = new
ArrayList<GenericTreeNode>();
+ finalPath.addAll(this.findPathToMutation(rootMutation).get(0));
+ finalPath.addAll(this.findPathToMutation(rootMutation).get(1));
- for(GenericTreeNode mutOnPath : finalPath)
- {
- if(mutOnPath.getChosenChange().compare(this.getChosenChange()))
- return false;
- }
- return true;
+ for (GenericTreeNode mutOnPath : finalPath) {
+ if (mutOnPath.getChosenChange().compare(this.getChosenChange()))
+ return false;
+ }
+ return true;
}
- public void propagateWeight()
- {
+ public void propagateWeight() {
- this.updateSubTreeWeight();
- if(this.getParent() != null)
- this.getParent().propagateWeight();
+ this.updateSubTreeWeight();
+ if (this.getParent() != null)
+ this.getParent().propagateWeight();
}
}
--
To stop receiving notification emails like this one, please contact
address@hidden
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] [taler-schemafuzz] branch master updated: corrected some shitty implementation and lightened up some code. Stop laughing Christian,
gnunet <=