Mercurial > hg > Members > tatsuki > bench > jungle-core
view src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/trasnformer/EditCache.java @ 19:703f0be5368a
added attribute cache
author | Shoshi TAMAKI |
---|---|
date | Thu, 20 Dec 2012 18:09:17 +0900 |
parents | 35c661de095d |
children |
line wrap: on
line source
package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer; import java.nio.ByteBuffer; import fj.Ord; import fj.data.List; import fj.data.Option; import fj.data.TreeMap; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.AppendChildAtOperation; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.DeleteAttributeOperation; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.DeleteChildAtOperation; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.Operation; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.SetAttributeOperation; public class EditCache { private final List<Operation> operations; private final TreeMap<String,Operation> attrCache; private final List<Operation> childrenCache; public EditCache() { operations = List.nil(); attrCache = TreeMap.empty(Ord.stringOrd); childrenCache = List.nil(); } private EditCache(List<Operation> _operations,TreeMap<String,Operation> _attrCache,List<Operation> _childrenCache) { operations = _operations; attrCache = _attrCache; childrenCache = _childrenCache; } public EditCache setAttribute(final String _key,final ByteBuffer _value) { SetAttributeOperation op = new SetAttributeOperation(){ @Override public String getKey(){ return _key; } @Override public ByteBuffer getValue(){ return _value; } }; TreeMap<String,Operation> newAttrCache = attrCache.set(_key,op); List<Operation> newOperations = operations.snoc(op); return new EditCache(newOperations,newAttrCache,childrenCache); } public EditCache deleteAttribute(final String _key) { DeleteAttributeOperation op = new DeleteAttributeOperation(){ @Override public String getKey(){ return _key; } }; TreeMap<String,Operation> newAttrCache = attrCache.set(_key,op); List<Operation> newOperations = operations.snoc(op); return new EditCache(newOperations,newAttrCache,childrenCache); } public EditCache appendChildAt(final int _pos) { AppendChildAtOperation op = new AppendChildAtOperation(){ @Override public int position(){ return _pos; } }; List<Operation> newOperations = operations.snoc(op); List<Operation> newChildrenCache = childrenCache.snoc(op); return new EditCache(newOperations,attrCache,newChildrenCache); } public EditCache deleteChildAt(final int _pos) { DeleteChildAtOperation op = new DeleteChildAtOperation(){ @Override public int position(){ return _pos; } }; List<Operation> newOperations = operations.snoc(op); List<Operation> newChildrenCache = childrenCache.snoc(op); return new EditCache(newOperations,attrCache,newChildrenCache); } public Operation getAttribute(String _key) { Option<Operation> result = attrCache.get(_key); if(result.isSome()){ return result.some(); } return null; } public List<Operation> operations() { return operations; } public List<Operation> childrenOperations() { return childrenCache; } }