001/*
002 * Copyright (c) 2012-2017 Institut National des Sciences Appliquées de Lyon (INSA-Lyon)
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the Eclipse Public License v1.0
006 * which accompanies this distribution, and is available at
007 * http://www.eclipse.org/legal/epl-v10.html
008 */
009package gololang;
010
011import java.util.Iterator;
012
013/**
014 * Wraps a {@code Headtail} into an iterator
015 */
016public class HeadTailIterator<T> implements Iterator<T> {
017  private HeadTail<T> data;
018
019  HeadTailIterator(HeadTail<T> headTail) {
020    this.data = headTail;
021  }
022
023  @Override
024  public boolean hasNext() {
025    return !data.isEmpty();
026  }
027
028  @Override
029  public T next() {
030    T h = data.head();
031    data = data.tail();
032    return h;
033  }
034
035  @Override
036  public void remove() {
037    throw new UnsupportedOperationException("HeadTail object are immutable");
038  }
039}