view Main/jungle-main/data/list/headNode.cs @ 20:1f99e150f336

fix folder and add Object Mapper.
author Kazuma Takeda
date Thu, 15 Dec 2016 22:52:48 +0900
parents
children f2ea780b3e80
line wrap: on
line source

using UnityEngine;
using System.Collections;
using System;

public class headNode<T> : Node<T>{
	private readonly Node<T> next;

	public headNode(){
		this.next = new TailNode<T> ();
	}

	public headNode(Node<T> next){
		this.next = next;
	}

	public Node<T> getNext(){
		return next;
	}

	public T getAttribute(){
		return default(T);
	}

	public Node<T> add(int currentNum, int num, T attribute) {
		if (num == 0) {
			Node<T> newNode = new DefaultNode<T>(attribute, next);
			return new headNode<T>(newNode);
		}
		Node<T> newNodes = next.add(currentNum + 1, num, attribute);
		if (newNodes == null) {
			return this;
		}
		return new headNode<T>(newNodes);
	}

	public Node<T> addLast(T attribute) {
		Node<T> node = next.addLast(attribute);
		return new headNode<T>(node);
	}

	public Node<T> delete(int currentNum, int deleteNum) {
		if (currentNum == deleteNum) {
			return new headNode<T>(this.next.getNext());
		}

		Node<T> newNode = next.delete(currentNum + 1, deleteNum);
		if (newNode == null) {
			return this;
		}
		return new headNode<T>(newNode);
	}

	public Node<T> replaceNode(int currentNum, int num, T attribute) {
		Node<T> nextNode = getNext();
		Node<T> newNode = nextNode.replaceNode(currentNum, num, attribute);
		if (newNode == null)
			return this;
		return new headNode<T>(newNode);
	}

	public int length() {
		return next.length();
	}

    public T getAttribure()
    {
        throw new NotImplementedException();
    }
}