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

com.sun.tv.si.ServiceIteratorImpl Maven / Gradle / Ivy

The newest version!
/*
 * @(#)ServiceIterator.java	1.10 00/07/03
 *
 * Copyright 1998-2000 by Sun Microsystems, Inc.,
 * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
 * All rights reserved.
 * 
 * This software is the confidential and proprietary information
 * of Sun Microsystems, Inc. ("Confidential Information").  You
 * shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement
 * you entered into with Sun.
 */

package com.sun.tv.si;

import java.util.*;
import javax.tv.service.navigation.*;
import java.util.NoSuchElementException;
import javax.tv.service.Service;

/**
 * ServiceIterator permits iteration over an ordered
 * list of Service objects.  Applications may use the
 * ServiceIterator interface to browse a
 * ServiceList forward or backward.

* * Upon initial usage, hasPrevious() will return * false and nextService() will return the * first Service in the list, if present. * * @see ServiceList */ public class ServiceIteratorImpl implements ServiceIterator { int theIndex; Vector services; /** * */ public ServiceIteratorImpl(Vector list) { if(list != null) { services = list; } else { services = new Vector(); } theIndex = -1; } /** * * Resets the iterator to the beginning of the list, such that * hasPrevious returns false. * * */ public void toBeginning() { theIndex = -1; } /** * * Sets the iterator to the end of the list, such that * hasNext returns false. */ public void toEnd() { theIndex = services.size(); } /** * * Reports the next Service object in the list. This * method may be called repeatedly to iterate through the list. * * @return The Service object at the next position in * the list. * * @throws NoSuchElementException If the iteration has no next * Service. */ public Service nextService() { if (hasNext() == false) { String msg = "next index (" + theIndex + ") is out of range."; throw new NoSuchElementException(msg); } theIndex++; return (Service)services.elementAt(theIndex); } /** * * Reports the previous Service object in the list. * This method may be called repeatedly to iterate through the list * in reverse order. * * @return The Service object at the previous position * in the list. * * @throws NoSuchElementException If the iteration has no previous * Service. */ public Service previousService() { if (hasPrevious() == false) { String msg = "next index (" + theIndex + ") is out of range."; throw new NoSuchElementException(msg); } theIndex--; return (Service)services.elementAt(theIndex); } /** * Tests if there is a Service in the next position in * the list. * * @return true if there is a Service in * the next position in the list; false otherwise. */ public boolean hasNext() { int index = theIndex + 1; return !(index < 0 || index > services.size() - 1); } /** * * Tests if there is a Service in the previous * position in the list. * * @return true if there is a Service in * the previous position in the list; false otherwise. */ public boolean hasPrevious() { int index = theIndex - 1; return !(index < 0 || index > services.size() - 1); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy