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
/* | |
There we go, much cleaner than https://gist.github.com/noizu/579fe422e3d600b0eee4 | |
encoding/decoding is handled in base class. We still require a recursive generic but we avoid the need to use a seperat helper class by forcing derived class to explicitly state the concrete class used for json encoding children. | |
getChildren/setChildren | |
Some boiler plate has to be added whenever including a Tree structure but its much more minimal than it was. No conditional logic, etc. Load to and from objectify appears to work. Load to and from memcache appears to work. | |
Important, any entity that embeds a tree should call OnSave, OnLoad on the nested entity as these may not called under certain conditions such as when using custom memcached encoding/decoding logic to work around poor built in cache granularity controls. ( https://github.com/noizu/fragmented-keys-4java ) |
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
/** | |
There has to be a more straight forward way. Not being able to use generics or persist recursions is painful. Maybe abstract base classes with type reflection and boxing/unboxing to prepare and populate nested structure and flat array structure. *muses* | |
Or moving flatten/expand logic into the Node class . . . so instantiating a single node and calling.expand(tree) onLoad, and m.tree = node.flatten() onSave. Which would let us keep that logic in a base class with out needing to work around specific node type (additional fields). | |
Sigh, but then we'd have a base class with a list of children of base class type or base class with a get children method of base class type or node interface type and extra boxing/unboxing cruft. | |
*/ |
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
public Long GetField(Integer from, Integer to) throws Exception { | |
if(from % 4 == 0 && (to + 1) % 4 == 0) { | |
return hexToLong(this.data, from/4, (to + 1)/4); | |
} else { | |
// 1. Grab Nibble bounding from, and to. | |
int firstChar = (int) Math.floor( (double) (from/4.0)) ; | |
int lastChar = (int) Math.ceil( (double) ((to + 1.0)/4.0)); | |
int bitWidth = (to + 1) - from; |
NewerOlder