All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.berkeley.nlp.util.IterableAdapter Maven / Gradle / Ivy

Go to download

The Berkeley parser analyzes the grammatical structure of natural language using probabilistic context-free grammars (PCFGs).

The newest version!
package edu.berkeley.nlp.util;

import java.util.Iterator;

public class IterableAdapter {

	public static interface Convertor  { public T convert(S s); }
	
	public static  Iterable adapt(final Iterable iterable, final Convertor convertor) {
		return new Iterable() {			
			public Iterator iterator() {
				final Iterator origIt = iterable.iterator();
				return new Iterator() {

					public boolean hasNext() {						
						return origIt.hasNext();
					}

					public T next() {
						// TODO Auto-generated method stub
						return convertor.convert(origIt.next());
					}

					public void remove() {
						// TODO Auto-generated method stub
						origIt.remove();
					}
					
				};
			}
			
		};
	}
	
}