Mercurial > hg > Members > tatsuki > bench > jungle-core
comparison src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/ChildrenImpl.java @ 10:a2c019a77c27
commit
author | Shoshi TAMAKI |
---|---|
date | Mon, 10 Dec 2012 18:50:53 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
9:bb96e631f022 | 10:a2c019a77c27 |
---|---|
1 package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl; | |
2 | |
3 import java.util.Iterator; | |
4 | |
5 import fj.P2; | |
6 import fj.data.List; | |
7 | |
8 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Children; | |
9 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Node; | |
10 | |
11 public class ChildrenImpl implements Children | |
12 { | |
13 private final List<Node> children; | |
14 private static final List<Node> EMPTY = List.nil(); | |
15 | |
16 public ChildrenImpl() | |
17 { | |
18 this(EMPTY); | |
19 } | |
20 | |
21 public ChildrenImpl(List<Node> _children) | |
22 { | |
23 children = _children; | |
24 } | |
25 | |
26 public ChildrenImpl add(Node _newNode) | |
27 { | |
28 return new ChildrenImpl(children.snoc(_newNode)); | |
29 } | |
30 | |
31 public ChildrenImpl insert(Node _newNode,int _pos) | |
32 { | |
33 check(_pos); | |
34 | |
35 P2<List<Node>,List<Node>> split = children.splitAt(_pos); | |
36 List<Node> newChildren = split._1().snoc(_newNode).append(split._2()); | |
37 | |
38 return new ChildrenImpl(newChildren); | |
39 } | |
40 | |
41 public ChildrenImpl delete(int _pos) | |
42 { | |
43 check(_pos); | |
44 | |
45 P2<List<Node>,List<Node>> split = children.splitAt(_pos); | |
46 List<Node> newChildren = split._1().init().append(split._2()); | |
47 | |
48 return new ChildrenImpl(newChildren); | |
49 } | |
50 | |
51 public void check(int _pos) | |
52 { | |
53 if(children.length() < _pos){ | |
54 throw new IllegalArgumentException("_pos > length"); | |
55 } | |
56 } | |
57 | |
58 @Override | |
59 public Iterator<Node> iterator() | |
60 { | |
61 return null; | |
62 } | |
63 } |