Mercurial > hg > Members > shoshi > jungle > jungle-core
view src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/operations/NetworkNodePath.java @ 310:474728dcfdb8
add PathType
author | tatsuki |
---|---|
date | Thu, 26 Jan 2017 23:44:14 +0900 |
parents | 201cc75a9984 |
children | a0529572fbcb |
line wrap: on
line source
package jp.ac.u_ryukyu.ie.cr.jungleNetwork.operations; import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.NodePath; import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.PathType; import jp.ac.u_ryukyu.ie.cr.jungle.util.Pair; import org.msgpack.annotation.Message; import java.nio.ByteBuffer; import java.util.Iterator; import java.util.LinkedList; @Message public class NetworkNodePath implements NodePath { LinkedList<Integer> path; PathType type; public NetworkNodePath() { path = new LinkedList<Integer>(); path.add(-1); type = PathType.Default; } public NetworkNodePath(NodePath _p) { path = new LinkedList<Integer>(); for (Integer pos : _p) { path.add(pos); } type = _p.getPathType(); } public NetworkNodePath(NodePath _p, PathType type) { path = new LinkedList<Integer>(); for (Integer pos : _p) { path.add(pos); } this.type = type; } private NetworkNodePath(LinkedList<Integer> _path) { path = _path; } @Override public Iterator<Integer> iterator() { return path.iterator(); } @Override public int get(int index) { return path.get(index); } @Override public NetworkNodePath add(int _pos) { LinkedList<Integer> newPath = copyPath(); newPath.add(_pos); return new NetworkNodePath(newPath); } @Override public NodePath addHead(int pos) { return null; //Linked Listを後で直す // List<Integer> newPath = path.add(0, pos); // return new DefaultNodePath(newPath); } @Override public Pair<Integer, NodePath> pop() { LinkedList<Integer> cPath = copyPath(); int e = cPath.getFirst(); cPath.remove(); return new Pair<Integer, NodePath>(e, new NetworkNodePath(cPath)); } @Override public int size() { return path.size(); } private LinkedList<Integer> copyPath() { LinkedList<Integer> newPath = new LinkedList<Integer>(); for (Integer i : path) { newPath.add(i); } return newPath; } @Override public String toString() { return path.toString(); } @Override public NodePath tail() { path.removeLast(); return new NetworkNodePath(path); } @Override public Pair<Integer, NodePath> last() { Integer num = path.removeLast(); return new Pair<Integer, NodePath>(num, new NetworkNodePath(path)); } //以下使わない @Override public String getKey() { return null; } @Override public ByteBuffer getValue() { return null; } @Override public PathType getPathType() { return PathType.Default; } @Override //ネットワークでは今のところ使わない public NodePath setType(PathType type) { return null; } }