-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* blocking tree changes * moved the set logic to block * reverted back tests * reverted back test data * removed unused code * added back commented code * ftd changes * refactor * simplified if-else * removed unused imports * ftd changes * changed absolute path * refactored class naming * config changes * changed tot this()
- Loading branch information
1 parent
d75daca
commit c69adbe
Showing
20 changed files
with
687 additions
and
75 deletions.
There are no files selected for viewing
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
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
44 changes: 44 additions & 0 deletions
44
common/core/src/main/java/zingg/common/core/block/CacheBasedHashFunctionUtility.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,44 @@ | ||
package zingg.common.core.block; | ||
|
||
import zingg.common.client.FieldDefinition; | ||
import zingg.common.core.hash.HashFunction; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class CacheBasedHashFunctionUtility<D, R, C, T> implements IHashFunctionUtility<D, R, C, T> { | ||
|
||
private final Set<String> hashFunctionsInCurrentNodePath; | ||
private static final String DELIMITER = ":"; | ||
|
||
public CacheBasedHashFunctionUtility() { | ||
this.hashFunctionsInCurrentNodePath = new HashSet<String>(); | ||
} | ||
|
||
@Override | ||
public boolean isHashFunctionUsed(FieldDefinition fieldDefinition, HashFunction<D, R, C, T> hashFunction, Tree<Canopy<R>> tree, Canopy<R> node) { | ||
return hashFunctionsInCurrentNodePath.contains(getKey(fieldDefinition, hashFunction)); | ||
} | ||
|
||
@Override | ||
public void addHashFunctionIfRequired(Canopy<R> node) { | ||
addHashFunctionInCurrentNodePath(node); | ||
} | ||
|
||
@Override | ||
public void removeHashFunctionIfRequired(Canopy<R> node) { | ||
removeHashFunctionInCurrentNodePath(node); | ||
} | ||
|
||
private void addHashFunctionInCurrentNodePath(Canopy<R> node) { | ||
this.hashFunctionsInCurrentNodePath.add(getKey(node.getContext(), node.getFunction())); | ||
} | ||
|
||
private void removeHashFunctionInCurrentNodePath(Canopy<R> node) { | ||
this.hashFunctionsInCurrentNodePath.remove(getKey(node.getContext(), node.getFunction())); | ||
} | ||
|
||
private String getKey(FieldDefinition fieldDefinition, HashFunction<D, R, C, T> hashFunction) { | ||
return fieldDefinition.getName() + DELIMITER + hashFunction.getName(); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
common/core/src/main/java/zingg/common/core/block/DefaultHashFunctionUtility.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,55 @@ | ||
package zingg.common.core.block; | ||
|
||
import zingg.common.client.FieldDefinition; | ||
import zingg.common.core.hash.HashFunction; | ||
|
||
public class DefaultHashFunctionUtility<D, R, C, T> implements IHashFunctionUtility<D, R, C, T>{ | ||
@Override | ||
public boolean isHashFunctionUsed(FieldDefinition fieldDefinition, HashFunction<D, R, C, T> hashFunction, Tree<Canopy<R>> tree, Canopy<R> node) { | ||
boolean isUsed = false; | ||
if (node == null || tree == null) { | ||
return false; | ||
} | ||
if (checkFunctionInNode(node, fieldDefinition.fieldName, hashFunction)) { | ||
return true; | ||
} | ||
Tree<Canopy<R>> nodeTree = tree.getTree(node); | ||
if (nodeTree == null) { | ||
return false; | ||
} | ||
|
||
Tree<Canopy<R>> parent = nodeTree.getParent(); | ||
if (parent != null) { | ||
Canopy<R>head = parent.getHead(); | ||
while (head != null) { | ||
// check siblings of node | ||
/*for (Tree<Canopy<R>> siblings : parent.getSubTrees()) { | ||
Canopy<R>sibling = siblings.getHead(); | ||
if (checkFunctionInNode(sibling, index, function)) | ||
return true; | ||
}*/ | ||
// check parent of node | ||
return isHashFunctionUsed(fieldDefinition, hashFunction, tree, head); | ||
} | ||
} | ||
return isUsed; | ||
} | ||
|
||
@Override | ||
public void addHashFunctionIfRequired(Canopy<R> node) { | ||
//don't add hashFunction to cache | ||
//as we are in default mode | ||
} | ||
|
||
@Override | ||
public void removeHashFunctionIfRequired(Canopy<R> node) { | ||
//don't remove hashFunction from cache | ||
//as we are in default mode | ||
} | ||
|
||
private boolean checkFunctionInNode(Canopy<R>node, String name, | ||
HashFunction<D, R, C, T> function) { | ||
return node.getFunction() != null && node.getFunction().equals(function) | ||
&& node.context.fieldName.equals(name); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
common/core/src/main/java/zingg/common/core/block/HashFunctionUtilityFactory.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,12 @@ | ||
package zingg.common.core.block; | ||
|
||
public class HashFunctionUtilityFactory { | ||
|
||
public static IHashFunctionUtility getHashFunctionUtility(HashUtility hashUtility) { | ||
|
||
if (HashUtility.DEFAULT.equals(hashUtility)) { | ||
return new DefaultHashFunctionUtility(); | ||
} | ||
return new CacheBasedHashFunctionUtility(); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
common/core/src/main/java/zingg/common/core/block/HashUtility.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,6 @@ | ||
package zingg.common.core.block; | ||
|
||
public enum HashUtility { | ||
DEFAULT, | ||
CACHED | ||
} |
12 changes: 12 additions & 0 deletions
12
common/core/src/main/java/zingg/common/core/block/IHashFunctionUtility.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,12 @@ | ||
package zingg.common.core.block; | ||
|
||
import zingg.common.client.FieldDefinition; | ||
import zingg.common.core.hash.HashFunction; | ||
|
||
public interface IHashFunctionUtility<D, R, C, T> { | ||
boolean isHashFunctionUsed(FieldDefinition fieldDefinition, HashFunction<D, R, C, T> hashFunction, Tree<Canopy<R>> tree, Canopy<R>node); | ||
|
||
void addHashFunctionIfRequired(Canopy<R> node); | ||
|
||
void removeHashFunctionIfRequired(Canopy<R> node); | ||
} |
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
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
Oops, something went wrong.